{"id":13896243,"url":"https://github.com/ceifa/sqlier","last_synced_at":"2025-03-20T10:30:33.460Z","repository":{"id":48484219,"uuid":"289582815","full_name":"ceifa/sqlier","owner":"ceifa","description":"Yet another gmod database abstraction","archived":false,"fork":false,"pushed_at":"2022-09-02T10:39:21.000Z","size":60,"stargazers_count":30,"open_issues_count":8,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-28T23:52:35.719Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Lua","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/ceifa.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-22T23:25:35.000Z","updated_at":"2025-01-26T00:16:34.000Z","dependencies_parsed_at":"2022-08-27T06:40:18.021Z","dependency_job_id":null,"html_url":"https://github.com/ceifa/sqlier","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/ceifa%2Fsqlier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ceifa%2Fsqlier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ceifa%2Fsqlier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ceifa%2Fsqlier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ceifa","download_url":"https://codeload.github.com/ceifa/sqlier/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244066180,"owners_count":20392406,"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-08-06T18:02:46.046Z","updated_at":"2025-03-20T10:30:33.144Z","avatar_url":"https://github.com/ceifa.png","language":"Lua","funding_links":[],"categories":["Lua"],"sub_categories":[],"readme":"Are you tired of these lots of heavy database libraries which do a lot of things which you don't need? You came at the right place! This project aims to offer a way of writing a very simple code only one time and be able to switch between multiple database drivers without problems. The most easier and lightweight database abstraction of the market!\n\n\u003e Alert: This project will not fill all the edge database cases and does not aim to do so.\n\n## Documentation\nYou can find the full library documentaion [here](https://github.com/ceifa/sqlier/wiki).\n\n## Usage\n\n### Setup a database\n\nFirstly you will need to setup your databases, sqlier can be initialized by running the initializer function `sqlier.Initialize(name, drive, conn)` which accepts the following arguments:\n\n1. `STRING` `name`: Identification name for the database (can be anything)\n2. `STRING` `driver`: The desired database driver, currently supports:\n   - `sqlite`: Uses default [Garry's Mod Sqlite](https://wiki.facepunch.com/gmod/sql) interface\n   - `mysqloo`: Uses the [Mysqloo Module](https://github.com/FredyH/MySQLOO) (provides MySQL interface)\n   - `file`: Uses [plain files](https://wiki.facepunch.com/gmod/file_class) to read and store data\n4. `optional` | `STRING` `Connection info`: Only needed when using MySqloo driver, passing the database authentication details.  \n\n```lua\n -- Sqlite\nsqlier.Initialize(\"db1\", \"sqlite\")\n\n -- MySQL\nsqlier.Initialize(\"db2\", \"mysqloo\", { address = \"localhost\", port = \"3306\", database = \"GmodServer\", user = \"root\", password = \"\" })\n```\n\n### Setup a model\n\nNow you will have to setup a model, it works like a class:\n\n```lua\nlocal User = sqlier.Model({\n    Table = \"user\",\n    Columns = {\n        Id = {\n            Type = sqlier.Type.Integer,\n            AutoIncrement = true\n        },\n        Name = {\n            Type = sqlier.Type.String\n        },\n        Rank = {\n            Type = sqlier.Type.String,\n            MaxLength = 15\n        },\n        SteamId64 = {\n            Type = sqlier.Type.SteamId64\n        },\n        CreateTimestamp = {\n            Type = sqlier.Type.Timestamp\n        }\n    },\n    Identity = \"Id\"\n})\n```\n\nThe columns `CreateTimestamp` and `UpdateTimestamp` are hard-coded internally populated automatically.\n\n### Instantiate, update or delete a model\n\n```lua\nlocal new_user = User({\n    Name = ply:Nick(),\n    SteamId = ply:SteamId64(),\n    Rank = \"user\"\n})\nnew_user:save()\n\nnew_user.Rank = \"donator\"\nnew_user:save()\n\nnew_user:delete()\n```\n\nIf you want to know when a save or delete is done, you can pass a callback or use their async api, if using `util.Promise`:\n\n```lua\nnew_user:save(function()\n    print(\"Save is done\")\nend)\n\nutil.PromiseAsync(function()\n    new_user:saveAsync():Await()\n    new_user:deleteAsync():Await()\nend)\n```\n\n### Querying\n\nWe have some simple methods to do querying:\n\n```lua\n-- The fastest way, get by identity\nUser:get(2, function(user)\nend)\n\n-- Find one by property filtering\nUser:find({ Name = \"ceifa\" }, function(user)\nend)\n\n-- Get many by property filtering\nUser:filter({ Rank = \"donator\" }, function(users)\nend)\n```\n\nIf you have support for `util.Promise`, you can use the async methods:\n\n```lua\nutil.PromiseAsync(function()\n    local user = User:getAsync(2):Await()\n    local user = User:findAsync({ Name = \"ceifa\" }):Await()\n    local users = User:filterAsync({ Rank = \"donator\" }):Await()\nend)\n```\n\nBut if you want more complex queries, you will have to do it yourself:\n\n```lua\nlocal user_db = User:database()\nif user_db.Driver == \"sqlite\" or user_db.Driver == \"mysqloo\" then\n    user_db:query(\"SELECT Name, COUNT(*) as Quantity FROM user GROUP BY Name\", function(names)\n    end)\nelse\n    error(\"Database driver not supported\")\nend\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fceifa%2Fsqlier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fceifa%2Fsqlier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fceifa%2Fsqlier/lists"}