{"id":19435298,"url":"https://github.com/andrey-moura/db","last_synced_at":"2025-02-25T06:43:51.340Z","repository":{"id":57181766,"uuid":"454219830","full_name":"andrey-moura/db","owner":"andrey-moura","description":"A C++ wrapper around SQL based on ActiveRecord","archived":false,"fork":false,"pushed_at":"2024-01-01T17:40:22.000Z","size":2844,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-07T21:09:44.231Z","etag":null,"topics":["activerecord","cpp","cpp17","cpp20","postgres","postgresql","psql","sql","sqlite","sqlite3"],"latest_commit_sha":null,"homepage":"","language":"C","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/andrey-moura.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-02-01T00:49:47.000Z","updated_at":"2024-01-01T14:49:29.000Z","dependencies_parsed_at":"2023-02-18T17:45:55.899Z","dependency_job_id":"5d55532c-8650-435d-b134-29e380a0e190","html_url":"https://github.com/andrey-moura/db","commit_stats":null,"previous_names":["andrey-moura/db"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrey-moura%2Fdb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrey-moura%2Fdb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrey-moura%2Fdb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrey-moura%2Fdb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrey-moura","download_url":"https://codeload.github.com/andrey-moura/db/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240619430,"owners_count":19830204,"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":["activerecord","cpp","cpp17","cpp20","postgres","postgresql","psql","sql","sqlite","sqlite3"],"created_at":"2024-11-10T15:05:20.850Z","updated_at":"2025-02-25T06:43:51.298Z","avatar_url":"https://github.com/andrey-moura.png","language":"C","readme":"# database\n\nSimple cross-platform library based in the ActiveRecord from Ruby, an wrapper around SQL.\n\n## Building \n\n### Linux\n\n```shell\ngit clone https://github.com/Moonslate/database.git\nmkdir build\ncd build\ncmake ..\nmake\n```\n\n## Basic Usage\n\n```cpp\nUser user;\nuser.name = \"Dummy\";\nuser.password = \"Some Password\";\nuser.age = 21;\nuser.save();\n```\n\n### The code above executes\n```sql\nINSERT INTO users(name,password,age) VALUES ('Dummy','Some Password',21) RETURNING id;\n```\n\n### The same can be archivied by\n```cpp\nUser user = User::create({\n    { \"name\", \"Dummy\" },\n    { \"password\", \"Some Password\" }\n    { \"age\", 21 }\n}); \n```\n\n## Creating a new record and a table\n\n```shell\ndatabase new-model user --migrate\n```\n\n### new-model generates the following code\n#### include/models/user.hpp\n```cpp\n#include \u003ccore.hpp\u003e\n#include \u003cdatabase.hpp\u003e\n\nclass User : public uva::database::basic_active_record\n{    \n    uva_database_declare(User);\n};\n```\n\n#### src/models/user.cpp\n```cpp\n#include \u003cuser.hpp\u003e\n\nuva_database_define(User);\n```\n\n### The optional --migrate option generates the following migration\n#### src\\migrations\\20230129161842_add_users_migration.cpp\n```cpp\n#include \u003ccore.hpp\u003e\n#include \u003cdatabase.hpp\u003e\n\n#include \u003cuser.hpp\u003e\n\nclass AddUsersMigration : public uva::database::basic_migration\n{\nuva_declare_migration(AddUsersMigration);\nprotected:\n    virtual void change() override \n    { \n        add_table(\"users\",\n        {\n            { \"id\",         \"INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL\" },\n            { \"updated_at\", \"INTEGER NOT NULL DEFAULT (STRFTIME('%s'))\" },\n            { \"created_at\", \"INTEGER NOT NULL DEFAULT (STRFTIME('%s'))\" },\n            { \"removed\",    \"INTEGER NOT NULL DEFAULT 0\" },\n        });\n    }\n};\n\nuva_define_migration(AddUsersMigration);\n```\n\nColumns are defined inside the map in second parameter of `add_table`. Those columns are accessed by `User::operator[](std::string)`, they'll only be available with the `User::operator.` when exposing the column inside the class:\n\n```cpp\nuva_database_expose_column(password);\n```\n\n## Supported database engines\n\n* SQLite3\n\n## Todo For Next (First) Release\n\n* Before save, update 👌\n* Create database tool 👌\n* Move multiple_value_holder to uva::core (and rename to var) 👌\n* Create database_exception\n* Strongly typed var 👌\n* Complete Todo List of [uva::string](https://github.com/Moonslate/core)\n* Complete Todo List of [uva::string](https://github.com/Moonslate/string)\n* Complete Todo List of [uva::cspec](https://github.com/Moonslate/cspec)\n* Have 100% of tests coverage\n\n### Priority (For future releases)\n\n* 🐞 - Copy constructor of base class not works\n\n## Contributing\nJust make a PR! :)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrey-moura%2Fdb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrey-moura%2Fdb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrey-moura%2Fdb/lists"}