{"id":18296561,"url":"https://github.com/fiedsch/sqlite-manager","last_synced_at":"2025-04-09T08:43:47.033Z","repository":{"id":74000955,"uuid":"119163813","full_name":"fiedsch/sqlite-manager","owner":"fiedsch","description":"Helper classes for working with SQLite Databases","archived":false,"fork":false,"pushed_at":"2018-01-31T05:47:50.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-04T10:08:54.363Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/fiedsch.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-27T12:49:15.000Z","updated_at":"2018-01-27T12:49:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"335811b7-9853-4244-a51a-c9f31cb27889","html_url":"https://github.com/fiedsch/sqlite-manager","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fiedsch%2Fsqlite-manager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fiedsch%2Fsqlite-manager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fiedsch%2Fsqlite-manager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fiedsch%2Fsqlite-manager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fiedsch","download_url":"https://codeload.github.com/fiedsch/sqlite-manager/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248008555,"owners_count":21032553,"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","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":[],"created_at":"2024-11-05T14:41:39.810Z","updated_at":"2025-04-09T08:43:47.010Z","avatar_url":"https://github.com/fiedsch.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SQLite Manager (Helper Library)\n\n\n## Purpose\n\nHelper classes for working with SQLite Databases.\n\n\n## Examples\n\n\n### Connect to a database\n\n```php\n$dbpath = '/path/to/your/sqlite-database.db';\n$manager = new \\Fiedsch\\SqliteManager\\Manager();\n// @var Doctrine\\DBAL\\Connection \n$connection = $manager-\u003econnectTo($dbpath);\n```\nwhich is mostly syntactic sugar that wraps `\\Doctrine\\DBAL\\DriverManager::getConnection()`.\n\n\n### Create a table in a database\n\n```php\n$manager = new \\Fiedsch\\SqliteManager\\Manager();\n// columns configuration \n// keys are the column names, \n// values are the respective column's configuration settings \n$columns = [\n    'foo' =\u003e [\n        'type' =\u003e 'TEXT',\n    ],\n    'bar' =\u003e [\n            'type'      =\u003e 'REAL',\n            'mandatory' =\u003e true,\n            'unique'    =\u003e true,\n     ]\n];\n$sql = $manager-\u003egetCreateTableSql('mytable', $columns);\n// \"CREATE TABLE mytable (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, foo TEXT, bar REAL NOT NULL,)\"\n// Note the id column that will always be created!\n```\n\nNote: what is stored in `$columns[\u003ccolname\u003e]['type']` is SQLite's \"affinity\" \n(see. \"Type Affinity\" in https://www.sqlite.org/datatype3.html).\n\n\n### Add a column to an existing table\n\n```php\n$manager = new \\Fiedsch\\SqliteManager\\Manager();\n// column configuration \n$colconfig = [\n    'type'      =\u003e 'REAL',\n    'mandatory' =\u003e true,\n    'default'    =\u003e 1.5,\n];\n$sql = $manager-\u003egetAddColumnSql('foo', 'bar', $colconfig);\n// \"ALTER TABLE foo ADD COLUMN bar REAL NOT NULL DEFAULT '1.5'\" \n```\n\n```php\n$manager = new \\Fiedsch\\SqliteManager\\Manager();\n// column configuration \n$colconfig = [\n    'type'      =\u003e 'REAL',\n    'unique'    =\u003e true,\n];\n$sql = $manager-\u003egetAddColumnSql('foo', 'bar', $colconfig);\n// will throw a \\RuntimeException as you can not add a unique column\n// (if the table already contains data, which we assume)\n```\n\n\n### Augment and check configuration\n\n```php\n$configuration = [\n  'type' =\u003e 'TEXT'\n];\n$checker = new ColumnConfiguration($configuration);\n$checker-\u003ehasErrors(); // false\n$checker-\u003egetErrors(); // []\n$checker-\u003egetConfiguration();\n// [\n//     'type'      =\u003e 'TEXT',\n//     'mandatory' =\u003e false,\n//     'unique'    =\u003e false,\n//     'default'   =\u003e null\n// ]  \n```\n\n\nFor column types see https://www.sqlite.org/datatype3.html\n\nFor more Examples see the unit tests located in `tests`.\n\n\n## TODO (Roadmap)\n\n* Test existing table matches a column configuration\n* Add columns if above test fails\n* Add new features if required. Feel free to open an issue or create a pull request.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffiedsch%2Fsqlite-manager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffiedsch%2Fsqlite-manager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffiedsch%2Fsqlite-manager/lists"}