ggedde / spry-db
Database Provider for Spry
Installs: 143
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:spry-provider
Requires
- php: >=5.4.0
- catfan/medoo: ~v1.7.10
- dev-master
- 1.0.12
- 1.0.11
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0.x-dev
- 1.0.0
- 0.9.29
- 0.9.28
- 0.9.27
- 0.9.26
- 0.9.25
- 0.9.24
- 0.9.23
- 0.9.22
- 0.9.21
- 0.9.20
- 0.9.19
- 0.9.18
- 0.9.17
- 0.9.16
- 0.9.15
- 0.9.14
- 0.9.13
- 0.9.12
- 0.9.11
- 0.9.10
- 0.9.9
- 0.9.8
- 0.9.7
- 0.9.6
- 0.9.5
- 0.9.4
- 0.9.3
- 0.9.2
- 0.9.1
- 0.9.0
This package is auto-updated.
Last update: 2025-03-27 07:45:49 UTC
README
Default Database Class for Spry
Spry's default Provider uses "Medoo" and you can find all the Documentation here: https://medoo.in/doc
Example Usage:
$item = Spry::db()->get('items', '*', ['id' => 123]); $items = Spry::db()->select('items', '*', ['date[>]' => '2020-01-01']); $insertResponse = Spry::db()->insert('items', ['name' => 'test', 'date' => '2020-01-01']); $updateResponse = Spry::db()->update('items', ['name' => 'newtest'], ['id' => 123]); $deleteResponse = Spry::db()->delete('items', ['id' => 123]);
Spry Config Settings
$config->dbProvider = 'Spry\\SpryProvider\\SpryDB'; $config->db = [ 'database_type' => 'mysql', 'database_name' => '', 'server' => 'localhost', 'username' => '', 'password' => '', 'charset' => 'utf8', 'port' => 3306, 'prefix' => 'api_x_', // Should change this to be someting Unique 'schema' => [ 'tables' => [ 'users' => [ 'columns' => [ 'name' => [ 'type' => 'string' ], 'email' => [ 'type' => 'string' ], ] ] ] ] ];
Schema
You can use this to build out or Modify your Database Schema.
Using Spry CLI your can run
spry migrate
spry migrate --dryrun (Show what changes will be made without running anything)
spry migrate --force (Run Destructively. Will delete and change fields. You could loose precious data)
Scheme Settings
'schema' => [ 'tables' => [ 'users' => [ 'columns' => [ 'name' => [ 'type' => 'string' ], 'email' => [ 'type' => 'string', 'unique' => true ], 'amount' => [ 'type' => 'number', 'default' => 0 ], 'status' => [ 'type' => 'enum', 'options' => ['pending','active','completed','archived',''], ], 'start_date' => [ 'type' => 'datetime', 'default' => 'CURRENT_TIMESTAMP' ], ] ] ] ]
Various Column Types
- bigint BIGINT 21
- bigstring VARCHAR 255
- bigtext LONGTEXT
- bool TINYINT 1
- date DATE
- datetime DATETIME
- decimal DECIMAL 10,2
- enum ENUM
- int INT 10
- number FLOAT
- string VARCHAR 64
- text TEXT
- time TIME
- tinyint TINYINT 3
- tinystring VARCHAR 10
Default Fields
By default the scheme will create an 'id', 'updated_at' and 'created_at' fields.
You can remove these by using 'use_id' and 'timestamps' in the table schema settings.
'schema' => [ 'tables' => [ 'users' => [ 'use_id' => false, 'timestamps' => false ] ] ]
Unique Key
You can make any column 'unique' by adding the attribute:
'email' => [ 'type' => 'string', 'unique' => true ]
If you need to combine columns then use an array with the additional fields to be included in the unique key
'email' => [ 'type' => 'string', 'unique' => [ 'name', 'phone' ] ]