v0.0.2 2023-06-03 09:43 UTC

This package is auto-updated.

Last update: 2024-04-03 11:15:40 UTC


README

  • you can create tables
  • add columns
  • CRUD operations
  • designed for sqlite or postgresql

install

composer require sensorario/orma

Copy vendor/sensorario/orma/public/index.php on your project root. SQLite does not require any installation. Postgres can be used with docker: vendor/sensorario/orma/docker-compose.yaml.

Happy coding

pdo

Postgres data refers to docker machine inside the project.

$config = [
    'postgresql' => [
        'dns' => 'pgsql:host=database;dbname=your_database_name',
        'username' => 'your_username',
        'password' => 'your_password',
    ],
    'sqlite' => [
        'dns' => 'sqlite:./erdatabase',
    ],
    'db' => 'postgresql',
    'db' => 'sqlite',
];

$pdo = new PDO(
    $config[$config['db']]['dns'],
    $config[$config['db']]['username'],
    $config[$config['db']]['password'],
);

init

$orma = new Orma($pdo, match($driver) {
    'sqlite' => new SQLiteDriver,
    'postgresql' => new PostgreSQLDriver,
});

create a table

$orma($table)->createTable();

add a column

$orma->addColumn($column);

insert

$orma->insert([ 'id' => 42, ]);

delete

$orma->delete([ 'id' => 42, ]);

update

$orma->update([ 'foo' => 'bar', ], [ 'id' => 42, ]);

PS. This repo is made just for fun.