npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@canner/canner-api

v0.0.24

Published

canner api

Downloads

67

Readme

canner-api NPM version Dependency Status

The api of canner.

Installation

$ npm install --save canner-api

or

<script src="https://static.canner.io/canner-api/stable/sdk.js"></script>

Usage

import CannerApi from 'canner-api';
const db = new CannerApi(<api key>).connect();
db.array('article')
    .find({title: 'Today is a good day.'})
    .exec((err, docs) {
      // ...
    });
db.object('author')
    .get('name')
    .exec((err, docs) {
      // ...
    });

API

Type

There are two data formats to choose. Each one of them offer the serveral methods to do operation on it.

array

Declares the specific array of the data.

db.array('posts');

object

Declares the specific object of the data.

db.object('info');

exec

Executes the request. If callback is not given, return a Promise;

db.array('posts')
  .find({title:'Today is a good day.'});
  .exec(callback);

db.array('posts')
  .find({title:'Today is a good day.'});
  .exec()
  .then(callback)
  .catch(errHandler);

Operators

find

Only for array. Declares this request a find operator. Executed when give a callback.

db.array('posts')
  .find()

db.array('posts')
  .find({title: 'Today is a good day.'})

db.array('posts')
  .find({title: 'Today is a good day.'}, function(err, docs) {
    // docs = [
    //  {title: 'Today is a good day.'}
    // ]
    // ...
  });

findOne

Only for array. Declares this request a findOne operator. Executed when give a callback. Return the first matched data.

db.array('posts')
  .findOne()

db.array('posts')
  .findOne({title: 'Today is a good day.'})

db.array('posts')
  .findOne({title: 'Today is a good day.'}, function(err, doc) {
    // doc = {
    //  title: 'Today is a good day.'
    // }
    // ...
  });

Delete

Only for array. Declares this request a delete operator. Executed when give a callback.

db.array('posts')
  .delete('<postId>')

db.array('posts')
  .delete('<postId>', function(err) {
    if (err) {
      // do something
    }
  });

Update

Only for array. Declares this request a update operator. Executed when give a callback.

db.array('posts')
  .update('<postId>', {title: 'This is a good day!'})

db.array('posts')
  .update('<postId>', {title: 'This is a good day!'}, function(err) {
    // ...;
  });

Create

Only for array. Declares this request a create operator. Executed when give a callback.

db.array('posts')
  .create({title: 'This is a good day.', content: 'yes'})

db.array('posts')
  .create({title: 'This is a good day.', content: 'yes'}, function(err, docs) {
    // ...;
    // return the docs you given with its _id
  });

Set

Only for object. Declares this request a set operator. Executed when give a callback.

db.object('person')
  .set('name', 'canner-tools!')

db.object('person')
  .set('info/city', 'Taipei', function(err) {
    // ...;
  });

Get

Only for object. Declares this request a get operator. Executed when give a callback.

db.object('person')
  .get('', function(err, doc) {
    // doc = {
    //   name: 'lee'
    // }
  })

db.object('person')
  .get('name', function(err, doc) {
    // doc = 'lee'
    // ...;
  });

Conditions

Only for array.

where

Specifies a path for adding one or one more conditions.

db.array("posts")
  .where({'title', 'title'})
  .find(callback)

db.array('post').find()
  .where({date: {$gt: '2017/05/04'}})

db.array('post').find()
  .where('date').gt('2017/05/04')
  .where('date').lt('2017/05/08')
  .exec(callback)

gt

Specifies $gt condition.

db.array("posts")
  .where('viewer').gt(15)

gte

Specifies $gte condition.

db.array("posts")
  .where('viewer').gte(15)

lt

Specifies $lt condition.

db.array("posts")
  .where('viewer').lt(150)

lte

Specifies $lte condition.

db.array("posts")
  .where('viewer').lte(150)

equals

Specifies $eq condition.

db.array("posts")
  .where('viewer').equals(15)

db.array("posts")
  .where('viewer').eq(15)

contains

Specifies $contains condition.


// posts: [{
//  title: 'this is a title',
//  tags: ['tiger', 'elephant', ...]
// }]
db.array("posts")
  .where('tags').contains('tiger')

in

Specifies $in condition.


// posts: [{
//  title: 'this is a title',
//  tag: 'tiger'
// }]
db.array("posts")
  .where('tag').in(['tiger', 'elephant', 'dog'])

exists

Specifies $exists condition.


// posts: [{
//  title: 'post1',
//  content: 'content',
//  ahthor: 'Lee'
// }, {
//  title: 'post2',
//  content: 'content',
// }]

// find the posts which have the author field
db.array("posts")
  .where('author').exists()

Options

Only for array.

limit

Specifies the limit option.

db.array("posts")
  .find().limit(10)

skip

Specifies the skip option.

db.array("posts")
  .find().skip(10)

sort

Specifies the sort option.

db.array("posts")
  .find().sort(10)

page

Specifies the page option.

use with perPage

db.array("posts").find().page(2)
  .exec(function(err, docs) {
    // docs = {
    //   data: [...],
    //   totalPage: 8
    // }
  });

perPage

Specifies the perPage option.

use with page

db.array("posts").find().perPage(10)
  .exec(function(err, docs) {
    // docs = {
    //   data: [...],
    //   totalPage: 8
    // }
  });

License

Apache-2.0 © abz53378