{"id":22497005,"url":"https://github.com/morebec/ydb","last_synced_at":"2025-10-05T05:54:05.339Z","repository":{"id":74799774,"uuid":"218968155","full_name":"Morebec/YDB","owner":"Morebec","description":"YDB is a simple PHP utility library to use Yaml files as a flat file database","archived":false,"fork":false,"pushed_at":"2020-01-29T13:20:06.000Z","size":364,"stargazers_count":4,"open_issues_count":12,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T21:32:04.470Z","etag":null,"topics":["database","php","table-schema","yaml","ydb"],"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/Morebec.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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":"2019-11-01T10:54:32.000Z","updated_at":"2024-04-07T16:16:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"1fad6bef-2fde-4114-9525-dafbb498afcd","html_url":"https://github.com/Morebec/YDB","commit_stats":null,"previous_names":[],"tags_count":2,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morebec%2FYDB","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morebec%2FYDB/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morebec%2FYDB/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morebec%2FYDB/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Morebec","download_url":"https://codeload.github.com/Morebec/YDB/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248844073,"owners_count":21170486,"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":["database","php","table-schema","yaml","ydb"],"created_at":"2024-12-06T20:15:24.103Z","updated_at":"2025-10-05T05:54:05.256Z","avatar_url":"https://github.com/Morebec.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# YDB\nYDB is a simple PHP utility library to use Yaml as a flat file databases\n\n[![Build Status](https://travis-ci.com/Morebec/YDB.svg?branch=master)](https://travis-ci.com/Morebec/YDB)\n\nYDB is a PHP library used by Morebec in some client projects to allow the use of\nyaml files as a database. Some of our clients have technical abilities to view and\nedit YAML files and therefore want their projects to save all their data using this\nformat in such a way that when they require it, they can manually update the data themselves.\nIt also provides the benifit of applying VCS on the database's data.\nYDB therfore provides an easy way to communicate with such a database in a\nsimple and efficient way. It offers functionalities, like table management, table schema\nupdates and data indexing for improved performance, as well as a custom SQL like language\ncalled YQL that allows to query the database in a more user-friendly manner.\n\n## Installation\nTo install the library in a project, add this to your `composer.json` file:\n\n```json\n{\n    // ...\n    \"repositories\": [\n        {\n            \"url\": \"https://github.com/Morebec/YDB.git\",\n            \"type\": \"git\"\n        }\n    ],\n\n    \"require\": {\n        // ...\n        \"morebec/ydb\": \"dev-master\"\n    }\n    // ...\n}\n```\n\n## Usage\n### Create a Database\nA database can be created by doing the following:\n\n```php\n// Create a configuration object for the database\n$config = new DatabaseConfig(\n    Directory::fromStringPath(__DIR__ . '/../_data/test-db')\n);\n\n// To enable logging\n$config-\u003eenabledLogging();\n\n// To disable indexing\n$config-\u003edisableIndexing();\n\n// Create the database\n$database = new Database($config);\n```\n\nThis would result in the following file structure at the directory of the database:\n\n```\ntest-db/\n    logs/\n    tables/\n        table-1/\n            ...\n        table-2/\n            ...\n```\n\n\n### Create a Table\nTables are created using a `TableSchema` that defines the columns of the table.\n\nA table schema is created this way\n```php\n$schema = new TableSchema('test-query-record', [\n    new Column('id', ColumnType::STRING(), true /* indexed */),\n    new Column('first_name', ColumnType::STRING()),\n    new Column('last_name', ColumnType::STRING()),\n    new Column('age', ColumnType::INTEGER())\n]);\n```\n\nAnd to create the table: \n\n```php\n// This function will return a table object that can be used to be queried\n$table = $database-\u003ecreateTable($schema);\n```\n\n### Create a Record\nT add a new record to the database, one must use a Record Object.\nA record can be constructed as follows:\n\n```php\n$r = new Record(\n    RecordId::generate(), // This will generate a Uuidv4 id.\n    [\n        'first_name' =\u003e 'Barney',\n        'last_name' =\u003e 'Stinson',\n        'age' =\u003e 31\n    ]\n);\n\n// And then add the record to the table\n$table-\u003eaddRecord($record);\n```\n\n**Note on ids**: If you want to have a different type of id, simply create a class \nimplementing the `RecordIdInterface`.\n\n### Query a Record\nIn order to query a record, one must create a Query Object:\n\n```php\n\n// Multiple Criteria\n$r = $table-\u003equeryOne(\n    new Query([\n        new Criterion('first_name', Operator::STRICTLY_EQUAL(), 'James'),\n        new Criterion('last_name', Operator::STRICTLY_EQUAL(), 'Bond'),\n        new Criterion('age', Operator::GREATER_OR_EQUAL(), 42)\n    ]);\n);\n\n// Helper static methods\n$r = $table-\u003equeryOne(Query::findById($record-\u003egetId()));\n\n$r = $table-\u003equeryOne(\n    Query::findByField('first_name', Operator::STRICTLY_EQUAL(), 'James')\n);\n```\n\nHowever the easiest way is to use the Query builder:\n\n```php\n// This query will find all records that have 'James Bond' as their full name or\n// that are 35 years old or less\n$query = QueryBuilder::find('first_name', Operator::STRICTLY_EQUAL(), 'James')\n                     -\u003eand('last_name', Operator::STRICTLY_EQUAL(), 'Bond')\n                     -\u003eor('age', Operator::LESS_OR_EQUAL(), 35)\n                     -\u003ebuild()\n;\n$r = $table-\u003equery($query);\n```\n\n## Running Tests\n\n```bash\n# Will run all tests including performance tests\ncomposer test\n\n# Will run all tests excluding performance tests\ncomposer test-no-performance\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorebec%2Fydb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmorebec%2Fydb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorebec%2Fydb/lists"}