Download the PHP package tobento/service-database without Composer
On this page you can find all versions of the php package tobento/service-database. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tobento/service-database
More information about tobento/service-database
Files in tobento/service-database
Package service-database
Short Description Creating and managing databases easily.
License MIT
Homepage https://www.tobento.ch
Informations about the package service-database
Database Service
With the Database Service you can create and manage databases easily.
Table of Contents
- Getting started
- Requirements
- Highlights
- Documentation
- Databases
- Create Databases
- Add Databases
- Get Database
- Default Databases
- PDO Database
- Create PDO Database
- Pdo Database Factory
- Using PDO Database
- Migration
- Table Schema
- Column Types
- Rename And Drop
- Column Parameters
- Indexes
- Foreign Keys
- Items and Seeding
- Items
- Item Factory
- Json File Items
- Table Factory
- Column Factory
- Index Factory
- Processors
- Pdo MySql Processor
- Stack Processor
- Storages
- Pdo MySql Storage
- Stack Storage
- Custom Storage
- Security
- Migrator
- Create Migration
- Create Migration Seeder
- Install And Uninstall Migration
- Table Schema
- Databases
- Credits
Getting started
Add the latest version of the Database service project running this command.
Requirements
- PHP 8.0 or greater
Highlights
- Framework-agnostic, will work with any project
- Decoupled design
- Managing Databases
- Simple PDO Database Wrapper
- Migration support with table schema builder and seeding items
Documentation
Databases
Create Databases
Add Databases
add
register
You may use the register method to only create database if requested.
Get Database
If the database does not exist or could not get created it throws a DatabaseException.
You may use the has method to check if a database exists.
Default Databases
You may add default databases for your application design.
PDO Database
Create PDO Database
Pdo Database Factory
You may use the factory to easily create a database.
createDatabase
createPdo
Using PDO Database
Use the execute method to excute any prepared statements.
select
insert
update
Execute a insert statement returning the number of rows affected.
delete
Execute a delete statement returning the number of rows affected.
transaction
You may use the transaction method to run a set of database operations within a transaction. If an exception is thrown within the transaction closure, the transaction will automatically be rolled back. If the closure executes successfully, the transaction will automatically be committed.
commit
rollback
supportsNestedTransactions
PDO
Migration
Table Schema
Table schemas are used by Storages for migration processing.
Column Types
Available Types
Type | Parameters | Lengthable | Nullable | Defaultable | Unsignable | Description |
---|---|---|---|---|---|---|
primary | name: 'column' | yes | no | no | yes | Usually mapped as int, auto-incrementing and added as primary index column. |
bigPrimary | name: 'column' | yes | no | no | yes | Usually mapped as bigint, auto-incrementing and added as primary index column. |
bool | name: 'column' | no | no | yes | no | Some databases will store it as tinyint (1/0). |
int | name: 'column', length: 11 | yes | yes | yes | yes | - |
tinyInt | name: 'column', length: 1 | yes | yes | yes | yes | - |
bigInt | name: 'column', length: 20 | yes | yes | yes | yes | - |
char | name: 'column', length: 255 | yes | yes | yes | no | - |
string | name: 'column', length: 255 | yes | yes | yes | no | - |
text | name: 'column' | no | yes | yes | no | - |
double | name: 'column' | no | yes | yes | no | - |
float | name: 'column' | no | yes | yes | no | - |
decimal | name: 'column', precision: 10, scale:0 | no | yes | yes | no | - |
datetime | name: 'column' | no | yes | yes | no | - |
date | name: 'column' | no | yes | yes | no | - |
time | name: 'column' | no | yes | yes | no | - |
timestamp | name: 'column' | no | yes | yes | no | - |
json | name: 'column' | no | yes | yes | no | - |
Lengthable
To set a column length.
Nullable
To set column as NOT NULL, use nullable method with false as parameter:
Defaultable
To set a default value for the column.
Unsignable
To set column as UNSIGNED.
primary / bigPrimary
Primary and bigPrimary columns will only be set while creation.
Rename and Drop
renameColumn
dropColumn
renameTable
dropTable
truncate
Column Parameters
charset
You might set the charset of the column.
collation
You might set the collation of the column.
Indexes
Simple index
Compound index
Simple unique index
Compound unique index
Primary index
Rename index
Drop index
Foreign Keys
No supported yet!
Items and Seeding
Items
chunk
You may play around with the chunk length parameter for speed improvements while having many items.
useTransaction
If set to true, it uses transaction while proccessing if the database supports it.
forceInsert
If set to true, it will always inserts the items, otherwise they will only be inserted if there there are not items yet.
Item Factory
You may use the item factory iterator to seed items and use the Seeder Service to generate fake data.
Json File Items
Table Factory
You may use the table factory to create a table.
Column Factory
You may use the column factory to create a column.
createColumn
Check out the supported Column Types for its type name.
createColumnFromArray
Lengthable, Nullable, Defaultable, Unsignable and Parameters column definitions:
Index Factory
createIndex
createIndexFromArray
Other parameter definitions:
Processors
Processors are used to process the table on the specified database.
Pdo MySql Processor
The proccessor will automatically determine if to add or modify table columns and indexes.
You may create a Pdo MySql Storage will query the database to create the current table as to determine modifications.
Stack Processor
You may use the "stack processor" to support multiple databases. Only the first processor which supports the specified database will process the action.
Storages
Storages are used to fetch the current table or store the processed.
Pdo MySql Storage
fetchTable
The storage will query the database to create the current table.
storeTable
No table data is stored as fetching will create the table.
Stack Storage
You may use the "stack storage" to support multiple databases. Only the first storage which supports the specified database will process the action.
Custom Storage
You may create custom storages for proccssors or as standalone usage.
Security
:warning: Avoid using user provided data for creating Table Schema without a proper whitelist!
Migrator
You might install and use the Migration Service for migration processing.
Create Migration
Create a migration class by extending the .
Using the method
You may use the method to register the table for the install and uninstall process.
Check out the Table Schema for its documentation.
Using the and methods
You may use the and methods for specifing the actions by your own.
Check out the Table Schema for its documentation.
Create Migration Seeder
First, you will need to install the Seeder Service and bind the implementation to your container in order to get injected on the .
Next, create a migration seeder class by extending the .
Then use the method to register the table for the install process.
Check out the Seeder Service for its documentation.
Check out the Table Schema for its documentation.
Install And Uninstall Migration
Check out the following migration service documentation to learn more about it.
Credits
- Tobias Strub
- All Contributors
All versions of service-database with dependencies
tobento/service-filesystem Version ^1.0
tobento/service-iterable Version ^1.0