{"id":23024452,"url":"https://github.com/thipages/quickdb","last_synced_at":"2026-05-07T10:34:46.443Z","repository":{"id":57068894,"uuid":"288931724","full_name":"thipages/quickdb","owner":"thipages","description":"Quick SQLite/MySql database sql creation builder","archived":false,"fork":false,"pushed_at":"2021-06-20T14:12:13.000Z","size":26,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-14T11:45:15.355Z","etag":null,"topics":["creation","database","foreign-keys","index","php","quick","sqlite"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thipages.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-20T07:02:13.000Z","updated_at":"2022-09-08T15:44:14.000Z","dependencies_parsed_at":"2022-08-24T14:54:13.663Z","dependency_job_id":null,"html_url":"https://github.com/thipages/quickdb","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/thipages/quickdb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thipages%2Fquickdb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thipages%2Fquickdb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thipages%2Fquickdb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thipages%2Fquickdb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thipages","download_url":"https://codeload.github.com/thipages/quickdb/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thipages%2Fquickdb/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271991297,"owners_count":24854746,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-24T02:00:11.135Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["creation","database","foreign-keys","index","php","quick","sqlite"],"created_at":"2024-12-15T13:18:44.898Z","updated_at":"2026-05-07T10:34:46.400Z","avatar_url":"https://github.com/thipages.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# quickdb\nQuick SQLite and MySql/MariaDB database sql creation builder\n\n### Installation\n**composer** require thipages\\quickdb\n\n### Dependency\n[quicksql](https://github.com/thipages/quicksql)\n\n### QDb class API\n\n```php\n    // Creates sql database creation statements\n    create($definition, $options=[]):Array\u003cstring\u003e\n    // Creates insert/update/delete sql statements\n    insert($tableName, $keyValues):string \n    update($tableName, $keyValues, $where):string\n    delete($tableName, $keyValues, $where):string\n```\n**Primary keys** are automatically created as `id` field name\n\n**Foreign keys** are automatically indexed\n\n**`$defintion`** is an associative array \u003ctableName,fieldDefinition\u003e\nfieldDefinition follows SQLite definition rules but supports shortcuts for indexes and foreign keys\n- `#INDEX` or `#UNIQUE` to add an index (unique) to the field,\n- `#FK_parentTable` to associate the field to the primary key of its parent table (foreign key)\n\n**`$options`** is an associated array for customization by merging with default\n- `primarykey : string` defines the primary key common to all tables, default : `id INTEGER PRIMARY KEY AUTOINCREMENT`\n- `prefield : boolean` (default:`false`). If true : all fields are prefixed by table name\n- `omnifields : array\u003cstring\u003e` defines fields present in all tables, default:\n```\n// For SQLite\n[\n    \"created_at INTEGER  not null default (strftime('%s','now'))\",\n    \"modified_at INTEGER  not null default (strftime('%s','now'))\"\n]\n// For MySql/MariaDB\n[\n    \"created_at TIMESTAMP  not null default CURRENT_TIMESTAMP\",\n    \"modified_at TIMESTAMP not null default CURRENT_TIMESTAMP ON UPDATE current_timestamp\"\n                ]\n```\nNote 1 : if `modified_at` definition is present in omnifields options, it will be automatically updated on `update`\n\nNote 2 : `strftime('%s','now')` stores UTC unixtime (sqlite)\n#### Example\n```php\n$db=new QDb();\n$db-\u003ecreate(\n    [\n        // MySql : VARCHAR(xx) is mandatory for MySql indexation\n        // MariaDB : TEXT would be ok\n        // SQLite : use TEXT instead - Equivalent to VARCHAR(X)\n        'user'=\u003e'name VARCHAR(10) #INDEX', \n        'message'=\u003e[\n            'content TEXT',\n            'userId INTEGER NOT NULL #FK_user',\n            'category TEXT #UNIQUE'\n        ]\n        ]\n);\n/*\nFor Sqlite\nArray\n(\n    [0] =\u003e PRAGMA foreign_keys=OFF;\n    [1] =\u003e DROP TABLE IF EXISTS user;\n    [2] =\u003e CREATE TABLE user (id INTEGER PRIMARY KEY AUTOINCREMENT,name VARCHAR(10),created_at INTEGER not null default (strftime('%s','now')),modified_at INTEGER not null default (str\nftime('%s','now')));\n    [3] =\u003e DROP INDEX IF EXISTS user_name_idx;\n    [4] =\u003e CREATE  INDEX user_name_idx ON user (name);\n    [5] =\u003e DROP TABLE IF EXISTS message;\n    [6] =\u003e CREATE TABLE message (id INTEGER PRIMARY KEY AUTOINCREMENT,content TEXT,userId INTEGER NOT NULL ,category TEXT,created_at INTEGER not null default (strftime('%s','now')),mod\nified_at INTEGER not null default (strftime('%s','now')),FOREIGN KEY(userId) REFERENCES user(id));\n    [7] =\u003e DROP INDEX IF EXISTS message_category_idx;\n    [8] =\u003e CREATE UNIQUE INDEX message_category_idx ON message (category);\n    [9] =\u003e DROP INDEX IF EXISTS message_userId_idx;\n    [10] =\u003e CREATE INDEX message_userId_idx ON message (userId);\n    [11] =\u003e PRAGMA foreign_keys=ON;\n)\n\nFor Mysql/MariaDB - varchar(10) for user name for compatibility\nArray\n(\n    [0] =\u003e SET FOREIGN_KEY_CHECKS=0;\n    [1] =\u003e DROP TABLE IF EXISTS user;\n    [2] =\u003e CREATE TABLE user (id INTEGER PRIMARY KEY AUTO_INCREMENT,name VARCHAR(10),created_at TIMESTAMP not null default CURRENT_TIMESTAMP,modified_at TIMESTAMP not null default CURRENT_TIMESTAMP ON UPDATE current_timestamp);\n    [3] =\u003e CREATE  INDEX user_name_idx ON user (name);\n    [4] =\u003e DROP TABLE IF EXISTS message;\n    [5] =\u003e CREATE TABLE message (id INTEGER PRIMARY KEY AUTO_INCREMENT,content TEXT,userId INTEGER NOT NULL ,category TEXT,created_at TIMESTAMP not null default CURRENT_TIMESTAMP,modified_at TIMESTAMP not null default CURRENT_TIMESTAMP ON UPDATE current_timestamp,FOREIGN KEY(userId) REFERENCES user(id));\n    [6] =\u003e CREATE UNIQUE INDEX message_category_idx ON message (category);\n    [7] =\u003e CREATE INDEX message_userId_idx ON message (userId);\n    [8] =\u003e SET FOREIGN_KEY_CHECKS=1;\n)\n*/\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthipages%2Fquickdb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthipages%2Fquickdb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthipages%2Fquickdb/lists"}