{"id":29670078,"url":"https://github.com/gitguanqi/xqsql","last_synced_at":"2026-02-16T17:33:41.409Z","repository":{"id":57402202,"uuid":"381309331","full_name":"gitguanqi/xqsql","owner":"gitguanqi","description":"This is a method warehouse for automatically generating various sql statements. ","archived":false,"fork":false,"pushed_at":"2025-04-05T11:00:44.000Z","size":38,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-03T19:48:37.498Z","etag":null,"topics":["npm-package","sql","xqsql"],"latest_commit_sha":null,"homepage":"","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/gitguanqi.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}},"created_at":"2021-06-29T09:26:35.000Z","updated_at":"2021-12-09T09:17:56.000Z","dependencies_parsed_at":"2022-09-17T06:42:53.916Z","dependency_job_id":null,"html_url":"https://github.com/gitguanqi/xqsql","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gitguanqi/xqsql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gitguanqi%2Fxqsql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gitguanqi%2Fxqsql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gitguanqi%2Fxqsql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gitguanqi%2Fxqsql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gitguanqi","download_url":"https://codeload.github.com/gitguanqi/xqsql/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gitguanqi%2Fxqsql/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29513989,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-16T09:05:14.864Z","status":"ssl_error","status_checked_at":"2026-02-16T08:55:59.364Z","response_time":115,"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":["npm-package","sql","xqsql"],"created_at":"2025-07-22T19:07:49.408Z","updated_at":"2026-02-16T17:33:41.379Z","avatar_url":"https://github.com/gitguanqi.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# xqsql\n\nThis is a method warehouse for automatically generating various sql statements.\n\n[View Chinese documents](./zh.md)\n\n## Install\n\n**Browser**:\n\nimport cdn\n\n```html\n\u003c!-- Browser --\u003e\n\u003cscript src=\"https://xqgj.cc/xqcdn/libs/xqsql/xqsql.min.js\"\u003e\u003c/script\u003e\n\u003c!-- es module --\u003e\n\u003cscript type=\"module\"\u003e\n    import xqsql from '../lib/xqsql-esm.min.js';\n\u003c/script\u003e\n```\n\n**Node**:\n\n```sh\nnpm install xqsql\n```\n\n```js\nconst xqsql = require('xqsql');\n```\n\n## Usage\n\n### CURD operation\n\n+ Create record\n\nThis method is suitable for creating single or multiple records\n\nParameters of req.body\n\n```js\nconst addParams = [\n    {\n        name:'Apple',\n        number: 10,\n        price: 8.8\n    },\n    {\n        name:'Blueberry',\n        number: 20,\n        price: 9.9\n    }\n]\n```\n\nField array\n\n```js\nconst addFields = [\n    {\n        name:'Product name',\n        value:'name',\n        isMust: true\n    },\n    {\n        name:'Product quantity',\n        value:'number',\n        isMust: true\n    },\n    {\n        name:'Commodity price',\n        value:'price',\n        isMust: true\n    }\n]\n```\n\nView Results\n\n```js\nconst addSql = xqsql.add('goods', addParams, addFields);\nconsole.log('The added statement is:', addSql);\n\n// The added statement is: INSERT INTO `goods` (id, name,number,price) VALUES (0,\"apple\",10,8),(0,\"blueberry\",20,9)\n```\n\n+ Get information\n\n1. Default query\n\nParameters of req.query\n\n```js\nlet getDefaultOneParams = [1];\nlet getDefaultMoreParams = [1,2,3];\n```\n\nView results (single in default mode)\n\n```js\nconst getDefaultOneSql = xqsql.get('goods', {\n    type:'one',\n    key:'id',\n    ids: getDefaultOneParams,\n},'default','id,name,number,price');\n\nconsole.log('Query default mode (single):', getDefaultOneSql);\n\n// Query the default mode (single): SELECT id,name,number,price FROM `goods` WHERE id = '1'\n```\n\nView results (single in default mode)\n\n```js\nconst getDefaultMoreSql = xqsql.get('goods', {\n    type:'more',\n    key:'id',\n    ids: getDefaultMoreParams,\n},'default','id,name,number,price');\n\nconsole.log('Query default mode (multiple):', getDefaultMoreSql);\n\n// Query the default mode (multiple): SELECT id,name,number,price FROM `goods` WHERE id in (1,2,3)\n```\n\nView results (all in default mode)\n\n```js\nconst getDefaultSql = xqsql.get('goods', {\n    type:'all',\n},'default','id,name,number,price');\n\nconsole.log('Query default mode (all):', getDefaultSql);\n// Query the default mode (all): SELECT id,name,number,price FROM `goods`\n```\n\n2.More conditional modes\n\n```js\nconst getMoretSql = xqsql.get('goods', {\n    id: 1,\n    name: \"Banana\",\n},'more','id,name,number,price');\n\nconsole.log('More condition mode:', getMoretSql);\n// More conditional patterns: SELECT id,name,number,price FROM `goods` WHERE id = '1' AND name LIKE'%banana%'\n```\n\n3.Paging query\n\n```js\nlet getListParams = {\n    name: \"Banana\",\n    page: 1,\n    size: 10,\n};\nlet currentPageSize = (getListParams.page-1) * getListParams.size;\nlet getListFields = [\n    {\n        name:'Product name',\n        value:'name'\n    },\n    {\n        name:'Product quantity',\n        value:'number'\n    },\n    {\n        name:'Commodity price',\n        value:'price'\n    }\n]\n\nlet getList = {};\n\nfor (const item of getListFields) {\n    let k = item.value;\n    if (getListParams[k]) {\n        getList[k] = getListParams[k];\n    }\n    if (getListParams[k] === 0) {\n        getList[k] = 0;\n    }\n}\n\nlet getListSql = xqsql.get('goods', {\n    list: getList,\n    sorts: {\n        name: getListParams.sort ||'create_time',\n        val: getListParams.sortRule ||'DESC'\n    },\n    limits: {\n        page: currentPageSize,\n        size: getListParams.size || 10\n    }\n},'page');\n\nconsole.log('The sentence after the paging list query is:', getListSql);\n/*\nThe sentence after the paging list query is: {\n  sql: \"SELECT * FROM `goods` WHERE name LIKE'%banana%' ORDER by create_time DESC LIMIT 0,10\",\n  count: \"SELECT COUNT(id) FROM `goods` WHERE name LIKE'%banana%'\"\n}\n*/\n```\n\n+ Update\n\nPublic section\n\n```js\nconst upParams = {\n    key:'id',\n    ids: null,\n    list: {\n        number: 10,\n        price: 9.9\n    }\n}\n\nconst upFields = [\n    {\n        name:'Product quantity',\n        value:'number',\n        isMust: true\n    },\n    {\n        name:'Commodity price',\n        value:'price',\n        isMust: true\n    }\n]\n```\n\n1. Single update\n\n```js\nupParams.ids = [1];\nlet upOneSql = xqsql.up('goods', upParams, upFields);\nconsole.log('Update (single) statement:', upOneSql);\n// Update (single) statement: UPDATE `goods` SET number = 10,price = 9 WHERE id = '1'\n```\n\n2.Multiple updates\n\n```js\nupParams.ids = [1,2,3];\nlet upMoreSql = xqsql.up('goods', upParams, upFields,'more');\nconsole.log('Update (multiple) statements:', upMoreSql);\n// Update (multiple) statements: UPDATE `goods` SET number = 10,price = 9 WHERE id in (1,2,3)\n```\n\n3.Update all\n\n```js\nlet upSql = xqsql.up('goods', upParams, upFields,'all');\nconsole.log('Update (all) statement:', upSql);\n// Update (all) statement: UPDATE `goods` SET number = 10, price = 9\n```\n\n+ Delete\n\nParameter req.query\n\n1. Delete a single\n\n```js\nlet delOneParams = {\n    key:'id',\n    ids: [1]\n};\nlet delOneSql = xqsql.del('goods', delOneParams);\nconsole.log('Delete (single) statement:', delOneSql);\n// Delete (single) statement: DELETE FROM `goods` WHERE id = '1'\n```\n\n2.Delete multiple\n\n```js\nlet delMoreParams = {\n    key:'id',\n    ids: [1,2,3]\n};\nlet delMoreSql = xqsql.del('goods', delMoreParams,'more');\nconsole.log('Delete (multiple) statements:', delMoreSql);\n// Delete (multiple) statements: DELETE FROM `goods` WHERE id in (1,2,3)\n```\n\n3.Delete all\n\n```js\nlet delSql = xqsql.del('goods','','all');\nconsole.log('Delete (all) statements:', delSql);\n// Delete (all) statements: DELETE FROM `goods`\n```\n\n## View xqsql\n\nRun this script to view the demonstration case: `npm run test:node`, `npm run test:browser`.\n\n## ask questions\n\n[submit your question](https://github.com/gitguanqi/xqsql/issues/new)\n\n## Author\n\n[@gitguanqi](https://github.com/gitguanqi)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgitguanqi%2Fxqsql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgitguanqi%2Fxqsql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgitguanqi%2Fxqsql/lists"}