{"id":29325373,"url":"https://github.com/nodef/extra-pg-english","last_synced_at":"2026-05-03T17:31:28.819Z","repository":{"id":52079043,"uuid":"135931378","full_name":"nodef/extra-pg-english","owner":"nodef","description":"Converts English query to Informal/Format SQL SELECT.","archived":false,"fork":false,"pushed_at":"2025-04-16T07:59:28.000Z","size":67,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-19T17:37:53.426Z","etag":null,"topics":["convert-to-formal-sql","convert-to-informal-sql","database","english","interface","language","natural","nlidb","nlp","pg","postgresql","processing"],"latest_commit_sha":null,"homepage":"https://jsr.io/@nodef/extra-pg-english","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/nodef.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,"zenodo":null}},"created_at":"2018-06-03T18:50:27.000Z","updated_at":"2025-04-16T07:59:32.000Z","dependencies_parsed_at":"2025-04-18T02:09:57.261Z","dependency_job_id":"99acfb32-1743-498b-a7e2-57d74f8fc857","html_url":"https://github.com/nodef/extra-pg-english","commit_stats":null,"previous_names":["nodef/extra-pg-english","nodef/pg-english"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nodef/extra-pg-english","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodef%2Fextra-pg-english","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodef%2Fextra-pg-english/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodef%2Fextra-pg-english/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodef%2Fextra-pg-english/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nodef","download_url":"https://codeload.github.com/nodef/extra-pg-english/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodef%2Fextra-pg-english/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32578578,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T06:36:36.687Z","status":"ssl_error","status_checked_at":"2026-05-03T06:36:09.306Z","response_time":103,"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":["convert-to-formal-sql","convert-to-informal-sql","database","english","interface","language","natural","nlidb","nlp","pg","postgresql","processing"],"created_at":"2025-07-07T18:01:09.917Z","updated_at":"2026-05-03T17:31:28.782Z","avatar_url":"https://github.com/nodef.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Converts [English query] to Informal/Format [SQL SELECT].\n\n▌\n📦 [JSR](https://jsr.io/@nodef/extra-pg-english),\n📰 [Docs](https://jsr.io/@nodef/extra-pg-english/doc).\n\n\u003cbr\u003e\n\n\n```javascript\nimport {convertToInformalSQL} from \"jsr:@nodef/extra-pg-english\";\n// convertToInformalSQL(\u003ctext\u003e, \u003cmatch fn\u003e, [this], [options])\n// -\u003e Promise (processed text)\n\n// \u003cmatch fn\u003e(\u003ctexts\u003e)\n// - texts: array of text\n// -\u003e Promise {type, value, length}\n// - type: token type (table/column/row)\n// - value: token value\n// - hint: token hint (identifies table)\n// - length: token length (from start of texts)\n\n// options: {\n//   table: undefined,       // default table: none\n//   columns: {\u003ctable\u003e: []}, // default columns per table: none\n// }\n\n\nasync function entityMatchFunction(txts: string[]) {\n  let   a   = null;\n  const txt = txts.join(' ');\n  if (txt.startsWith('ascorbic acid')) a = {type: 'column', value: 'ASCORBIC ACID', length: 2};\n  else if (txt.startsWith('food'))     a = {type: 'table',  value: 'FOOD', length: 1};\n  return a;\n}\nawait convertToInformalSQL('show food with ascorbic acid less than twenty nine mg', entityMatchFunction);\n// → SELECT \"ASCORBIC ACID\" FROM \"FOOD\" WHERE (\"ASCORBIC ACID\" \u003c 0.029)\n```\n\n```typescript\nimport {convertToFormalSQL} from \"jsr:@nodef/extra-pg-english\";\n// convertToFormalSQL(\u003cinformal sql\u003e, \u003cmap fn\u003e, [this], [options])\n// -\u003e Promise (formal sql)\n\n// \u003cinformal sql\u003e:\n// SELECT \"food name\", \"trans fat\" FROM \"food\" ORDER BY \"trans fat\" DESC\n// SELECT \"protein\", \"vitamin d\" FROM \"poultry ORDER BY \"vitamin d\" DESC\n// SELECT \"sum: essential amino acids\" AS \"amino\" FROM \"meat\" ORDER BY \"amino\"\n// ...\n\n// \u003cmap fn\u003e(\u003ctext\u003e, \u003ctype\u003e, [hint], [from]):\n// - text: field name, like \"food name\", \"trans fat\", \"food\", ...\n// - type: field type, can be \"from\",\"columns\", \"where\", \"having\", \"orderBy\", or \"groupBy\"\n// - hint: field hint, can be null, \"all\", \"sum\", or \"avg\"\n// - from: field from, will be null for type=table\n// -\u003e Promise [\u003cvalue\u003e]\n// - value: expression string\n\n// [options]:\n// - from: default table\n// - limit: default maximum limit\n// - limits: table specific maximum limts\n\n\nasync function resolveFunctionA(_text: string, type: string, _hint: string | null, _from: string) {\n  return type==='from'? ['table'] : ['column'];\n}\nawait convertToFormalSQL(`SELECT \"food name\", \"calcium\" FROM \"apples\"`, resolveFunctionA);\n// → SELECT \"column\", \"column\" FROM \"table\" WHERE TRUE AND TRUE\n\n\nasync function resolveFunctionB(_text: string, type: string, _hint: string | null, _from: string) {\n  if (type==='from') return ['compositions'];\n  return ['ca', 'ca_e'];\n}\nawait convertToFormalSQL(`SELECT \"food name\", \"calcium\" FROM \"apples\"`, resolveFunctionB);\n// → SELECT \"ca\", \"ca_e\", \"ca\", \"ca_e\" FROM \"compositions\" WHERE TRUE AND TRUE\n\n\nconst columns: Map\u003cstring, string[]\u003e = new Map([\n  ['food code', ['code']],\n  ['food name', ['name']],\n  ['calcium', ['ca', 'ca_e']],\n  ['magnesium', ['mg', 'mg_e']]\n]);\nconst tables = ['food', 'compositions'];\nasync function resolveFunctionC(text: string, type: string, _hint: string | null, _from: string) {\n  if (type==='from') return tables.includes(text)? ['compositions'] : [];\n  return columns.get(text) as string[];\n}\nawait convertToFormalSQL(`SELECT \"food name\", \"calcium\" FROM \"apples\"`, resolveFunctionC);\n// → SELECT \"name\", \"ca\", \"ca_e\" FROM \"null\" WHERE TRUE AND TRUE\n\n\nasync function resolveFunctionD(text: string, type: string, _hint: string | null, _from: string) {\n  if (type==='from') return tables.includes(text)? ['compositions'] : [`\"tsvector\" @@ '${text}'`];\n  return columns.get(text) as string[];\n}\nawait convertToFormalSQL(`SELECT \"food name\", \"calcium\" FROM \"apples\"`, resolveFunctionD);\n// → SELECT \"name\", \"ca\", \"ca_e\" FROM \"null\" WHERE TRUE AND (FALSE OR (\"tsvector\" @@ 'apples'))\n\n\nconst options = {from: 'compositions'};\nawait convertToFormalSQL(`SELECT \"food name\", \"calcium\" FROM \"apples\"`, resolveFunctionD, null, options);\n// → SELECT \"name\", \"ca\", \"ca_e\" FROM \"compositions\" WHERE TRUE AND (FALSE OR (\"tsvector\" @@ 'apples'))\n\n\n// PRIMARY USECASE\n// ---------------\nasync function resolveFunctionDB(text: string, type: string, hint: string | null, from: string) {\n  // ...\n  // \u003cdo some database lookup\u003e\n  // ...\n}\nawait convertToFormalSQL(/*  */, resolveFunctionDB, null, options);\n// → SELECT \"name\", \"ca\", \"ca_e\" FROM \"compositions\" WHERE TRUE AND (FALSE OR (\"tsvector\" @@ 'apples'))\n\n\n// NOTES\n// -----\n// 1. Map function return value can be an expression array\n// 2. For column, return multiple values to select multiple columns\n// 3. But in expressions, only first return value is considered\n// 4. Hints perform an operation on matching columns\n// 5. Use hint to decide which columns to return\n// 6. For table, returning expression will append to where\n// 7. Return expression and table name for full association\n// 8. Hint can be used in column text as \"\u003chint\u003e: \u003ccolumn text\u003e\"\n// 9. Hint \"all\": all|each|every\n// 10. Hint \"sum\": sum|gross|total|whole|aggregate\n// 11. Hint \"avg\": avg|mid|par|mean|norm|center|centre|average|midpoint\n```\n\n\u003cbr\u003e\n\u003cbr\u003e\n\n\n[![](https://raw.githubusercontent.com/qb40/designs/gh-pages/0/image/11.png)](https://wolfram77.github.io)\u003cbr\u003e\n[![ORG](https://img.shields.io/badge/org-nodef-green?logo=Org)](https://nodef.github.io)\n![](https://ga-beacon.deno.dev/G-RC63DPBH3P:SH3Eq-NoQ9mwgYeHWxu7cw/github.com/nodef/extra-pg-english)\n\n[English query]: https://www.nexthink.com/blog/natural-language-interfaces-to-databases-nlidb/\n[SQL SELECT]: https://www.postgresql.org/docs/10/static/sql-select.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodef%2Fextra-pg-english","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnodef%2Fextra-pg-english","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodef%2Fextra-pg-english/lists"}