{"_id":"node-sql-2","_rev":"3018673","name":"node-sql-2","description":"sql builder","dist-tags":{"latest":"0.80.1"},"maintainers":[{"name":"aingram-hfour","email":""},{"name":"damienpuig","email":""},{"name":"naumhfour","email":""},{"name":"spion","email":"gorgi.kosev@gmail.com"},{"name":"stdim","email":""},{"name":"whoeverest","email":""}],"time":{"modified":"2023-11-06T06:32:47.000Z","created":"2018-05-10T13:41:26.433Z","0.80.1":"2021-01-18T14:36:22.536Z","0.80.0":"2021-01-15T15:09:14.239Z","0.79.0":"2020-03-11T15:32:09.640Z","0.78.0":"2018-05-10T13:41:26.433Z"},"users":{},"author":{"name":"brianc","email":"brian.m.carlson@gmail.com"},"repository":{"type":"git","url":"git://github.com/TokyoFarmer/node-sql-2.git"},"versions":{"0.80.1":{"author":{"name":"brianc","email":"brian.m.carlson@gmail.com"},"name":"node-sql-2","description":"sql builder","version":"0.80.1","homepage":"https://github.com/TokyoFarmer/node-sql-2","license":"MIT","repository":{"type":"git","url":"git://github.com/TokyoFarmer/node-sql-2.git"},"main":"lib/","types":"lib/types.d.ts","scripts":{"test":"mocha","lint":"jshint lib test","posttest":"jshint lib test"},"engines":{"node":"*"},"dependencies":{"sliced":"0.0.x","lodash":"^4.17.5"},"devDependencies":{"jshint":"*","mocha":">6.0.0"},"mocha":{"reporter":"dot","ui":"tdd"},"gitHead":"b793c5ab32693fe4c285606c0a92a2f1b0ebe23f","bugs":{"url":"https://github.com/TokyoFarmer/node-sql-2/issues"},"_id":"node-sql-2@0.80.1","_nodeVersion":"12.14.0","_npmVersion":"6.13.4","dist":{"shasum":"d4a16820d2e653e13c078f79d3a6444f60da6b12","size":81713,"noattachment":false,"key":"/node-sql-2/-/node-sql-2-0.80.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-sql-2/download/node-sql-2-0.80.1.tgz"},"_npmUser":{"name":"mayah4","email":"mvladimirova@hfour.com"},"directories":{},"maintainers":[{"name":"aingram-hfour","email":""},{"name":"damienpuig","email":""},{"name":"naumhfour","email":""},{"name":"spion","email":"gorgi.kosev@gmail.com"},{"name":"stdim","email":""},{"name":"whoeverest","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/node-sql-2_0.80.1_1610980582396_0.7543760249027887"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2021-12-23T02:47:56.435Z","publish_time":1610980582536,"_cnpm_publish_time":1610980582536},"0.80.0":{"author":{"name":"brianc","email":"brian.m.carlson@gmail.com"},"name":"node-sql-2","description":"sql builder","version":"0.80.0","homepage":"https://github.com/TokyoFarmer/node-sql-2","license":"MIT","repository":{"type":"git","url":"git://github.com/TokyoFarmer/node-sql-2.git"},"main":"lib/","types":"lib/types.d.ts","scripts":{"test":"mocha","lint":"jshint lib test","posttest":"jshint lib test"},"engines":{"node":"*"},"dependencies":{"sliced":"0.0.x","lodash":"^4.17.5"},"devDependencies":{"jshint":"*","mocha":">6.0.0"},"mocha":{"reporter":"dot","ui":"tdd"},"gitHead":"bd61fa0f24e91102cb633e626514dec44c0d062b","bugs":{"url":"https://github.com/TokyoFarmer/node-sql-2/issues"},"_id":"node-sql-2@0.80.0","_nodeVersion":"12.13.0","_npmVersion":"6.12.0","dist":{"shasum":"419c515381f5ad87993b3fb165b1b8e61f603649","size":81713,"noattachment":false,"key":"/node-sql-2/-/node-sql-2-0.80.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-sql-2/download/node-sql-2-0.80.0.tgz"},"_npmUser":{"name":"ivasilov","email":"vasilov.ivan@gmail.com"},"directories":{},"maintainers":[{"name":"aingram-hfour","email":""},{"name":"damienpuig","email":""},{"name":"naumhfour","email":""},{"name":"spion","email":"gorgi.kosev@gmail.com"},{"name":"stdim","email":""},{"name":"whoeverest","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/node-sql-2_0.80.0_1610723353990_0.9834204836240561"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2021-12-23T02:47:54.812Z","publish_time":1610723354239,"_cnpm_publish_time":1610723354239},"0.79.0":{"author":{"name":"brianc","email":"brian.m.carlson@gmail.com"},"name":"node-sql-2","description":"sql builder","version":"0.79.0","homepage":"https://github.com/TokyoFarmer/node-sql-2","license":"MIT","repository":{"type":"git","url":"git://github.com/TokyoFarmer/node-sql-2.git"},"main":"lib/","types":"lib/types.d.ts","scripts":{"test":"mocha","lint":"jshint lib test","posttest":"jshint lib test"},"engines":{"node":"*"},"dependencies":{"sliced":"0.0.x","lodash":"^4.17.5"},"devDependencies":{"jshint":"*","mocha":"*"},"gitHead":"e9ec238cec60198b462b772a2017c60f0a2c10c9","bugs":{"url":"https://github.com/TokyoFarmer/node-sql-2/issues"},"_id":"node-sql-2@0.79.0","_nodeVersion":"12.13.0","_npmVersion":"6.12.0","dist":{"shasum":"79e108b3dea5042cba3478b9c5a6274ed61518e1","size":81273,"noattachment":false,"key":"/node-sql-2/-/node-sql-2-0.79.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-sql-2/download/node-sql-2-0.79.0.tgz"},"maintainers":[{"name":"aingram-hfour","email":""},{"name":"damienpuig","email":""},{"name":"naumhfour","email":""},{"name":"spion","email":"gorgi.kosev@gmail.com"},{"name":"stdim","email":""},{"name":"whoeverest","email":""}],"_npmUser":{"name":"naumhfour","email":"naum@hfour.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/node-sql-2_0.79.0_1583940729498_0.049021227400236844"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2021-12-23T02:47:53.225Z","publish_time":1583940729640,"_cnpm_publish_time":1583940729640},"0.78.0":{"author":{"name":"brianc","email":"brian.m.carlson@gmail.com"},"name":"node-sql-2","description":"sql builder","version":"0.78.0","homepage":"https://github.com/TokyoFarmer/node-sql-2","license":"MIT","repository":{"type":"git","url":"git://github.com/TokyoFarmer/node-sql-2.git"},"main":"lib/","types":"lib/types.d.ts","scripts":{"test":"node_modules/.bin/mocha","lint":"jshint lib test","posttest":"jshint lib test"},"engines":{"node":"*"},"dependencies":{"sliced":"0.0.x","lodash":"^4.17.5"},"devDependencies":{"jshint":"*","mocha":"*"},"licenseText":"Copyright (C) 2011 Brian Carlson\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_id":"node-sql-2@0.78.0","dist":{"shasum":"69fe8c701af8ace09fda5a2e61eb0e80e0f56918","size":75984,"noattachment":false,"key":"/node-sql-2/-/node-sql-2-0.78.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-sql-2/download/node-sql-2-0.78.0.tgz"},"maintainers":[{"name":"aingram-hfour","email":""},{"name":"damienpuig","email":""},{"name":"naumhfour","email":""},{"name":"spion","email":"gorgi.kosev@gmail.com"},{"name":"stdim","email":""},{"name":"whoeverest","email":""}],"_npmUser":{"name":"whoeverest","email":"andrejtrajchevski@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/node-sql-2_0.78.0_1525959686301_0.897452182647096"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2021-12-23T02:47:51.663Z","publish_time":1525959686433,"_cnpm_publish_time":1525959686433}},"readme":"# node-sql\n_sql string builder for node_ - supports PostgreSQL, mysql, Microsoft SQL Server, Oracle and sqlite dialects.\n\n[![Build Status](https://secure.travis-ci.org/brianc/node-sql.png)](http://travis-ci.org/TokyoFarmer/node-sql-2)\n\n## install\n\n```sh\n$ npm install node-sql-2\n```\n\n## use\n\n```js\n//require the module\nvar sql = require('sql');\n\n//(optionally) set the SQL dialect\nsql.setDialect('postgres');\n//possible dialects: mssql, mysql, postgres (default), sqlite\n\n//first we define our tables\nvar user = sql.define({\n  name: 'user',\n  columns: ['id', 'name', 'email', 'lastLogin']\n});\n\nvar post = sql.define({\n  name: 'post',\n  columns: ['id', 'userId', 'date', 'title', 'body']\n});\n\n//now let's make a simple query\nvar query = user.select(user.star()).from(user).toQuery();\nconsole.log(query.text); //SELECT \"user\".* FROM \"user\"\n\n//something more interesting\nvar query = user\n    .select(user.id)\n    .from(user)\n    .where(\n      user.name.equals('boom').and(user.id.equals(1))\n    ).or(\n      user.name.equals('bang').and(user.id.equals(2))\n    ).toQuery();\n\n//query is parameterized by default\nconsole.log(query.text); //SELECT \"user\".\"id\" FROM \"user\" WHERE (((\"user\".\"name\" = $1) AND (\"user\".\"id\" = $2)) OR ((\"user\".\"name\" = $3) AND (\"user\".\"id\" = $4)))\n\nconsole.log(query.values); //['boom', 1, 'bang', 2]\n\n//queries can be named\nvar query = user.select(user.star()).from(user).toNamedQuery('user.all');\nconsole.log(query.name); //'user.all'\n\n//how about a join?\nvar query = user.select(user.name, post.body)\n  .from(user.join(post).on(user.id.equals(post.userId))).toQuery();\n\nconsole.log(query.text); //'SELECT \"user\".\"name\", \"post\".\"body\" FROM \"user\" INNER JOIN \"post\" ON (\"user\".\"id\" = \"post\".\"userId\")'\n\n//this also makes parts of your queries composable, which is handy\n\nvar friendship = sql.define({\n  name: 'friendship',\n  columns: ['userId', 'friendId']\n});\n\nvar friends = user.as('friends');\nvar userToFriends = user\n  .leftJoin(friendship).on(user.id.equals(friendship.userId))\n  .leftJoin(friends).on(friendship.friendId.equals(friends.id));\n\n//and now...compose...\nvar friendsWhoHaveLoggedInQuery = user.from(userToFriends).where(friends.lastLogin.isNotNull());\n//SELECT * FROM \"user\"\n//LEFT JOIN \"friendship\" ON (\"user\".\"id\" = \"friendship\".\"userId\")\n//LEFT JOIN \"user\" AS \"friends\" ON (\"friendship\".\"friendId\" = \"friends\".\"id\")\n//WHERE \"friends\".\"lastLogin\" IS NOT NULL\n\nvar friendsWhoUseGmailQuery = user.from(userToFriends).where(friends.email.like('%@gmail.com'));\n//SELECT * FROM \"user\"\n//LEFT JOIN \"friendship\" ON (\"user\".\"id\" = \"friendship\".\"userId\")\n//LEFT JOIN \"user\" AS \"friends\" ON (\"friendship\".\"friendId\" = \"friends\".\"id\")\n//WHERE \"friends\".\"email\" LIKE %1\n\n//Using different property names for columns\n//helpful if your column name is long or not camelCase\nvar user = sql.define({\n  name: 'user',\n  columns: [{\n      name: 'id'\n    }, {\n      name: 'state_or_province',\n      property: 'state'\n    }\n  ]\n});\n\n//now, instead of user.state_or_province, you can just use user.state\nconsole.log(user.select().where(user.state.equals('WA')).toQuery().text);\n// \"SELECT \"user\".* FROM \"user\" WHERE (\"user\".\"state_or_province\" = $1)\"\n```\n\nFor more examples, check out [node-sql-examples](https://node-sql-examples.github.io/)\n\n## from the command line\nYou can use the [sql-generate module](https://github.com/tmont/node-sql-generate)\nto automatically generate definition files from a database instance. For example,\nrunning `node-sql-generate --dsn \"mysql://user:password@host/database\"` will generate\nsomething similar to:\n\n```javascript\n// autogenerated by node-sql-generate v0.0.1 on Tue May 21 2013 01:04:12 GMT-0700 (PDT)\nvar sql = require('sql');\n\n/**\n * SQL definition for database.bar\n */\nexports.bar = sql.define({\n    name: 'bar',\n    columns: [\n        'id',\n        'foo_id'\n    ]\n});\n\n/**\n * SQL definition for database.foo\n */\nexports.foo = sql.define({\n    name: 'foo',\n    columns: [\n        'id',\n        'field_1',\n        'foo_bar_baz'\n    ]\n});\n\n/**\n * Adding a column to an existing table:\n */\nvar model = sql.define({ name: 'foo', columns: [] });\nmodel.addColumn('id');\n\n// If you try to add another column \"id\", node-sql will throw an error.\n// You can suppress that error via:\nmodel.addColumn('id', { noisy: false });\n```\n\nRead the module's documentation for more details.\n\n## contributing\n\nWe __love__ contributions.\n\nnode-sql wouldn't be anything without all the contributors and collaborators who've worked on it.\nIf you'd like to become a collaborator here's how it's done:\n\n1. fork the repo\n2. `git pull https://github.com/(your_username)/node-sql`\n3. `cd node-sql`\n4. `npm install`\n5. `npm test`\n\nAt this point the tests should pass for you.  If they don't pass please open an issue with the output or you can even send me an email directly.\nMy email address is on my github profile and also on every commit I contributed in the repo.\n\nOnce the tests are passing, modify as you see fit.  _Please_ make sure you write tests to cover your modifications.  Once you're ready, commit your changes and submit a pull request.\n\n__As long as your pull request doesn't have completely off-the-wall changes and it does have tests we will almost always merge it and push it to npm__\n\nIf you think your changes are too off-the-wall, open an issue or a pull-request without code so we can discuss them before you begin.\n\nUsually after a few high-quality pull requests and friendly interactions we will gladly share collaboration rights with you.\n\nAfter all, open source belongs to everyone.\n\n\n## license\nMIT\n","_attachments":{},"homepage":"https://github.com/TokyoFarmer/node-sql-2","bugs":{"url":"https://github.com/TokyoFarmer/node-sql-2/issues"},"license":"MIT"}