New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

anydb-sql

Package Overview
Dependencies
Maintainers
3
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

anydb-sql - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

2

anydb-sql.js

@@ -105,2 +105,4 @@ var anyDB = require('any-db');

extQuery.execWithin = function (where, fn) {
if (!where || !where.query)
throw new Error("query: Cannot execWithin " + where);
var query = self.toQuery(); // {text, params}

@@ -107,0 +109,0 @@ if (!fn)

2

package.json
{
"name": "anydb-sql",
"version": "0.2.2",
"version": "0.2.3",
"description": "anydb-sql combines node-anydb and node-sql into a single package full of awesomeness.",

@@ -5,0 +5,0 @@ "main": "anydb-sql.js",

@@ -21,3 +21,3 @@ # anydb-sql

Defining a table for that database is the same as in node-sql:
Defining a table is the same as in node-sql:

@@ -35,3 +35,3 @@ ```js

But now you can also specify relationships between tables:
But now you can also add properties based on relationships between tables:

@@ -47,4 +47,7 @@ ```js

});
// user.posts is now a "subtable"
```
Read about [joins and subobjects](#joins-and-subobjects) to see how you can
use subtables with `selectDeep`

@@ -59,15 +62,16 @@ ## extra methods

* get(function(err, row)) - executes the query and returns the first result
* allObject(keyColumn, function(err, map), [mapper, filter]) - executes the
* allObject(keyColumn, function(err, object), [mapper, filter]) - executes the
query and maps the result to an object
* execWithin(transaction, function(err, rows)) - execute within a transaction
* selectDeep - deeply select join results (with grouping). More info below.
* selectDeep - deeply select join results (with grouping). More info in
the section [joins and subobjects](#joins-and-subobjects) below.
If you omit the callback from the additional methods, an eventemitter will be
If you omit the callback from a querying method, an eventemitter will be
returned instead (like in anydb).
Use regular node-sql queries then chain one of the additional methods at the
Use regular node-sql queries then chain one of the querying methods at the
end:
```js
user.where({email: user.email}).get(function(err, user) {
user.where({email: email}).get(function(err, user) {
// user.name,

@@ -93,7 +97,7 @@ });

using `selectDeep`
```js
user.selectDeep(user.name, post.content)
.from(user.join(post).on(user.id.equals(post.userId)))
user.from(user.join(post).on(user.id.equals(post.userId)))
.where(post.date.gt(yesterday))
.selectDeep(user.name, post.content)
.all(function(err, res) {

@@ -104,9 +108,9 @@ // res[0].user.name and res[0].post.content

With selectDeep you can also utilize relationships to get a full-blown
With selectDeep you can also utilize `has` relationships to get full-blown
result structures:
```js
user.selectDeep(user.id, user.name, user.posts)
.from(user.join(user.posts).on(user.id.equals(user.posts.userId)))
user.from(user.join(user.posts).on(user.id.equals(user.posts.userId)))
.where(user.posts.date.gt(yesterday))
.selectDeep(user.id, user.name, user.posts)
.all(function(err, res) {

@@ -120,3 +124,4 @@ // res[0] is

Create a transactions and execute queries within it
To create a transaction and execute queries within it, use
`db.begin()`

@@ -123,0 +128,0 @@ ```js

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc