{"id":49943348,"url":"https://github.com/rwillians/qx","last_synced_at":"2026-05-17T12:33:39.904Z","repository":{"id":326922870,"uuid":"1107161870","full_name":"rwillians/qx","owner":"rwillians","description":"A teeny tiny ORM for SQLite.","archived":false,"fork":false,"pushed_at":"2026-02-25T18:15:09.000Z","size":173,"stargazers_count":0,"open_issues_count":5,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-02-25T19:53:45.242Z","etag":null,"topics":["bun","javascript","orm","sqlite","sqlite-database","sqlite3","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/rwillians.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-30T17:38:48.000Z","updated_at":"2026-02-25T18:15:10.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/rwillians/qx","commit_stats":null,"previous_names":["rwillians/quex","rwillians/qx"],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/rwillians/qx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwillians%2Fqx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwillians%2Fqx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwillians%2Fqx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwillians%2Fqx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rwillians","download_url":"https://codeload.github.com/rwillians/qx/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwillians%2Fqx/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33138406,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-17T09:28:26.183Z","status":"ssl_error","status_checked_at":"2026-05-17T09:27:52.702Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["bun","javascript","orm","sqlite","sqlite-database","sqlite3","typescript"],"created_at":"2026-05-17T12:33:39.065Z","updated_at":"2026-05-17T12:33:39.893Z","avatar_url":"https://github.com/rwillians.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# qx\n\nA teeny tiny, type-safe and dependency-free ORM for TypeScript and\nJavaScript.\n\nBuilt for you who wants a simple, small ORM that just works.\n\n```ts\nimport * as sqlite from '@rwillians/qx/bun-sqlite';\nimport { create, from, into, table } from '@rwillians/qx';\n\nconst users = table('users', t =\u003e ({\n  id: t.integer().autoincrement().primaryKey(),\n  name: t.string(),\n  email: t.string(),\n  createdAt: t.datetime(),\n}));\n\n// ...\n\nconst db = sqlite.connect('./db.sqlite');\n\nawait create.table(users).onto(db);\n\n// ...\n\nconst rows = await into(users)\n  .insert({ name: 'John Doe', email: 'john.doe@gmail.com' })\n  .insert([ userA, userB, userC ])\n  .run(db);\n\n// ...\n\nconst user = await from(users.as('u'))\n  .where(({ u }) =\u003e e.eq(u.id, 1))\n  .one(conn);\n\nif (!user) {\n  throw new Error('User not found');\n}\n\nconsole.log(user);\n```\n\n- See [roadmap to v1.0.0](https://github.com/users/rwillians/projects/1/views/1).\n- See more [examples](#examples).\n\n\n# Vision\n\nHere's the basics of what I need from an ORM, thus it's my priority to\nbuild it first:\n\n- Defining model fields should be very similar to defining a schema\n  with [Zod](https://zod.dev) (with support for validation refiements\n  and transformations).\n- The model should have a schema compatible with [standard schema](https://github.com/standard-schema/standard-schema),\n  meaning it should be interoperable with [Zod](https://zod.dev),\n  [ArkType](https://arktype.io), [Joi](https://joi.dev), etc.\n- It should have a SQL-Like, type-safe, fluent query builder api that\n  works even for NoSQL databases¹, allowing us to write queries once\n  then use them with any supported database.\n- The query builder should output a plain map representation of the\n  query that can be encoded to JSON, mostly for three reasons:\n    1. It's easy to test;\n    2. Makes it easier to debug queries; and\n    3. Makes `qx` more modular, allowing the community to build\n       their own extensions.\n- The query results should be type-safe.\n\n_¹ Some database adapters might not support all query features, that's\n   expected._\n\nOnce this vision is fullfilled, `qx` will become `v1.0.0`.\n\n\n## Components\n\nThe vision above implies the existence of four main components to this\nlibrary:\n\n1. A table factory that outputs a model with a [standard schema](https://github.com/standard-schema/standard-schema);\n2. A query builder that outputs a plain map representation of the\n   query;\n3. A query engine that orchestrates the query execution using a\n   database adapter; and\n4. Database adapters that can execute queries for a specific database\n   driver.\n\n\n# Database Adapters\n\nDatabase adapters are per driver implementation. Quex ships with a few\nhand picked built-in database adapters:\n\n- [x] bun-sqlite3 (prioritary)\n- [ ] bun-postgres\n- [ ] mongodb\n\nFor community-built adapters, check GitHub's tag [#qx-adapter](https://github.com/topics/qx-adapter)\n(you won't find anything there yet).\n\n\n## Examples\n\nHere are some examples that I'm using to guide the implementation.\n\n**Define a table:**\n```ts\n// src/db/tables/backups.ts\nimport { z } from 'zod/v4';\nimport { type as arktype } from 'arktype';\nimport { defineColumn, create, table } from 'qx';\n\n// custom types\nconst tc = {\n  absolutePath: () =\u003e defineColumn({\n    type: 'VARCHAR',\n    schema: z\n      .string()\n      .refine(str =\u003e str.startsWith('/'), \"must be an absolute path\")\n      .transform(str =\u003e str.endsWith('/') ? str.slice(0, -1) : str)\n  }),\n  bytes: () =\u003e defineColumn({\n    type: 'INTEGER',\n    schema: arktype('number.integer \u003e 0'),\n  }),\n  email: () =\u003e defineColumn({\n    type: 'VARCHAR',\n    schema: z.string().email(),\n  }),\n};\n\nexport const backups = table('backups', t =\u003e ({\n  id: t.integer().autoincrement().primaryKey(),\n  parentId: t.integer().nullable(),\n  state: t.enum(['succeeded', 'failed']).default('succeeded'),\n  path: tc.absolutePath(),\n  size: tc.bytes().nullable(),\n  notifyableContacts: tc.email().array().default([]),\n  //                            ↑ should be stored as VARCHAR[] in postgres\n  //                              should be stored as json encoded TEXT in sqlite\n  createdAt: t.datetime().default(() =\u003e new Date),\n}));\n\nexport type Backup = typeof backups.infer;\nexport type BackupForInsert = typeof backups.inferForInsert;\nexport type BackupForUpdate = typeof backups.inferForUpdate;\n```\n\n**Create the table in the database:**\n```ts\nimport * as sqlite from 'qx/bun-sqlite';\n\n// ...\n\nconst db = sqlite.connect('./db.sqlite');\n\nawait create.table(backups).onto(db);\n```\n\n**Insert rows:**\n```ts\nimport { into } from 'qx';\nimport * as sqlite from 'qx/bun-sqlite';\n\n// ...\n\nconst db = sqlite.connect('./db.sqlite');\n\nconst rows = await into(backups)\n  .insert({ state: 'succeeded', path: '/data/backup_1.tar.gz', size: 104857600 })\n  .run(db);\n```\n\n**Query the table:**\n```ts\nimport { expr, from } from 'qx';\nimport * as sqlite from 'qx/bun-sqlite';\n\nconst conn = sqlite.connect('./db.sqlite');\n\n// ...\n\nconst yesterday = new Date(Date.now() - (24 * 60 * 60 * 1000));\n\nconst results = await from(backups.as('b1'))\n  .leftJoin(backups.as('b2'), ({ b1, b2 }) =\u003e expr.eq(b2.id, b1.parentId))\n  .where(({ b1, b2 }) =\u003e expr.and([\n    expr.eq(b1.state, 'failed'),\n    expr.gte(b1.failedAt, yesterday),\n    expr.eq(b1.scheduledBy, 'johndoe@gmail.com'),\n  ]))\n  .orderBy(({ b1 }) =\u003e expr.desc(b1.scheduledAt))\n  .limit(25)\n  .offset(0)\n  .select(({ b1, b2 }) =\u003e ({\n    ...b1,\n    parentPath: b2.path,\n    totalSizeMiB: expr.div(expr.add(b1.size, expr.coalesce(b2.size, 0)), 1048576),\n  }))\n  .all(db);\n```\n\nNo singleton magic here! Not on my watch. You need to explicitly pass\nthe db connection to the query.\n\nThe results would look like this:\n\n```ts\n[\n  {\n    id: 2,\n    parentId: 1,\n    state: 'failed',\n    path: '/backups/20251130133100.tar.gz',\n    size: 104857600,\n    notifyableContacts: ['devops@ecma.com'],\n    createdAt: new Date('2025-11-30T13:31:00.000Z'),\n    parentPath: '/backups/20251030134200.tar.gz',\n    totalSizeMiB: 42069,\n  }\n]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frwillians%2Fqx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frwillians%2Fqx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frwillians%2Fqx/lists"}