{"id":20663577,"url":"https://github.com/yanun0323/sworm","last_synced_at":"2025-04-19T15:55:25.668Z","repository":{"id":177663703,"uuid":"659304842","full_name":"yanun0323/Sworm","owner":"yanun0323","description":"The fantastic ORM library of SQLite for Swift, makes life easier.","archived":false,"fork":false,"pushed_at":"2025-01-18T15:44:15.000Z","size":58735,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T09:41:54.988Z","etag":null,"topics":["orm","sqlite","swift","swiftui"],"latest_commit_sha":null,"homepage":"","language":"Swift","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/yanun0323.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-27T14:46:34.000Z","updated_at":"2025-03-22T06:11:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"543be195-b3a6-4eb1-9ea7-d836c845d830","html_url":"https://github.com/yanun0323/Sworm","commit_stats":null,"previous_names":["yanun0323/sworm"],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanun0323%2FSworm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanun0323%2FSworm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanun0323%2FSworm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanun0323%2FSworm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yanun0323","download_url":"https://codeload.github.com/yanun0323/Sworm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249731218,"owners_count":21317341,"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":["orm","sqlite","swift","swiftui"],"created_at":"2024-11-16T19:18:43.542Z","updated_at":"2025-04-19T15:55:25.647Z","avatar_url":"https://github.com/yanun0323.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sworm\n\nThe fantastic SQLite ORM library for Swift base on [SQLite](https://github.com/stephencelis/SQLite.swift).\n\n### Sample Code\n\n#### Definition\n```swift\n// implement Model protocol\nextension Element: Model {\n    static let id = Expression\u003cInt64\u003e(\"id\")\n    static let name = Expression\u003cString\u003e(\"name\")\n    static let value = Expression\u003cDecimal\u003e(\"value\")\n    \n    static var table: Tablex { .init(\"elements\") }\n    \n    static func migrate(_ db: DB) throws {\n        try db.run(table.create(ifNotExists: true) { t in\n            t.column(id, primaryKey: .autoincrement)\n            t.column(name, unique: true)\n            t.column(value)\n        })\n        \n        try db.run(table.createIndex(name, ifNotExists: true))\n    }\n    \n    static func parse(_ r: Row) throws -\u003e Element {\n        return Element(\n            id: try r.get(id),\n            name: try r.get(name),\n            value: try r.get(value)\n        )\n    }\n\n    // setter is for quick insert/update/upsert\n    // ** please DO NOT set primary key in setter **\n    func setter() -\u003e [Setter] {\n        return [\n            Element.name \u003c- name,\n            Element.age \u003c- age\n        ]\n    }\n}\n```\n\n#### Usage\n```swift\n// initialize SQLite database and migrate tables with structures\n// before you do every thing\nfunc setup() {\n    let db = Sworm.setup(dbName: \"database\", isMock: false)\n    db.migrate(Element.self, Record.self)\n}\n\n// query\nfunc getElement(_ id: Int64) throws -\u003e Element? {\n    return try Sworm.db.query(Element.self) { $0.where(Element.id == id) }.first\n}\n\nfunc listElements() throws -\u003e [Element] {\n    return try Sworm.db.query(Element.self) { $0 }\n}\n\n// insert\nfunc createElement(_ elem: Element) throws -\u003e Int64 {\n    return try Sworm.db.insert(elem)\n}\n\n// update\nfunc updateElement(_ elem: Element) throws -\u003e Int {\n    return try Sworm.db.update(elem) { $0.where(Element.id == elem.id) }\n}\n\n// upsert\nfunc upsertElement(_ elem: Element) throws -\u003e Int64 {\n    return try Sworm.db.upsert(elem, Element.id) { $0.where(Element.id == elem.id) }\n}\n\n// delete\nfunc deleteElement(_ id: Int64) throws -\u003e Int {\n    return try Sworm.db.delete(Element.self) { $0.where(Element.id == id)\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyanun0323%2Fsworm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyanun0323%2Fsworm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyanun0323%2Fsworm/lists"}