{"id":16359127,"url":"https://github.com/valentindebon/sqlcodable","last_synced_at":"2025-12-30T13:30:15.283Z","repository":{"id":54152448,"uuid":"332175240","full_name":"ValentinDebon/SQLCodable","owner":"ValentinDebon","description":null,"archived":false,"fork":false,"pushed_at":"2021-06-05T21:05:12.000Z","size":57,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-29T16:58:29.083Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ValentinDebon.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":"2021-01-23T09:43:14.000Z","updated_at":"2021-03-07T11:31:40.000Z","dependencies_parsed_at":"2022-08-13T07:40:53.642Z","dependency_job_id":null,"html_url":"https://github.com/ValentinDebon/SQLCodable","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ValentinDebon%2FSQLCodable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ValentinDebon%2FSQLCodable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ValentinDebon%2FSQLCodable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ValentinDebon%2FSQLCodable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ValentinDebon","download_url":"https://codeload.github.com/ValentinDebon/SQLCodable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239720616,"owners_count":19686126,"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-10-11T02:07:35.431Z","updated_at":"2025-12-30T13:30:15.228Z","avatar_url":"https://github.com/ValentinDebon.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SQLCodable\n\nManipulate SQL databases using the SQL language. And interface with Swift using Codable.\n\n## Why?\n\nIn Swift, lots of ORMs and bindings exists. But none of them allows you to write raw SQL and directly interface with the database.\nSQLCodable provides an Opaque Interface to the database and statement management. It doesn't manage nested containers, but encodes\nyour type in a prepared statement, and decodes each row using the parameters/columns names.\n\n## Example\n\nLet's say you're a teacher and want to keep track of every students and the average of their marks for the semester.\nThe following sample illustrates how to create a DAO and interface for and SQLite-backed database.\n\n```swift\nimport SQLiteCodable\nimport SQLCodable\n\nstruct Student : Codable {\n\tlet firstname: String\n\tlet lastname: String\n\tlet average: Double\n}\n\nfinal class StudentDAO : SQLDataAccessObject {\n\tlet database: SQLDatabase\n\n\tinit(database: SQLDatabase) throws {\n\t\tself.database = database\n\n\t\ttry self.query(\"\"\"\n\t\t\tcreate table if not exists students (\n\t\t\t\tfirstname text,\n\t\t\t\tlastname text,\n\t\t\t\taverage real,\n\n\t\t\t\tprimary key (firstname, lastname)\n\t\t\t)\n\t\t\"\"\").next()\n\t}\n\n\tfunc add(student: Student) throws {\n\t\ttry self.query(\"insert into students values (:firstname, :lastname, :average)\", with: student).next()\n\t}\n\n\tfunc findStudent(firstname: String, lastname: String) throws -\u003e Student? {\n\t\ttry self.query(\"select * from students where firstname = ?1 and lastname = ?2\", with: firstname, lastname).next()\n\t}\n\n\tfunc validStudents(minimum average: Double = 10.0) throws -\u003e [Student] {\n\t\ttry Array(self.query(\"select * from students where average \u003e= ?1 order by average desc\", with: average))\n\t}\n}\n\nlet studentDAO = try StudentDAO(database: SQLiteDatabase())\n\ntry studentDAO.add(student: Student(firstname: \"Nino\", lastname: \"Quincampoix\", average:  9.0))\ntry studentDAO.add(student: Student(firstname: \"Raphaël\", lastname: \"Poulain\", average: 7.0))\ntry studentDAO.add(student: Student(firstname: \"Dominique\", lastname: \"Bretodeau\", average: 12.0))\ntry studentDAO.add(student: Student(firstname: \"Raymond\", lastname: \"Dufayel\", average: 17.0))\n\ntry print(studentDAO.findStudent(firstname: \"Dominique\", lastname: \"Bretodeau\")!)\ntry print(studentDAO.validStudents())\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvalentindebon%2Fsqlcodable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvalentindebon%2Fsqlcodable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvalentindebon%2Fsqlcodable/lists"}