🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

keystone-db-shortcuts

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

keystone-db-shortcuts

Keystone js database shortcuts.

1.0.24
latest
Source
npm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

KEYSTONE JS DB SHORTCUTS

version 1.0.22

loading the library.

var db = require('keystone-db-shortcuts');

db.schema

db.schema

var schema=db.schema(model_name);

db.model

db.model

var model=db.model(model_name);

db.one

db.one

db.one({
  model: 'ModelName',
  find: { _id: _id }
},function(err,res){
  // do something
});

db.count

db.count where

db.count({
  model: 'ModelName',
  where: { ... }
},function(err,res){
  // do something
});

db.count find

db.count({
  model: 'ModelName',
  find: { _id: _id }
},function(err,res){
  // do something
});

db.exists

db.exists where

db.exists({
  model: 'ModelName',
  where: { _id: _id }
},function(err,res){
  // do something
});

db.exists find

db.exists({
  model: 'ModelName',
  find: { _id: _id }
},function(err,res){
  // do something
});

db.get

complex db.get example

var _q={
  model: 'Papers',
  where: {
    $or: [
      {_id: { $in: [0,1,2,3,4,5] }},
      {numbers: { $in: [0,1,2,3,4,5]}}
    ]
  },
  populate: 'cover',
  select: 'cover name cont',
  limit: 10
};
db.get(_q,function(err,papers){
  if(err) done(true,err);
  else{
    done(null,papers);
  }
});

db.get as find

find all models.

var query = {
  model:'modelName'
};
db.get(query, callback(err, res){
  // do something
});

db.get as findById

modelID String

var query = {
  model:'modelName',
  id: modelID
};
db.get(query, callback(err, res){
  // do something
});

db.get - Find by multiple ids.

id accepts an Array of values.

modelID Array or String

var query = {
  model:'modelName',
  where: { _id : { $in : [...] } }
};
db.get(query, callback(err, res){
  // do something
});

db.get as find (passing a where option.)

var query = {
  model:'modelName',
  where: { ... } // list of columns
};
db.get(query, callback(err, res){
  // do something
});

db.create

var _q = {
  model:'Papers',
  body: {
    name:'Important paper.',
    cont:'...'
  }
};
db.get(_q, callback(err, res){
  // do something
});

db.update (it's like using get.)

var _q={
  model: 'Papers',
  where: { name: 'Unnamed paper.' },
  body:{
    name: 'Important paper.'
  },
  limit: 10
};
db.update(_q,function(err,affected){
  done(err,affected);
});

db.update

passing a function

var _q={
  model: 'Papers',
  where: { _id: _id },
  body:function(model,opts,cb){
    // model - the model.
    // opts - this same _q object.
    // cb - callback for complete.
    // this - model schema.
    model.update({
      // update 1
    },{
      // update 2
    });
  }
};
db.update(_q,function(err,affected){
  done(err,affected);
});

db.destroy (it's like using get.)

var query = {
  model: 'modelName',
  where: { _id: _id }
};
db.destroy(query, callback(err, res){
  // do something
});

License (MIT)

Copyright (c) 2014 Victor P.

Permission 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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE 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.

Keywords

keystonejs

FAQs

Package last updated on 22 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts