{"id":18370854,"url":"https://github.com/ugate/sqler","last_synced_at":"2026-02-12T04:09:43.925Z","repository":{"id":36552504,"uuid":"160833547","full_name":"ugate/sqler","owner":"ugate","description":"🔑Turn your SQL files into executable functions for use in Node.js","archived":false,"fork":false,"pushed_at":"2023-03-04T05:19:51.000Z","size":1512,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T14:07:33.520Z","etag":null,"topics":["database","nodejs","sql","sql-files"],"latest_commit_sha":null,"homepage":"https://ugate.github.io/sqler","language":"JavaScript","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/ugate.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":"2018-12-07T14:24:11.000Z","updated_at":"2021-10-21T14:17:00.000Z","dependencies_parsed_at":"2024-06-21T15:34:08.653Z","dependency_job_id":"3e2e0b3e-7ac2-4a6d-9ba9-573fd71a8887","html_url":"https://github.com/ugate/sqler","commit_stats":{"total_commits":205,"total_committers":3,"mean_commits":68.33333333333333,"dds":"0.30731707317073176","last_synced_commit":"9bd910d2eb964204ca301af01ced775fadc7a507"},"previous_names":[],"tags_count":60,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ugate%2Fsqler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ugate%2Fsqler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ugate%2Fsqler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ugate%2Fsqler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ugate","download_url":"https://codeload.github.com/ugate/sqler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247539070,"owners_count":20955234,"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":["database","nodejs","sql","sql-files"],"created_at":"2024-11-05T23:40:33.398Z","updated_at":"2026-02-12T04:09:38.889Z","avatar_url":"https://github.com/ugate.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cb class=\"jsdocp-remove-me\"\u003e\n\n# ![](https://raw.githubusercontent.com/ugate/sqler/master/jsdocp/static/favicon-32x32.png) `sqler`\n\n[![npm version](https://badgen.net/npm/v/sqler?color=orange\u0026icon=npm)](https://www.npmjs.com/package/sqler)\n[![Build Status](https://badgen.net/travis/ugate/sqler?icon=travis)](https://travis-ci.com/ugate/sqler)\n[![Dependency Status](https://badgen.net/david/dep/ugate/sqler)](https://david-dm.org/ugate/sqler)\n[![Dev Dependency Status](https://badgen.net/david/dev/ugate/sqler)](https://david-dm.org/ugate/sqler?type=dev)\n\n\u003c/b\u003e\n\n`npm install sqler`\n\nSkip the ORM and simplify your SQL execution plans using plain 💯% SQL systax.\u003cbr/\u003e\n`sqler` is a Node.js manager for [RDBMS](https://en.wikipedia.org/wiki/Relational_database) systems that autogenerates/manages SQL execution functions from underlying SQL statement files. Features include:\n\n- [Autogeneration of object paths and prepared statement functions](https://ugate.github.io/sqler/tutorial-1-manual.html) that coincide with SQL file paths\n- Debugging options that allow for near real time updates to [SQL files](https://ugate.github.io/sqler/tutorial-1-manual.html#sqlf) without restarting an application\n- [Expanded SQL substitutions](https://ugate.github.io/sqler/tutorial-1-manual.html#es), [fragment substitutions](https://ugate.github.io/sqler/tutorial-1-manual.html#fs), [dialect specific substitutions](https://ugate.github.io/sqler/tutorial-1-manual.html#ds) and [version specific substitutions](https://ugate.github.io/sqler/tutorial-1-manual.html#vs)\n- [Simplified transaction management](https://ugate.github.io/sqler/tutorial-1-manual.html#tx)\n- [Simplified prepared statement management](https://ugate.github.io/sqler/tutorial-1-manual.html#ps)\n- [Fast read and write streaming support for __large reads/writes__](https://ugate.github.io/sqler/tutorial-1-manual.html#streams)\n- Using SQL vs ORM/API solutions minimizes overhead and maximizes optimal utilization of SQL syntax and DBA interaction and reduces over-fetching that is commonly assocaited with ORM\n- Unlike strict ORM/API based solutions, models are generated on the fly- lending itself to a more function centric design\n\nFor more details check out the tutorials and API docs!\n\n- [Tutorials](https://ugate.github.io/sqler/tutorial-1-manual.html)\n- [API Docs](https://ugate.github.io/sqler/Manager.html)\n\n#### Usage \u003cins id=\"usage\"\u003e\u003c/ins\u003e:\nIn order to use `sqler` a simple implementation of [Dialect](https://ugate.github.io/sqler/Dialect.html) should be supplied. There are a few that have already been written for a few enteprise level applications that make use of `sqler`\u003cins id=\"dialects\"\u003e\u003c/ins\u003e:\n\n- [SQL Server - `sqler-mssql`](https://ugate.github.io/sqler-mssql)\n- [Oracle - `sqler-oracle`](https://ugate.github.io/sqler-oracle)\n- [MariaDB and/or MySQL - `sqler-mdb`](https://ugate.github.io/sqler-mdb)\n- [PostgreSQL - `sqler-postgres`](https://ugate.github.io/sqler-postgres)\n- [ODBC - `sqler-odbc`](https://ugate.github.io/sqler-odbc)\n\nExample Read\u003cins id=\"exampleread\"\u003e\u003c/ins\u003e:\n```sql\n-- db/finance/read.ap.companies.sql\nSELECT CO.COMPANY AS \"company\", CO.R_NAME AS \"name\", CO.PAY_GROUP AS \"payGroup\", CO.TAX_ACCOUNT AS \"taxAccount\", CO.TAX_ACCT_UNIT AS \"taxAcctUnit\",\nCO.TAX_SUB_ACCT AS \"taxSubAcct\"\nFROM APCOMPANY CO\nWHERE CO.INVOICE_AUDIT = :invoiceAudit\nORDER BY CO.COMPANY ASC\n```\n\n```js\n// replace xxxx with one of the prexisiting vendor implementations\n// or roll your own Dialect\nconst dialect = 'xxxx', dialectModule = `sqler-${dialect}`;\nconst { Manager } = require('sqler');\nconst conf = {\n  \"univ\": {\n    \"db\": {\n      \"myId\": {\n        \"host\": \"myhost.example.com\",\n        \"username\": \"myusername\",\n        \"password\": \"mypassword\"\n      }\n    }\n  },\n  \"db\": {\n    \"dialects\": {\n      [dialect]: dialectModule\n    },\n    \"connections\": [\n      {\n        \"id\": \"myId\",\n        \"name\": \"fin\",\n        \"dir\": \"db/finance\",\n        \"service\": \"MYSRV\",\n        \"dialect\": dialect\n      }\n    ]\n  }\n};\nconst mgr = new Manager(conf);\n// initialize connections and set SQL functions\nawait mgr.init();\n\nconsole.log('Manager is ready for use');\n\n// execute the SQL statement and capture the results\nconst rslts = await mgr.db.fin.read.ap.companies({ binds: { invoiceAudit: 'Y' } });\n\n// after we're done using the manager we should close it\nprocess.on('SIGINT', async function sigintDB() {\n  await mgr.close();\n  console.log('Manager has been closed');\n});\n```\n\nExample Write (with implicit transaction)\u003cins id=\"examplewrite1\"\u003e\u003c/ins\u003e:\n```sql\n-- db/finance/create.ap.companies.sql\nINSERT INTO APCOMPANY (COMPANY, R_NAME, PAY_GROUP, TAX_ACCOUNT, TAX_ACCT_UNIT)\nVALUES (:company, :name, :payGroup, :taxAccount, :taxAcctUnit);\n```\n\n```js\n// using the same setup as the read example...\n\n// execute within the an implicit transaction scope\n// (i.e. autoCommit === true w/o transaction)\nconst rslts = await mgr.db.fin.create.ap.company({\n  autoCommit: true, // \u003c--- could omit since true is default\n  binds: {\n    company: 1,\n    name: 'Company 1',\n    payGroup: 'MYCO1',\n    taxAccount: 1234,\n    taxAcctUnit: 10000000\n  }\n});\n```\n\nExample Write (with explicit transaction)\u003cins id=\"examplewrite2\"\u003e\u003c/ins\u003e:\n```sql\n-- db/finance/create.ap.companies.sql\nINSERT INTO APCOMPANY (COMPANY, R_NAME, PAY_GROUP, TAX_ACCOUNT, TAX_ACCT_UNIT)\nVALUES (:company, :name, :payGroup, :taxAccount, :taxAcctUnit);\n```\n\n```js\n// using the same setup as the read example...\n\n// autCommit = false will cause a transaction to be started\nconst coOpts = {\n  autoCommit: false,\n  binds: {\n    company: 1,\n    name: 'Company 1',\n    payGroup: 'MYCO1',\n    taxAccount: 1234,\n    taxAcctUnit: 10000000\n  }\n};\n// autCommit = false will cause a transaction to be continued\nconst acctOpts = {\n  autoCommit: false,\n  binds: {\n    company: 2,\n    name: 'Company 2',\n    payGroup: 'MYCO2',\n    taxAccount: 5678,\n    taxAcctUnit: 20000000\n  }\n};\n\nlet tx;\ntry {\n  // start a transaction\n  tx = await mgr.db.fin.beginTransaction();\n\n  // set the transaction ID on the execution options\n  // so the company/account SQL execution is invoked\n  // within the same transaction scope\n  coOpts.transactionId = tx.id;\n  acctOpts.transactionId = tx.id;\n\n  // execute within the a transaction scope\n  // (i.e. autoCommit === false and transaction = tx)\n  const exc1 = await mgr.db.fin.create.ap.company(coOpts);\n\n  // execute within the same transaction scope\n  // (i.e. autoCommit === false and transaction = tx)\n  const exc2 = await mgr.db.fin.create.ap.account(acctOpts);\n\n  // use the transaction to commit the changes\n  await tx.commit();\n} catch (err) {\n  if (tx) {\n    // use the transaction to rollback the changes\n    await tx.rollback();\n  }\n  throw err;\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fugate%2Fsqler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fugate%2Fsqler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fugate%2Fsqler/lists"}