{"id":45805,"library":"postgres-partial","title":"postgres-partial","description":"A lightweight wrapper around postgres.js (the porsager/postgres library) for building partial and dynamic SQL queries. Version 0.2.0 is the latest and only release. Unlike query builders like Knex or raw template strings, postgres-partial allows composing SQL fragments (e.g., WHERE clauses, SET clauses) that are merged into a final statement while preserving parameter safety. Designed for projects that use postgres.js and need a minimal, typed way to conditionally build queries without a full ORM. Types included.","status":"active","version":"0.2.0","language":"javascript","source_language":"en","source_url":"git://github.com/yckao/postgres-partial","tags":["javascript","postgres.js","postgres","sql","typescript"],"install":[{"cmd":"npm install postgres-partial","lang":"bash","label":"npm"},{"cmd":"yarn add postgres-partial","lang":"bash","label":"yarn"},{"cmd":"pnpm add postgres-partial","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; postgres-partial is a wrapper around postgres.js and requires it to be installed.","package":"postgres.js","optional":false}],"imports":[{"note":"The module exports named functions, not a default export. All helpers are top-level exports.","wrong":"import postgresPartial from 'postgres-partial'","symbol":"sql, and, or, not, eq, neq, gt, gte, lt, lte, like, ilike, in, notIn, isNull, isNotNull, between, notBetween","correct":"import { sql, eq, and } from 'postgres-partial'"},{"note":"TypeScript type for a partial query object; also exported as a type.","wrong":"","symbol":"PartialQuery","correct":"import { PartialQuery } from 'postgres-partial'"},{"note":"Type for the context object passed to `sql` to build the final query.","wrong":"","symbol":"Context","correct":"import { Context } from 'postgres-partial'"}],"quickstart":{"code":"import postgres from 'postgres';\nimport { sql, eq, and } from 'postgres-partial';\n\nconst db = postgres(process.env.DATABASE_URL ?? '');\n\n// Build a partial query\nconst partial = sql`SELECT * FROM users WHERE ${and(\n  eq('name', 'Alice'),\n  eq('age', 30)\n)}`;\n\n// Apply to a full query using the context\nconst context = partial.getContext();\nsql`${sql('')}${context.query}`; // Unused here; instead:\nconst finalSql = sql`${partial}`;\nconst result = await db.unsafe(finalSql);","lang":"typescript","description":"Shows building a SELECT query with dynamic WHERE conditions using `and`, `eq`, and the `PartialQuery` object."},"warnings":[{"fix":"Use e.g. eq('name', userInput) instead of sql`name = ${userInput}`.","message":"Do not interpolate user input directly into partial queries; always use the provided helpers like eq() to avoid SQL injection.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"None.","message":"No breaking changes yet as this is the initial release (0.2.0).","severity":"breaking","affected_versions":"0.2.0"},{"fix":"None.","message":"No deprecations yet.","severity":"deprecated","affected_versions":"0.2.0"}],"env_vars":null,"search_vec":"'0.2.0':20 'allow':39 'around':7 'build':13,73 'builder':29 'claus':45,47 'compos':40 'condit':72 'design':59 'dynam':16 'e.g':43 'final':53 'fragment':42 'full':77 'includ':80 'javascript':81 'knex':31 'latest':23 'librari':11 'lightweight':5 'like':30 'merg':50 'minim':68 'need':66 'orm':78 'paramet':57 'partial':3,14,38 'porsager/postgres':10 'postgr':2,37,83 'postgres-parti':1,36 'postgres.js':8,64,82 'preserv':56 'project':61 'queri':18,28,74 'raw':33 'releas':26 'safeti':58 'set':46 'sql':17,41,84 'statement':54 'string':35 'templat':34 'type':69,79 'typescript':85 'unlik':27 'use':63 'version':19 'way':70 'without':75 'wrapper':6","created_at":"2026-06-07T12:56:49.018717+00:00","updated_at":"2026-06-07T12:56:49.018717+00:00","problems":[{"fix":"Ensure you have imported `sql` from 'postgres-partial' (not from 'postgres') and that the template literal uses the imported `sql` function.","cause":"Calling getContext on a template literal result that hasn't been converted to a PartialQuery object properly.","error":"TypeError: sql(...).getContext is not a function"},{"fix":"Add `import { eq } from 'postgres-partial'`.","cause":"Forgetting to import `eq` from 'postgres-partial'.","error":"ReferenceError: eq is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"git://github.com/yckao/postgres-partial","github":"git://github.com/yckao/postgres-partial","docs":null,"changelog":null,"pypi":null,"npm":"postgres-partial","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}