{"id":18463720,"url":"https://github.com/commandstring/jsondb","last_synced_at":"2025-04-28T13:33:31.773Z","repository":{"id":65705817,"uuid":"595422243","full_name":"CommandString/jsondb","owner":"CommandString","description":"Build your database with JSONs","archived":false,"fork":false,"pushed_at":"2023-02-05T17:28:55.000Z","size":22,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-16T16:57:58.345Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CommandString.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2023-01-31T03:17:58.000Z","updated_at":"2023-02-28T19:08:59.000Z","dependencies_parsed_at":"2023-02-19T01:01:53.435Z","dependency_job_id":null,"html_url":"https://github.com/CommandString/jsondb","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CommandString%2Fjsondb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CommandString%2Fjsondb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CommandString%2Fjsondb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CommandString%2Fjsondb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CommandString","download_url":"https://codeload.github.com/CommandString/jsondb/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251320036,"owners_count":21570495,"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-06T09:07:47.400Z","updated_at":"2025-04-28T13:33:31.709Z","avatar_url":"https://github.com/CommandString.png","language":"PHP","readme":"# commandstring/jsondb #\n\nA fully customizable JSON Database system structured similarly to MySQL\n\n# Creating a database\n\n```php\n\u003c?php\n\nuse CommandString\\JsonDb\\Structure\\Database;\nuse CommandString\\JsonDb\\Structure\\Table;\n\nclass YourDatabase extends Database {\n    protected static array $tableClasses = [];\n}\n```\n\nCreate a class that extends `CommandString\\JsonDb\\Structure\\Database` and add the property shown above. We'll come back to it later\n\n# Creating a table\n\n```php\n\u003c?php\n\nuse CommandString\\JsonDb\\Structure\\Table;\n\nclass YourTable extends Table {\n    protected static string $name = \"yourtable\";\n    protected static string $fileLocation = __DIR__.\"/yourtable.json\";\n    protected static array $columns = [];\n}\n```\n\nCreate a class that extends `CommandString\\JsonDb\\Structure\\Table` like the one above. The first property is how the table will be identified, the second is where the table's json will be stored/retrieved and I'll come back to the columns property later as well. However, for the tableClasses property in your database class, you will want to add your table class to it like so...\n\n```php\n// ...\nprotected static array $tableClasses = [YourDatabase::class];\n// ...\n```\n\nand append any future tables you create to this property\n\n# Creating a column\n\n```php\n\nuse CommandString\\JsonDb\\Structure\\Column;\nuse CommandString\\JsonDb\\Structure\\DataTypes;\n\nclass YourColumn extends Column {\n    protected static DataTypes              $type = DataTypes::STRING;\n    protected static string                 $name = \"yourcolumn\";\n    protected static array                  $enumValues = [];\n    protected static string|int|float|null  $default;\n    protected static bool                   $nullable = false;\n    protected static bool                   $unique = false;\n}\n```\n\nCreate a class that extends `CommandString\\JsonDb\\Structure\\Column` then add the properties shown above. The available DataTypes are string, int, float, and enum. If the type is enum then make sure to add the values this column can be inside the enumValues array.\n\n## Special Notes\n1. I would recommend adding magic methods and public constants to your classes to take advantage of intellesense while coding, checkout the TestDb for an example\n2. Column and Table names will always be lowercased, so I would recommend having them lowercased by default to prevent any confusion.\n\n# Creating Rows\n\n```php\n$db = new YourDatabase; // you can also pass JSON encoder flags into the constructor\n\n$row = $db-\u003eyourtable-\u003enewRow();\n\n$row-\u003esetColumn($db-\u003eyourtable::COLUMN_NAME, \"\u003cvalue\u003e\") // you can pass a string for the column name but I recommend having constants has mentioned earlier\n\n$row = $row-\u003estore(); // returns that same row but this is associated to specific point in the JSON file\n```\n\n# Fetching rows\n\n```php\n/**\n * @var Row[]\n */\n$results = $db-\u003eyourtable-\u003enewQuery()-\u003ewhereAnd($db-\u003eyourtable::COLUMN_NAME, Operators::EQUAL_TO, \"\u003cvalue\u003e\")-\u003eexecute();\n```\n\n# Updating rows\n```php\n$row = $results[0];\n\n$row-\u003esetColumn($db-\u003eyourtable::COLUMN_NAME, \"\u003cnew value\u003e\");\n\n$row-\u003estore(); // updated the row\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommandstring%2Fjsondb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcommandstring%2Fjsondb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommandstring%2Fjsondb/lists"}