{"id":20396873,"url":"https://github.com/blockzilla101/deno-sqlite-orm","last_synced_at":"2026-04-14T23:32:23.411Z","repository":{"id":135739227,"uuid":"573699032","full_name":"Blockzilla101/deno-sqlite-orm","owner":"Blockzilla101","description":"sqlite orm library for deno","archived":false,"fork":false,"pushed_at":"2024-11-25T13:25:58.000Z","size":53,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-12T00:23:06.257Z","etag":null,"topics":["deno","deno-module","orm","sqlite"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Blockzilla101.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-03T06:12:27.000Z","updated_at":"2024-11-25T13:25:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"eba0b2f4-2c62-4108-9b08-d0b1e74bb907","html_url":"https://github.com/Blockzilla101/deno-sqlite-orm","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/Blockzilla101/deno-sqlite-orm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blockzilla101%2Fdeno-sqlite-orm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blockzilla101%2Fdeno-sqlite-orm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blockzilla101%2Fdeno-sqlite-orm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blockzilla101%2Fdeno-sqlite-orm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Blockzilla101","download_url":"https://codeload.github.com/Blockzilla101/deno-sqlite-orm/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blockzilla101%2Fdeno-sqlite-orm/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260050986,"owners_count":22951574,"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":["deno","deno-module","orm","sqlite"],"created_at":"2024-11-15T04:10:08.901Z","updated_at":"2026-04-14T23:32:23.373Z","avatar_url":"https://github.com/Blockzilla101.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Sqlite ORM for deno. Tables with relations are not supported.\n\n#### Usage\n**Create an instance of the ORM:**\n```typescript\nimport { SqliteOrm, SqlTable } from 'https://deno.land/x/deno_sqlite_orm@1.2.0/mod.ts';\nconst orm = new SqliteOrm({\n    dbPath: 'path/to/database.db'\n});\n```\nYou can access the database instance directly by `orm.db`. If you are using an existing database and it contains JSON objects, enable `jsonCompatMode` in options or objects similar to following will not be parsed.\n```json\n{\n    \"foo\": \"baz\",\n    \"bar\": 0\n}\n```\n\n**Create a model:**\u003cbr\u003e\nUse the `@orm.model()` decorator for creating a new model. After all models are loaded, call `orm.modelsLoaded()`\n```typescript\n@orm.model()\nclass Foo extends SqlTable {\n\n}\norm.modelsLoaded()\n```\nIncase `Foo` exists in the database but has a different name, use `@orm.model('bar')`. All Tables have `id` as a primary key. \nIt can be removed by overriding it and using `@orm.ignoreColumn()`. Tables are created if they don't exist. If new columns \nare added, the table is altered. If a column is removed from the model, it still stays in the database. If you want to rename the property, or the column exists with a different name use `@orm.mappedTo('oldName')`\n\n**Defining columns:**\u003cbr\u003e\nAll properties of the table are considered as columns. Column types are automatically inferred from the default value\u003cbr\u003e\nof the property.\n```typescript\nclass Foo extends SqlTable {\n@orm.model()\nclass Foo extends SqlTable {\n  // type is automatically inferred as \"string\"\n  public foo = 'bar'\n\n  // column type is required when property doesn't have a default value\n  @orm.columnType('string')\n  public bar!: string\n\n  // set a column as a primary key\n  @orm.primaryKey()\n  public fooId = 0\n\n  // ignore property\n  @orm.ignoreColumn()\n  @orm.autoIncrement() // mark it as autoincrement\n  public ignored = 0\n  \n  // remove id from primary key\n  @orm.ignoreColumn()\n  public id = -1\n\n  // automatically marked as nullable\n  @orm.columnType('string')\n  @orm.nullable() // or manually mark it\n  public baz: string | null = null\n\n  // incase the column exists with a different name\n  @orm.mappedTo('bar')\n  public baa = ''\n\n  // if you don't want to stack multiple decorators, you can do:\n  @orm.column({ type: 'string', nullable: true })\n  public faz!: string | null\n}\n```\n**Querying data:**\n```typescript\n// find a single a row, throws an error (`DBNotFound`) when not found\norm.findOne(Foo, 1) // finds a row in Foo where id = 1\n// equivalent to above\norm.findOne(Foo, {\n  where: {\n    clause: 'id = ?',\n    values: [1] // optional when not using placeholders\n  }\n})\n\n// same usage as above, but returns a new instance of `Foo` when not found\n// you can check if its new from `Foo._new`\norm.findOneOptional(Foo, 1)\n\n// same as `findOne` but returns multiple instances of or rows of Foo\norm.findMany(Foo, {\n  where: {\n    clause: 'id \u003e 5'\n  },\n  limit: 10, // optional\n  offset: 3 // optional\n})\n\n// save an instance of Foo\nconst baz = new Foo()\norm.save(baz)\n\n// delete rows from Foo where id = 1\norm.delete(Foo, {\n  where: {\n    clause: 'id = 1'\n  }\n})\n\n// count rows of Foo where id \u003c 5\norm.countWhere(Foo, {\n  where: {\n    clause: 'id \u003c 5'\n  }\n})\n\n// or you can do a more advanced count\norm.aggregateSelect\u003c[foo: string, count: number]\u003e(Foo, {\n  select: {\n    clause: 'foo, COUNT(baz)'\n  },\n  group: {\n    cols: ['foo']\n  }\n})\n```\n\n**Saving objects:**\u003cbr\u003e\nObjects are converted to JSON before saving, and parsed when read. If its a class instance then the class should be registered\nby `@registerJsonSerializable()`\n```typescript\nimport { registerJsonSerializable } from 'https://deno.land/x/deno_sqlite_orm@1.2.0/mod.ts';\n\n// the property \"ignored\" will be ignored and not saved\n@registerJsonSerializable(['ignored'])\nclass Bar {\n  public foo = 'bar'\n  public ignored = ''\n}\n\n@orm.model()\nclass Foo extends SqlTable {\n  // type is automatically inferred as json\n  bar: Record\u003cstring, any\u003e = {}\n  baz: Bar = new Bar()\n}\n```\n\n##### Example\n```typescript\nimport { SqliteOrm, SqlTable } from 'https://deno.land/x/deno_sqlite_orm@1.2.0/mod.ts';\nconst orm = new SqliteOrm({\n    dbPath: 'path/to/database.db',\n});\n\n// register the class as a table\n@orm.model()\nclass Foo extends SqlTable {\n  // type is automatically inferred\n  public foo = 'baz'\n\n  // type is required when not set\n  @orm.columnType('string')\n  public bar!: string\n\n  // type is inferred as json\n  public baz: Record\u003cstring, any\u003e = {\n    foo: 'foo',\n    bar: 'baz'\n  }\n  \n  // ignore this property\n  @orm.ignoreColumn()\n  public ignored = ''\n}\n\norm.modelsLoaded()\nconst obj = new Foo()\n\n// save the obj\norm.save(obj)\n\n// fetch the saved obj\nconsole.log(db.findOne(Foo, 1))\n\n// count number of rows of `Foo` where id \u003e 1\nconsole.log(db.countWhere(Foo, {\n  where: {\n    clause: 'id \u003e ?',\n    values: [1]\n  }\n}))\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblockzilla101%2Fdeno-sqlite-orm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblockzilla101%2Fdeno-sqlite-orm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblockzilla101%2Fdeno-sqlite-orm/lists"}