{"id":15391387,"url":"https://github.com/sultan99/sql-fns","last_synced_at":"2026-01-20T02:47:21.826Z","repository":{"id":44019794,"uuid":"231209980","full_name":"sultan99/sql-fns","owner":"sultan99","description":"🧱 Yet another SQL builder for Node.js.","archived":false,"fork":false,"pushed_at":"2024-05-08T03:11:16.000Z","size":911,"stargazers_count":1,"open_issues_count":13,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-13T18:57:03.809Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sultan99.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":"2020-01-01T11:51:14.000Z","updated_at":"2024-05-08T03:11:20.000Z","dependencies_parsed_at":"2024-10-01T15:21:04.867Z","dependency_job_id":null,"html_url":"https://github.com/sultan99/sql-fns","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sultan99/sql-fns","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sultan99%2Fsql-fns","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sultan99%2Fsql-fns/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sultan99%2Fsql-fns/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sultan99%2Fsql-fns/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sultan99","download_url":"https://codeload.github.com/sultan99/sql-fns/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sultan99%2Fsql-fns/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28594958,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T02:08:49.799Z","status":"ssl_error","status_checked_at":"2026-01-20T02:08:44.148Z","response_time":117,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2024-10-01T15:10:55.688Z","updated_at":"2026-01-20T02:47:21.811Z","avatar_url":"https://github.com/sultan99.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sql-fns\nYet another SQL builder for Node.js.\n\nAt this moment just blue-prints of api. Implementation would be later, the final aim is to make \"ORM\" base on this SQL builder with the same FP approach.\n\nFeatures:\n - less verbose \u0026 human readable syntax\n - curried \u0026 composable functions\n - compatible with fp libraries like [ramda](https://github.com/ramda/ramda), [lodash/fp](https://github.com/lodash/lodash/wiki/FP-Guide)\n\n### Templates\nDead simple just use plain text to build SQL:\n\n```js\nimport {sql} from 'sql-fns'\n\nconst findUserByName = name =\u003e sql`\n  SELECT * FROM \"user\"\n   WHERE name = '${name}'\n   LIMIT 1\n`\n\nconst bob = await findUserByName(`Bob`)\n\n// SELECT * FROM \"user\" WHERE name = 'Bob' LIMIT 1\n```\n\n### Query function\nPlain text is ok in some cases, but much better to use functions to build more reusable queries.\n```js\nimport {query, select, from, limit, gt} from 'sql-fns'\n\nconst findUser = query(\n  select(`*`),\n  from(`user`),\n  limit(1)\n)\n\nconst bob = await findUser({name: `Bob`})\nconst pal = await findUser({isCrazy: `yes`, age: gt(21)})\n\n// SELECT * FROM \"user\" WHERE name = 'Bob' LIMIT 1\n// SELECT * FROM \"user\" WHERE is_crazy = 'yes' AND age \u003e 21 LIMIT 1\n\n/* middleware applied to convert camelCase to snake_case */\n```\n\n### Recomposing existing query\nHere we reuse the existing `findUser` query by adding new conditions and rewriting limit to a new value.\n```js\nimport {where, like} from 'sql-fns'\n\nconst findBrides = findUser(user =\u003e [\n  where(\n    user.age.between(21, 28),\n    user.gender.equals(`female`),\n  ),\n  limit(100),\n])\n\nconst brides = await findBrides({bio: like(`%sexy%`)})\n\n// SELECT * FROM \"user\"\n//  WHERE age BETWEEN 21 AND 28\n//    AND gender = 'female'\n//    AND bio like '%sexy%'\n//  LIMIT 100\n```\n\n### Join and rule\nAlias and table join\n\n```js\nimport {table, join} from 'sql-fns'\n\nconst country = table(`country`, `c`)\nconst {code: countryCode} = country\n\nconst findTeenagers = findUser(user =\u003e [\n  join(country).on(user.countryId, country.id),\n  limit(100),\n])\n\n// for where clause we can pass json or function\nconst users = await findTeenagers(({age}) =\u003e [\n  age.between(10, 19),\n  countryCode.equals(`LU`),\n])\n\n// SELECT * FROM \"user\" u\n//   JOIN \"country\" c ON u.country_id = c.id\n//  WHERE u.age BETWEEN 10 AND 19\n//    AND c.code = 'LU'\n//  LIMIT 100\n```\n\n### Mutations\nInsert one ore more records.\n```js\nimport {insert} from 'sql-fns'\n\nconst createUsers = insert(`user`)\n\nconst id = await createUsers({name: `Bob`, age: 13})\n\nconst ids = await createUsers([\n  {name: `Foo`, age: 12},\n  {name: `Bar`, age: 34},\n])\n```\n\nUpdate records\n```js\nimport {update, lt} from 'sql-fns'\n\nconst updateUsers = update(`user`)\n\nawait updateUsers(\n  set({status: `banned`}),\n  where({age: lt(21)}),\n)\n```\n\nAll mutation functions are extendable similar to queries.\n```js\nconst banUsers = updateUsers(user =\u003e\n  user.role.not(`admin`),\n)\n\nawait banUsers()\n\n// UPDATE \"user\" SET status = 'banned' WHERE age \u003c 21 AND role \u003c\u003e 'admin';\n```\n\n## To be continued ...\nYou are welcome to [follow](https://github.com/sultan99/sql-fns/stargazers) or [join](https://github.com/sultan99/sql-fns/network/members) the project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsultan99%2Fsql-fns","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsultan99%2Fsql-fns","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsultan99%2Fsql-fns/lists"}