{"_id":"@allnulled/sql-utils","_rev":"2-819047a01430744ec84e1494aae82e45","name":"@allnulled/sql-utils","dist-tags":{"latest":"0.0.2"},"versions":{"0.0.1":{"name":"@allnulled/sql-utils","version":"0.0.1","description":"Various SQL utilities for Node.js","main":"index.js","scripts":{"dev":"nodemon -w ./src -w './test/*.test.js' --ext '.js,.ejs' -x 'npm run test'","build":"npm run docs && npm shrinkwrap","upload":"npm run build && npm run test && git add . && git commit && git push","docs":"javadoc -i index.js -o docs/README.api.md -f markdown && concat docs/README.ini.md docs/README.api.md docs/README.end.md -o README.md","test":"mocha --sort --bail test/*.test.js","cover":"nyc --reporter=html mocha --sort --bail test/**/*.test.js"},"keywords":["sql","utilities"],"author":{"name":"allnulled"},"license":"WTFPL","dependencies":{"sqlstring":"^2.3.1"},"devDependencies":{"chai":"^4.2.0","concat":"^1.0.3","javadoc":"^2.0.0","mocha":"^7.1.1","nodemon":"^2.0.2","nyc":"^15.0.1"},"directories":{"test":"test"},"repository":{"type":"git","url":"git+https://github.com/allnulled/sql-utils.git"},"bugs":{"url":"https://github.com/allnulled/sql-utils/issues"},"homepage":"https://github.com/allnulled/sql-utils#readme","gitHead":"85b72d73f953465a27e9b66e00dbd9f3336370c1","_id":"@allnulled/sql-utils@0.0.1","_nodeVersion":"12.16.1","_npmVersion":"6.13.7","dist":{"integrity":"sha512-65F/yDo/UC/+LP5WK0Xg5WzY8l6GyFj/yPA5pRWEf08RJlbN30+WB4DzwmjES8pc0iwuTowO+R6VJhZiV1X9mg==","shasum":"d564d753a0ac1419dea5c07277d8031facf1521e","tarball":"https://registry.npmjs.org/@allnulled/sql-utils/-/sql-utils-0.0.1.tgz","fileCount":8,"unpackedSize":202288,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJejeSQCRA9TVsSAnZWagAAsG4P/iKRB4beFpLOogJb2Svs\nAnln6PzuBdzU8JvMaVNUlDxplk8PwSmrwataLAstI5NOfJQH8tUv9NQf5n4V\nPQmQeJSXTABppOD40NKulx6z04gYgF9GAB1mOyhTdOKBOXuRxcrOsgITQNB4\npMJaohagWiuiJSxoTOaiR4dD2I9Mij1EZwdsHbnDxfon0HSehO9UZoMDUCHn\n0tvj5+6AvxgifBmAAAPGlLi+X7CTmASWNGtYDJOh2DvLYVVmWw9Y4VcWFtFv\nrY0i+c3SJL5D6wSvgNDs9stcko5oVsYufqxJqsu/Wi7cpIN/uXf0EDGfOcJX\nmSqCxGpSrbepATZx0QPZiV/PxsWefRst8Ujx6L8cLPP3fQjpeQ/+xS6nsoMr\naC5dsY9T51XD+UW61KYYHQSzQ8ycMEYSGMORk4ZbfUjgxcWZEYMKDAZnW1Ag\nboWHAiXuTqSKI2kiJMzmkpUoRbVwnItp4u+UJTb0p5RyzOJQ6veAvjoyG2TZ\ngGWP/vNXRcdafaUc5KqOntRWuvKS7AAjOGXfb9m8/hSpvT9TcAXhesM7POtA\niCkDmC4SAvK4woa6jo5hlwCU0ROqG2VTiXDDHC+0f6Od9Q3qdW2+riM0wdI5\nt0WjZiIoPEP/2JXlRFStQjnnh6nAcuyVl95vzUyqcajWRExpv6d5OeK1h3jW\nt/0j\r\n=yTtq\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIERjPkjarJoJSBN8x8Bt+o8sJgTmlvE9vsW9JpDrrRETAiBEXUD1MO98BiVynsKU4bJxPCQ9f0j2tic6MxAuAsEfBQ=="}]},"maintainers":[{"name":"allnulled","email":"todosanulados@gmail.com"}],"_npmUser":{"name":"allnulled","email":"todosanulados@gmail.com"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sql-utils_0.0.1_1586357391957_0.004808555573960538"},"_hasShrinkwrap":true},"0.0.2":{"name":"@allnulled/sql-utils","version":"0.0.2","description":"Various SQL utilities for Node.js","main":"index.js","scripts":{"dev":"nodemon -w ./src -w './test/*.test.js' --ext '.js,.ejs' -x 'npm run test'","build":"npm run docs && npm shrinkwrap","upload":"npm run build && npm run test && git add . && git commit && git push","docs":"javadoc -i index.js -o docs/README.api.md -f markdown && concat docs/README.ini.md docs/README.api.md docs/README.end.md -o README.md","test":"mocha --sort --bail test/*.test.js","cover":"nyc --reporter=html mocha --sort --bail test/**/*.test.js"},"keywords":["sql","utilities"],"author":{"name":"allnulled"},"license":"WTFPL","dependencies":{"sqlstring":"^2.3.1"},"devDependencies":{"chai":"^4.2.0","concat":"^1.0.3","javadoc":"^2.0.0","mocha":"^7.1.1","nodemon":"^2.0.2","nyc":"^15.0.1"},"directories":{"test":"test"},"repository":{"type":"git","url":"git+https://github.com/allnulled/sql-utils.git"},"bugs":{"url":"https://github.com/allnulled/sql-utils/issues"},"homepage":"https://github.com/allnulled/sql-utils#readme","gitHead":"29e4662a910a3489edaa0f2f47eb89b7dc45d0de","_id":"@allnulled/sql-utils@0.0.2","_nodeVersion":"12.16.1","_npmVersion":"6.13.7","dist":{"integrity":"sha512-1RIbQJtvPwX9k7Pnd4jIuZYRukVdaTeyB0Z7OVVof9qOXjenWtcBnLpzObyiaFfR72/ZdcJmqhZ6mYWXHBa/TA==","shasum":"20099369d5101b01e2c8f367ebad218e02189858","tarball":"https://registry.npmjs.org/@allnulled/sql-utils/-/sql-utils-0.0.2.tgz","fileCount":8,"unpackedSize":203895,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJejwV8CRA9TVsSAnZWagAAIwoQAIo1ubbyOvRrZkKz9HXP\ncd29QSNSCRuz0kaAhmtVLABB1h5SNy9mGEesAtxxEgtinPXC1rgGgoKN1FwH\nMwyj7KHhGVJ/9frQ6Nt/6ZPGJ+0q/0O/KTRj5pdRwybJjfc5ryKWbs8jIVvG\n0+WGv8pf0PBypHMsLgf8D61verFCouLCBRH29YQKLqq9Bny2zLeUsoFoVh9n\n4rBkPNKuqfj1/96n3t3oWrV7/HN/wSs2rkc9l1Sx+befKP26zoXBrfVjq9JA\nXZUu1fjjIW6pOcl9NUIDbXfBA2WIv7Bs420Gv9lUTfxBvMG7aMV1fXB1BHRE\nTSYhxoBTizQAUoJGF1fmRNwjncVmkzX7Udt32KG5yUWSMKSWHCPQwhz89xnl\nfchHDKdiT+JZNaBF9ZdnRi89vHDVg0pi/4jnByEPvhuXMFwn8eQvgVlQjzKX\nxQK4oW0fcne3VjywmgazNJJyH/2hBxWr0lkB4/Dwo+mTt6D+c2Y2q012ZEOw\nCpDECdxBwNHMf70C2sufBpN6D4yrpZAcqqfBF3gWAOGawu9LT4b61bPfuwHd\nsIo5Yaz1Y+B8/IZNwJ2FourZWOKbCT8kMkCUVNOPL2WhhTNZ9ZK0ZGiiLR/f\nGfCjCy6PZ0j2w5YgNjJHoG9+GaZp5RFd2MlTSEJo0diBuSUl/rfBBZwT3Q/1\nttEh\r\n=79Pu\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCIGSI1zDWxAxg5WFevTje9eTJCfq3Ju5GTyc1L89d72QIhAKCbGOyQGOtoxF+0RN25jkduWh6ULC7blbrFv+tWOfvW"}]},"maintainers":[{"name":"allnulled","email":"todosanulados@gmail.com"}],"_npmUser":{"name":"allnulled","email":"todosanulados@gmail.com"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sql-utils_0.0.2_1586431355650_0.8697813976299711"},"_hasShrinkwrap":true}},"time":{"created":"2020-04-08T14:49:51.714Z","0.0.1":"2020-04-08T14:49:52.212Z","modified":"2022-04-04T13:33:32.276Z","0.0.2":"2020-04-09T11:22:35.960Z"},"maintainers":[{"name":"allnulled","email":"todosanulados@gmail.com"}],"description":"Various SQL utilities for Node.js","homepage":"https://github.com/allnulled/sql-utils#readme","keywords":["sql","utilities"],"repository":{"type":"git","url":"git+https://github.com/allnulled/sql-utils.git"},"author":{"name":"allnulled"},"bugs":{"url":"https://github.com/allnulled/sql-utils/issues"},"license":"WTFPL","readme":"# sql-utils\n\nVarious SQL utilities for Node.js\n\n## Installation\n\n`$ npm i -s @allnulled/sql-utils`\n\n## Usage\n\n```js\nconst SQLUtils = require(\"sql-utils\");\nconst whereSQL = SQLUtils.whereToSQL({\n\tname: \"somename\",\n\tpassword: \"somepassword\"\n});\nconst query = `SELECT * FROM user WHERE ${whereSQL}`;\n```\n\n### `whereToSQL` function\n\n`SQLUtils.whereToSQL(...)` allows to obtain SQL `WHERE` expressions from:\n\n   - `Object`: where each property is a column, and each value, a `SQL` (escaped) value.\n   - `Array`: where each item represents:\n       - *2 values*: SQL column and value, bound by `=`\n       - *3 values*: SQL column, SQL logic operators, and value\n   - `String`: inline `SQL` injections are allowed by the framework, to fully customize what is going on `WHERE` SQL expressions.\n\nThis function also allows you to use `in` and `not in` operators with `Arrays` of values (that will be safely escaped).\n\n## API\n\n------\n\n\n\n#### `const SQLUtils = require(\"sql-utils\")`\n\n\n\n**Type**:  Class\n\n\n**Description**:  Class that contains the whole API of the package.\n\n\n\n\n----\n\n#### `SQLUtils.die(...args:any)`\n\n\n\n**Type**:  Static method\n\n\n**Description**:  Prints by console whatever you pass, and kills the process.\n\n\n\n\n----\n\n#### `SQLUtils.getPropertiesSQL(property:String|Any, table:String|Boolean)`\n\n\n\n**Type**:  Static method\n\n\n**Parameter**: \n\n\n  - `property:String|Any`. SQL column name. When it is not a string, it is returned directly.\n\n\n  - `table:String|Boolean`. Optional. SQL table name. When it is a falsy value, it is omitted.\n\n\n**Return**:  `sql:String`. SQL code to represent this column.\n\n\n**Description**:  Splits the property by `\".\"`, escaped as SQL ids every part, and prefixes with the name of the table, if any.\n\n\n\n\n----\n\n#### `SQLUtils.generateToken(length:Integer, charset:Array)`\n\n\n\n**Type**:  Static method\n\n\n**Parameter**: \n\n\n  - `length:Integer`. Required. Number of characters for the token.\n\n\n  - `charset:Array<String>`. Optional. Valid characters for the token.\n\n\n**Return**:  `token:String`. Generated token.\n\n\n**Description**:  Returns a token from the pool of characters provided.\n\n\n\n\n----\n\n#### `SQLUtils.rowsToObject(rows:Array<Object>, table:String, columnId:String)`\n\n\n\n**Type**:  Static method\n\n\n**Parameter**: \n\n\n  - `rows:Array<Object>`. Required. Data in arrays of objects, where each object property is read like: `$table.$column`.\n\n\n  - `table:String`. Required. Table to extract the data from.\n\n\n  - `columnId:String`. Optional. Column to index all data rows by. By default: `\"id\"`.\n\n\n**Return**:  `formattedData:Array<Object>`. Data resulted from the operation.\n\n\n**Description**:  Returns an array of objects with the properties like `${table}.*` grouped by the rows that have the same `columnId`.\n\n\n\n\n----\n\n#### `SQLUtils.whereToSQL(where:Array|Object, table:String, andPrefix:Boolean, defaultValue:String)`\n\n\n\n**Type**:  Static method\n\n\n**Parameter**: \n\n\n  - `where:Object|Array`. Required. As object, it must contain the properties (columns) and the expected values. As array, it must contain arrays of 2 or 3 items: subject and object, or subject, operator and object respectively.\n\n\n  - `table:String`. Optional. Table used to prefix the properties in this `where` statement part. By default: `false`.\n\n\n  - `andPrefix:Boolean`. Optional. If `true`, a ` AND ` will prefix the generated code. By default: `false`.\n\n\n  - `defaultValue:String`. Required. Column to index all data rows by. By default: `\"1 = 1\"`.\n\n\n**Return**:  `sql:String`. SQL code that represents this partial `WHERE` statement.\n\n\n**Description**:  Returns SQL code to represent a specific `WHERE` statement part.\n\n\n\n\n\n------\n\n## License\n\nThis project is under [WTFPL](https://es.wikipedia.org/wiki/WTFPL), which means basically: *do What The Fuck you want with it*.\n\n## Contact\n\nPlease, address issues and suggestions [here](https://github.com/allnulled/sql-utils/issues). Thank you.\n\n","readmeFilename":"README.md"}