{"id":17298020,"url":"https://github.com/inlife/squirrel-orm","last_synced_at":"2025-04-14T12:24:23.485Z","repository":{"id":47232265,"uuid":"67304746","full_name":"inlife/squirrel-orm","owner":"inlife","description":"Simple OOP-based ORM for squirrel-lang","archived":false,"fork":false,"pushed_at":"2021-09-07T19:14:01.000Z","size":96,"stargazers_count":8,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-28T01:46:23.231Z","etag":null,"topics":["database","mysql","nut","orm","sql","sqlite","squirrel"],"latest_commit_sha":null,"homepage":"","language":"Squirrel","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/inlife.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":"2016-09-03T18:11:42.000Z","updated_at":"2023-04-16T23:15:20.000Z","dependencies_parsed_at":"2022-09-10T13:22:10.035Z","dependency_job_id":null,"html_url":"https://github.com/inlife/squirrel-orm","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/inlife%2Fsquirrel-orm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inlife%2Fsquirrel-orm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inlife%2Fsquirrel-orm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inlife%2Fsquirrel-orm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/inlife","download_url":"https://codeload.github.com/inlife/squirrel-orm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248879010,"owners_count":21176419,"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","mysql","nut","orm","sql","sqlite","squirrel"],"created_at":"2024-10-15T11:17:50.398Z","updated_at":"2025-04-14T12:24:23.433Z","avatar_url":"https://github.com/inlife.png","language":"Squirrel","readme":"# squirrel-orm\n\nHey everybody. Are you tired of making same actions over and over, creating, formatting and populating those stupid SQL requests, and after all of that, you also need to fetch and transform all the returned data. And do it for every table! \n\nToday im gonna show you how to make your (your dev team) life easier and happier.\n\n## What is it ?\nThis is a small library that wraps your data and maps it to the table fields in database. Adding operations for fast access, modifications and saving without any extra work.\n\n## How it works:\n\nFirst of all you need to declare your model(s):\n\n```squirrel\nclass Player extends ORM.Entity {\n    \n    /**\n     * Didn't find any way to get current classname\n     * so, we need to set it up manually\n     * @type {String}\n     */\n    static classname = \"Player\";\n\n    /**\n     * Set up table name\n     * @type {String}\n     */\n    static table = \"tbl_players\";\n\n    /**\n     * Set up mapping for different values/columns inside table\n     * @type {Array}\n     */\n    static fields = [\n        ORM.Field.String({ name = \"username\", }),\n        ORM.Field.Password({ name = \"password\" }),\n        ORM.Field.Timestamp({ name = \"registeredAt\" })\n    ];\n\n    /**\n     * Set up traits\n     * (predefined collections of fields)\n     * @type {Array}\n     */\n    static traits = [\n        ORM.Trait.Positionable()\n    ];\n}\n```\n\nAnd now we can access all the beauty of the library; You can use high-level abstractions:\n\n```squirrel\n// create new record\nlocal player = Player();\n\nplayer.username = \"John\";\nplayer.password = \"123123\";\n\nplayer.save();\n\n// find one player by id\nPlayer.findOneBy({ id = 15 }, function(err, player) {\n\t::print(player.username);\n\t\n\t// you can change some fields and save the model right after\n\tplayer.username = \"newusername\";\n\tplayer.save();\n});\n\n// or delete all of them\nPlayer.findAll(function(err, players) {\n\tforeach (idx, player in players) {\n\t\tplayer.remove();\n\t}\n});\n```\n\nOr you can show your damn ninja skillz with some SQL:\n\n```squirrel\nlocal q = ORM.Query(\"\n\tselect \n\t\tp.id,\n\t\tp.username as nickname,\n\t\tconcat(\n\t\t\t'item: ', pi.title,\n\t\t\t' size: ', pi.size\n\t\t) as inventory,\n\t\tpv.plate as car_plate\n\t\t\n\tfrom @Player p\n\t\n\tleft join @PlayerItem pi on pi.player_id = p.id\n\tleft join @PlayerVehicle pv on pv.player_id = p.id\n\t\n\twhere p.id = :id and pi.id = :item_id\n\");\n\nq.setParameter(\"id\", 15);\nq.setParameter(\"item_id\", 2424);\n\nq.getSingleResult(function(err, data) {\n\t::print(data[\"inventory\"]);\n});\n```\nNote: **@Player** or **@PlayerItem**, ..., are synonyms for registered model class. They will be replace to a table names described in each entity class.\n\n## Installation:\n\n1. Download in any convinient way to you. (you can download only dst/index.nut)\n2. Put somewhere not far away from your binary (*.exe)\n3. Insert code where you want to use it:\n\n#### Common MySQL example:\n\n```squirrel\n// load lib where you want it to work\n// note, path relative to your PWD\n// (Process Working Directory)\ndofile(\"./orm/dst/index.nut\", true);\n\n// and set up driver (this example uses simple mysql)\nORM.Driver.setProxy(function(queryString, callback) {\n    local query = mysql_query(queryString);\n    \n    // return data inside ORM\n    callback(null, mysql_fetch_assoc(query));\n    \n    // free\n    mysql_free_result(query);\n});\n\n// now use it!\n```\n\n#### Mafia 2 Online SQLite example:\n```squirrel\n// load lib where you want it to work\n// note, path relative to your PWD\n// (Process Working Directory)\ndofile(\"./orm/dst/index.nut\", true);\n\nORM.Driver.setProxy(function(queryString, callback) {\n    local result = [];\n    local tmp = connection.query(queryString);\n\n    // manuanlly push sqlite forced last inserted id after insert\n    if (queryString.slice(0, 6).toupper() == \"INSERT\") {\n        tmp = connection.query(\"select last_insert_rowid() as id\");\n    }\n\n    // override empty result\n    if (!tmp) tmp = [];\n\n    // override tmp indexes\n    foreach (idx, value in tmp) {\n        result.push(value);\n    }\n\n    // return data inside ORM\n    callback(null, result);\n});\n\n// NOTE: configuring orm to work\n// with sqlite (some differences)\nORM.Driver.configure({\n    provider = \"sqlite\"\n});\n```\n\n## Developers\nIf You want, you can help with development of this library. All you need to do is to clone it locally, and start doing stuff. However you need to have installed squirrel binary `sq` :p\n\n### Unit testing\nAlso, there is a testing suite, (unit testing) to test if stuff still works after your changes. \n\nTo run it, use: `sq test/index.nut`\n(You dont need actual database to test most of those). Look inside test/index.nut for details.\n\n### Building\nAfter you've successfuly tested all the stuff, you can now build composited file via `./build.sh`.\nAnd submit pull request! :p\n\n## License\nCheck out [LICENSE](LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finlife%2Fsquirrel-orm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finlife%2Fsquirrel-orm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finlife%2Fsquirrel-orm/lists"}