{"id":27194790,"url":"https://github.com/j-dumbell/snow-builder","last_synced_at":"2025-04-09T19:36:30.369Z","repository":{"id":65152418,"uuid":"579679641","full_name":"j-dumbell/snow-builder","owner":"j-dumbell","description":"Type-safe NodeJS query builder library for Snowflake with smart return type inference, written in Typescript.","archived":false,"fork":false,"pushed_at":"2023-04-25T12:06:24.000Z","size":621,"stargazers_count":8,"open_issues_count":6,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-01T08:02:10.309Z","etag":null,"topics":["nodejs","npm","orm-library","query-builder","snowflake","sql","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/j-dumbell.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-18T14:14:09.000Z","updated_at":"2024-07-25T15:33:26.000Z","dependencies_parsed_at":"2024-11-01T19:40:34.258Z","dependency_job_id":null,"html_url":"https://github.com/j-dumbell/snow-builder","commit_stats":{"total_commits":49,"total_committers":2,"mean_commits":24.5,"dds":0.4693877551020408,"last_synced_commit":"c1fd8f13df9713e2bd9ba00a235c56c81b49efba"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j-dumbell%2Fsnow-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j-dumbell%2Fsnow-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j-dumbell%2Fsnow-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j-dumbell%2Fsnow-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/j-dumbell","download_url":"https://codeload.github.com/j-dumbell/snow-builder/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248098509,"owners_count":21047455,"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":["nodejs","npm","orm-library","query-builder","snowflake","sql","typescript"],"created_at":"2025-04-09T19:36:29.828Z","updated_at":"2025-04-09T19:36:30.338Z","avatar_url":"https://github.com/j-dumbell.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003esnow-builder\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\nType-safe NodeJS query builder library for \u003ca href=\"https://www.snowflake.com/en/\"\u003eSnowflake\u003c/a\u003e with smart return type inference, written in Typescript.\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/j-dumbell/snow-builder/actions/workflows/test.yml\"\u003e\n      \u003cimg src=\"https://github.com/j-dumbell/snow-builder/actions/workflows/test.yml/badge.svg?branch=main\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/j-dumbell/snow-builder/blob/main/LICENSE\"\u003e\n      \u003cimg src=\"https://img.shields.io/badge/License-MIT-yellow.svg\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://badge.fury.io/js/snow-builder\"\u003e\n        \u003cimg src=\"https://badge.fury.io/js/snow-builder.svg\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cbr/\u003e\n\n## Features\n\nSupports the following SQL operations in Snowflake:\n\n- `SELECT` statements, including all SQL clauses and subqueries.\n- `INSERT INTO` rows directly, or the result of a `SELECT` query.\n- `CREATE TABLE`\n\n## Usage\n\n### DB configuration\n\nInstantiate a `Db` instance by passing a [Snowflake NodeJS SDK connection](https://docs.snowflake.com/en/user-guide/nodejs-driver-use.html#establishing-connections) and table definitions. Managing the lifecycle of the Snowflake connection (e.g. connecting \u0026 destroying) is not handled by snow-builder.\n\n```typescript\nimport {\n  TConfig,\n  sNumber,\n  sVarchar,\n  sBoolean,\n  DBConfig,\n  Db,\n} from 'snow-builder';\n\nconst users = {\n  tRef: { db: 'foo', schema: 'bar', table: 'users' },\n  tSchema: {\n    user_id: sNumber(38, 0).notNull(),\n    email: sVarchar().notNull(),\n    is_verified: sBoolean().notNull(),\n    first_name: sVarchar(),\n  },\n} satisfies TConfig;\n\nconst orders = {\n  tRef: { db: 'foo', schema: 'bar', table: 'orders' },\n  tSchema: {\n    order_id: sNumber(38, 0).notNull(),\n    user_id: sNumber(38, 0).notNull(),\n    order_date: sDate().notNull(),\n    total: sNumber(38, 2).notNull(),\n  },\n} satisfies TConfig;\n\nconst dbConfig = {\n  users,\n  orders,\n} satisfies DBConfig;\n\nconst db = new Db(conn, dbConfig);\n```\n\n### Select queries\n\n```typescript\nconst result = await db\n  .selectFrom('users', 'u')\n  .innerJoin('users', 'u', 'o.user_id', 'u.user_id')\n  .select((f) =\u003e ['u.user_id', f.sum('o.total').as('user_total')])\n  .where('u.is_verified', '=', true)\n  .groupBy('u.user_id')\n  .orderBy('u.first_name')\n  .limit(10)\n  .findMany();\n```\n\n### Inserts\n\n**From Records**\n\nUse the generic type `TInsert` together with the table's `tSchema` property to create the corresponding object type. Snowflake column types are mapped to object properties as per the [Snowflake NodeJS SDK mapping](https://docs.snowflake.com/en/user-guide/nodejs-driver-use.html#data-type-casting). Nullable columns are represented by optional properties.\n\n```typescript\nimport { TInsert } from 'snow-builder';\n\ntype User = TInsert\u003ctypeof users.tSchema\u003e;\n\nconst newUsers: User[] = [\n  {\n    user_id: 1,\n    email: 'blah@gmail.com',\n    is_verified: true,\n    // 'first_name' is optional since nullable\n  },\n];\n\nconst result = await db.insertInto('users', newUsers);\n```\n\n**From Select:**\n\nThe select query's return type must resolve to the same type as the table's corresponding object type (after calling `TInsert`). Nullable fields in the table may be omitted from the select query.\n\n```typescript\nconst query = db\n  .selectFrom('orders', 'o')\n  .select((f) =\u003e [\n    'o.user_id',\n    s\u003cstring\u003e(`'new_email@gmail.com'`).as('email'),\n    s\u003cboolean\u003e('true').as('is_verified'),\n  ])\n  .where('o.user_id', '=', 1)\n  .limit(1);\n\nconst result = await db.insertInto('users', query);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fj-dumbell%2Fsnow-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fj-dumbell%2Fsnow-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fj-dumbell%2Fsnow-builder/lists"}