{"id":15067347,"url":"https://github.com/131/sql-template","last_synced_at":"2025-06-21T06:37:03.265Z","repository":{"id":41407049,"uuid":"58260401","full_name":"131/sql-template","owner":"131","description":"Nodejs template string for SQL queries","archived":false,"fork":false,"pushed_at":"2024-05-22T12:55:56.000Z","size":37,"stargazers_count":16,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T16:48:47.658Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/131.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2016-05-07T10:06:23.000Z","updated_at":"2025-04-09T10:11:04.000Z","dependencies_parsed_at":"2024-05-22T13:57:59.687Z","dependency_job_id":"0e88ba3d-1bbf-4d98-8e59-4c90360b5d1a","html_url":"https://github.com/131/sql-template","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/131%2Fsql-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/131%2Fsql-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/131%2Fsql-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/131%2Fsql-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/131","download_url":"https://codeload.github.com/131/sql-template/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248232633,"owners_count":21069487,"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":[],"created_at":"2024-09-25T01:19:57.526Z","updated_at":"2025-04-10T14:12:30.371Z","avatar_url":"https://github.com/131.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Motivation\nTemplate string builder for SQL.\n\n\n[![Build Status](https://github.com/131/sql-template/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/131/sql-template/actions/workflows/test.yml)\n[![Coverage Status](https://coveralls.io/repos/github/131/sql-template/badge.svg?branch=master)](https://coveralls.io/github/131/sql-template?branch=master)\n[![NPM version](https://img.shields.io/npm/v/sql-template.svg)](https://www.npmjs.com/package/sql-template)\n[![Code style](https://img.shields.io/badge/code%2fstyle-ivs-green.svg)](https://www.npmjs.com/package/eslint-plugin-ivs)\n\n\n## Key features\n* tag based (easily extensible)\n* made with love\n* very simple\n* drop in compatible with pg\n* strongly tested with 100% code coverage\n\n\n# API/Usage\n```\nvar SQL = require('sql-template');\n\npg(SQL`SELECT * FROM foo`)\n  {text: 'SELECT * FROM foo', values: []} \n\npg(SQL`SELECT * FROM foo WHERE age \u003e ${22}`)\n  {text: 'SELECT * FROM foo WHERE age \u003e $1 ', values: [22]} \n```\n\n# Tags (transformers) list\n## $where$\n```\npg(SQL`SELECT * FROM foo $where${ {name:'John doe'} }`)\n  {text: 'SELECT * FROM foo WHERE \"name\" = $1 ', values: [\"John doe\"]} \n\npg(SQL`SELECT * FROM foo $where${ {id: [1,2,3], type:'snow'} }`)\n  {text: 'SELECT * FROM foo WHERE \"id\" IN($1,$2,$3) AND \"type\"=$4 ', values: [1,2,3,\"snow\"]} \n```\n\n## $set$\n```\npg(SQL`UPDATE foo $set${ {joe: 22, bar: 'ok'} }`)\n  {text: 'UPDATE foo SET \"joe\"=$1,\"bar\"=$2', values: [22, 'ok']}\n```\n\n## $keys$\n```\npg(SQL`INSERT INTO foo $keys${[\"joe\", \"bar\"]} VALUES (${22}, ${'ok'})}`)\n  {text: 'INSERT INTO foo (\"joe\", \"bar\") VALUES ($1,$2), values: [22, 'ok']}\n```\n\n## $values$\n```\npg(SQL`INSERT INTO foo (joe, bar) $values${ {joe: 22, bar: 'ok'} }`)\n  {text: 'INSERT INTO foo (joe, bar) VALUES ($1,$2), values: [22, 'ok']}\n  \nconst obj = {joe: 22, bar: 'ok'};\npg(SQL`INSERT INTO foo $keys${Object.keys(obj)} $values${obj}`)\n  {text: 'INSERT INTO foo (\"joe\",\"bar\") VALUES ($1,$2), values: [22, 'ok']}\n```\nor use the `SQL.insert` static api.\n\n## $id$\n```\npg(SQL`SELECT * FROM $id${'foo'}`)\n  {text: 'SELECT * FROM \"foo\"', values: []}\n```\n\n## $in$\n```\npg(SQL`SELECT * FROM foo WHERE id $in${[1,2,3]}`)\n  {text: `SELECT * FROM foo WHERE id IN($1,$2,$3)', values: [1,2,3]}\n```\n\nNote that transformers internaly use `?:` as parameter placeholder, per jsonb compliance.\n\n\n# Static API\n\n## SQL.insert\n```\npq(SQL.insert('foo', {joe: 22, bar: 'ok'}))\n  {text: 'INSERT INTO foo (\"joe\",\"bar\") VALUES ($1,$2), values: [22, 'ok']}\n```\n\n## SQL.insert_bulk\n```\npq(SQL.insert_bulk(\"foo\", [\"age\", \"name\"], [[22, \"ok\"], [45, \"ng\"]]))\n  {text: 'INSERT INTO \"foo\" (\"age\",\"name\") VALUES ($1,$2),($3,$4)', values: [ 22, 'ok', 45, 'ng' ]}\n```\n\n## SQL.update\n```\npq(SQL.update(\"foo\", { joe: 22, bar: \"ok\" }, { name: \"John doe\" }))\n  {text: 'UPDATE \"foo\" SET \"joe\"=$1,\"bar\"=$2  WHERE \"name\"=$3', values: [22, \"ok\", \"John doe\"]}\n```\n\n## SQL.select\n```\npq(SQL.select(\"foo\", { name: \"John doe\" }, [\"name\", \"age\"]))\n  {text: 'SELECT name,age FROM \"foo\"  WHERE \"name\"=$1 ', values: [ 'John doe' ]}\n```\n\n\n## SQL.search_blob (search_field, expression)\nCompute a smart query expression.\n\n\n\n\n# TODO\n* Get rich or die tryin'\n\n# Shoutbox, keywords, SEO love\npg, sql, sql-string, sql-builder, ES6 template string, prepared statement, escape, \"Let's have a beer \u0026 talk in Paris\"\n\n# Credits\n* [131](https://github.com/131)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F131%2Fsql-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F131%2Fsql-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F131%2Fsql-template/lists"}