cycle / database
DBAL, schema introspection, migration and pagination
Fund package maintenance!
roadrunner-server
Installs: 201 537
Dependents: 17
Suggesters: 0
Security: 0
Stars: 39
Watchers: 4
Forks: 18
Open Issues: 22
Requires
- php: >=8.0
- ext-pdo: *
- psr/log: 1 - 3
- spiral/core: ^2.8 || ^3.0
- spiral/pagination: ^2.8 || ^3.0
Requires (Dev)
- infection/infection: ^0.26.10
- mockery/mockery: ^1.5
- phpunit/phpunit: ^9.5
- spiral/tokenizer: ^2.13
- vimeo/psalm: ^4.23
Conflicts
This package is auto-updated.
Last update: 2023-09-21 11:36:10 UTC
README
Secure, multiple SQL dialects (MySQL, PostgreSQL, SQLite, SQLServer), schema introspection, schema declaration, smart identifier wrappers, database partitions, query builders, nested queries.
Documentation
- Installation and Configuration
- Access Database
- Database Isolation
- Query Builders
- Transactions
- Schema Introspection
- Schema Declaration
- Migrations
- Errata
Requirements
Make sure that your server is configured with following PHP version and extensions:
- PHP 8.0+
- PDO Extension with desired database drivers
Installation
To install the component:
$ composer require cycle/database
Example
Given example demonstrates the connection to SQLite database, creation of table schema, data insertion and selection:
<?php declare(strict_types=1); require_once "vendor/autoload.php"; use Cycle\Database\Config; use Cycle\Database\DatabaseManager; $dbm = new DatabaseManager(new Config\DatabaseConfig([ 'databases' => [ 'default' => ['connection' => 'sqlite'], ], 'connections' => [ 'sqlite' => new Config\SQLiteDriverConfig( connection: new Config\SQLite\FileConnectionConfig( database: 'runtime/database.db' ), ), ], ])); $users = $dbm->database('default')->table('users'); // create or update table schema $schema = $users->getSchema(); $schema->primary('id'); $schema->string('name'); $schema->datetime('created_at'); $schema->datetime('updated_at'); $schema->save(); // insert data $users->insertOne([ 'name' => 'test', 'created_at' => new DateTimeImmutable(), 'updated_at' => new DateTimeImmutable(), ]); // select data foreach ($users->select()->where(['name' => 'test']) as $u) { print_r($u); }
License:
MIT License (MIT). Please see LICENSE
for more information. Maintained
by Spiral Scout.