{"id":24737300,"url":"https://github.com/byzanteam/kysely_postgres_js_dialect","last_synced_at":"2026-03-10T12:31:23.956Z","repository":{"id":213683548,"uuid":"734679762","full_name":"Byzanteam/kysely_postgres_js_dialect","owner":"Byzanteam","description":"Kysely dialect for PostgreSQL using the Postgres.js client.","archived":false,"fork":false,"pushed_at":"2024-10-30T05:07:34.000Z","size":36,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-27T12:28:08.533Z","etag":null,"topics":["jet"],"latest_commit_sha":null,"homepage":"https://jsr.io/@byzanteam/kysely-deno-postgres-dialect","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/Byzanteam.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":"2023-12-22T10:13:33.000Z","updated_at":"2024-10-30T05:06:26.000Z","dependencies_parsed_at":"2024-04-10T11:26:11.557Z","dependency_job_id":"9c3aca1b-ea5f-4e10-875c-80a688f51ca6","html_url":"https://github.com/Byzanteam/kysely_postgres_js_dialect","commit_stats":null,"previous_names":["byzanteam/kysely-deno-postgres-dialect","byzanteam/kysely_postgres_js_dialect","byzanteam/kysely_deno_postgres_dialect"],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/Byzanteam/kysely_postgres_js_dialect","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Byzanteam%2Fkysely_postgres_js_dialect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Byzanteam%2Fkysely_postgres_js_dialect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Byzanteam%2Fkysely_postgres_js_dialect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Byzanteam%2Fkysely_postgres_js_dialect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Byzanteam","download_url":"https://codeload.github.com/Byzanteam/kysely_postgres_js_dialect/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Byzanteam%2Fkysely_postgres_js_dialect/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27670308,"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","status":"online","status_checked_at":"2025-12-11T02:00:11.302Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["jet"],"created_at":"2025-01-27T22:07:42.855Z","updated_at":"2025-12-11T21:11:44.998Z","avatar_url":"https://github.com/Byzanteam.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# kysely-deno-postgres-dialect\n\n[![ci](https://github.com/Byzanteam/kysely_deno_postgres_dialect/actions/workflows/ci.yml/badge.svg)](https://github.com/Byzanteam/kysely_deno_postgres_dialect/actions/workflows/ci.yml)\n[![JSR](https://jsr.io/badges/@byzanteam/kysely-deno-postgres-dialect)](https://jsr.io/@byzanteam/kysely-deno-postgres-dialect)\n\n[Kysely](https://github.com/kysely-org/kysely) dialect for PostgreSQL using the\n[postgresjs](https://github.com/porsager/postgres) client.\n\n## 🚀 Getting started\n\n### Install dependencies\n\n```\ndeno add @byzanteam/kysely-deno-postgres-dialect\n```\n\nOptional: Import using `imports` in `deno.json`, if you dont want to use `npm`\nregistry.\n\n```json\n{\n  \"imports\": {\n    \"kysely-deno-postgres-dialect\": \"jsr:@byzanteam/kysely-deno-postgres-dialect\",\n    \"postgresjs\": \"https://deno.land/x/postgresjs@v3.4.4/mod.js\",\n    \"kysely\": \"https://esm.sh/kysely@0.27.4\"\n  }\n}\n```\n\n### Use kysely-deno-postgres-dialect\n\n1. Define your database schema\n\n```typescript\nimport postgres from \"postgresjs/mod.js\";\nimport { type Generated, Kysely } from \"kysely\";\nimport {\n  PostgresJSDialect,\n  setup,\n  wrapTransaction as wrapTransactionFn,\n} from \"kysely-deno-postgres-dialect\";\n\ninterface UserTable {\n  id: Generated\u003cnumber\u003e;\n  name: string;\n}\n\ninterface Database {\n  users: UserTable;\n}\n```\n\n2. Setup the kysely instance before using it\n\n```typescript\nsetup(() =\u003e {\n  const dialect = new PostgresJSDialect({\n    postgres: postgres(\n      {\n        database: \"postgres\",\n        hostname: \"localhost\",\n        password: \"postgres\",\n        port: 5432,\n        user: \"postgres\",\n        max: 10,\n      },\n    ),\n  });\n\n  return new Kysely\u003cDatabase\u003e({\n    dialect,\n  });\n});\n```\n\n3. Make your own `wrapTransaction` function that incorporates a database context\n\n```typescript\nasync function wrapTransaction\u003cT\u003e(\n  callback: Parameters\u003ctypeof wrapTransactionFn\u003cDatabase, T\u003e\u003e[0],\n): Promise\u003cT\u003e {\n  return await wrapTransactionFn\u003cDatabase, T\u003e(callback);\n}\n```\n\n4. Use the `wrapTransaction` function to execute queries\n\n```typescript\nconst users = await wrapTransaction(async (trx) =\u003e {\n  return await trx.selectFrom(\"users\").selectAll().execute();\n});\n```\n\n## 🩺 Testing\n\n\u003e [!TIP]\\\n\u003e See examples at `./tests/testing/utils_test.ts`.\n\n`setupTesting` function is provided to set up the testing environment. It stubs\ntransaction functions, and each test runs in a transaction that is rolled back\nafter the test. Theoretically, tests are isolated from each other, and can be\nrun in parallel.\n\n1. Add a helper function to setup the testing database\n\n```typescript\n// test_helper.ts\n\nimport { PostgresJSDialect, setup } from \"kysely-deno-postgres-dialect\";\nimport { Kysely } from \"kysely\";\nimport postgres from \"postgresjs\";\n\nexport function setupTestingDB() {\n  setup(() =\u003e {\n    const dialect = new PostgresJSDialect({\n      postgres: postgres(\n        {\n          database: \"postgres\",\n          hostname: \"localhost\",\n          password: \"postgres\",\n          port: 5432,\n          user: \"postgres\",\n          max: 10,\n        },\n      ),\n    });\n\n    return new Kysely\u003cDatabase\u003e({\n      dialect,\n    });\n  });\n}\n```\n\n2. Setup the testing environment in the test files, and write tests\n\n```typescript\n// test files\n\nimport { setupTesting } from \"kysely-deno-postgres-dialect/testing\";\nimport { stub } from \"jsr:@std/testing/mock\";\nimport {\n  afterAll,\n  afterEach,\n  beforeAll,\n  beforeEach,\n  describe,\n  it,\n} from \"jsr:@std/testing/bdd\";\n\nsetupTesting({ stub, beforeEach, afterEach, beforeAll, afterAll });\n\ndescribe(\"this is a description\", () =\u003e {\n  it(\"works\", async () =\u003e {\n    // snip\n  });\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbyzanteam%2Fkysely_postgres_js_dialect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbyzanteam%2Fkysely_postgres_js_dialect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbyzanteam%2Fkysely_postgres_js_dialect/lists"}