{"id":13535218,"url":"https://github.com/vmanot/SwiftDB","last_synced_at":"2025-04-02T00:32:52.694Z","repository":{"id":50568938,"uuid":"275573647","full_name":"vmanot/SwiftDB","owner":"vmanot","description":"A modern database abstraction layer + runtime, batteries included [WIP].","archived":false,"fork":false,"pushed_at":"2024-11-23T21:31:04.000Z","size":558,"stargazers_count":339,"open_issues_count":0,"forks_count":7,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-03-27T16:12:48.638Z","etag":null,"topics":["attribute","codable","core-data","coredata","database","dsl","property-wrapper","relationship","runtime","sql","swift","swiftui","type-safe","wrapper"],"latest_commit_sha":null,"homepage":"","language":"Swift","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/vmanot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2020-06-28T11:48:11.000Z","updated_at":"2024-12-14T00:23:29.000Z","dependencies_parsed_at":"2024-04-06T07:32:23.854Z","dependency_job_id":"92dcdec3-1896-4d76-8d5d-f0c3716d437c","html_url":"https://github.com/vmanot/SwiftDB","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/vmanot%2FSwiftDB","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmanot%2FSwiftDB/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmanot%2FSwiftDB/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmanot%2FSwiftDB/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vmanot","download_url":"https://codeload.github.com/vmanot/SwiftDB/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246735356,"owners_count":20825221,"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":["attribute","codable","core-data","coredata","database","dsl","property-wrapper","relationship","runtime","sql","swift","swiftui","type-safe","wrapper"],"created_at":"2024-08-01T08:00:51.440Z","updated_at":"2025-04-02T00:32:52.239Z","avatar_url":"https://github.com/vmanot.png","language":"Swift","readme":"# SwiftDB [WIP]\n\n\u003e [!IMPORTANT]\n\u003e This package is under development and is being currently rewritten to fully leverage Swift 5.9.\n\nA modern, type-safe database abstraction layer. SwiftDB aims to be an opinionated DBAL for relational and document-oriented databases. \n\n## Get Started\n\nDefine an `Entity`:\n\n```swift\nstruct Foo: Entity, Identifiable {\n    @Attribute var bar: String = \"Untitled\"\n    \n    var id: some Hashable {\n        bar\n    }\n}\n```\n\nDefine a `Schema`:\n\n```swift\nstruct MySchema: Schema {\n    var entities: Entities {\n        Foo.self\n    }\n}\n```\n\nCreate a `ContentView` for your application:\n\n```swift\nstruct ContentView: View {\n    @StateObject var container = PersistentContainer(MySchema())\n    \n    var body: some View {\n        Text(\"Hello World\")\n    }\n}\n```\n\nCreate a list view:\n\n```swift\nstruct ListView: View {\n    @EnvironmentObject var container: PersistentContainer\n    \n    @QueryModels\u003cFoo\u003e() var models\n    \n    var body: some View {\n        NavigationView {\n            List(models) { foo in\n                NavigationLink(destination: EditView(foo: foo)) {\n                    Text(foo.bar)\n                }\n                .contextMenu {\n                    Button {\n                        container.delete(foo)\n                    } label: {\n                        Text(\"Delete\")\n                    }\n                }\n            }\n            .navigationBarItems(\n                trailing: Button {\n                    container.create(Foo.self)\n                } label: {\n                    Image(systemName: .plusCircleFill)\n                        .imageScale(.large)\n                }\n            )\n            .navigationBarTitle(\"A List of Foo\")\n        }\n    }\n    \n    struct EditView: View {\n        @EnvironmentObject var container: PersistentContainer\n        \n        let foo: Foo\n        \n        var body: some View {\n            VStack {\n                Form {\n                    TextField(\"Enter a value\", text: foo.$bar) {\n                        container.save()\n                    }\n                }\n            }\n            .navigationBarTitle(\"Edit Foo\")\n        }\n    }\n}\n```\n\nAdd it to our `ContentView`:\n\n```swift\nstruct ContentView: View {\n    @StateObject var container = PersistentContainer(MySchema())\n    \n    var body: some View {\n        ListView()\n            .databaseContainer(container)\n    }\n}\n```\n\nThat's it.\n","funding_links":[],"categories":["Swift","CoreData","SwiftUI"],"sub_categories":["Content"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvmanot%2FSwiftDB","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvmanot%2FSwiftDB","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvmanot%2FSwiftDB/lists"}