# @canner/canner-api

> canner api

Latest version **0.0.24** (published 2017-10-16) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @canner/canner-api
pnpm add @canner/canner-api
yarn add @canner/canner-api
bun add @canner/canner-api
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.24 |
| Published | 2017-10-16 |
| First published | 2017-05-16 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | abz53378 |
| Maintainers | abz53378, wwwy3y3, ctxhou, chilijung |
| Keywords | cannerapi canner api |

## Links

- npm: https://www.npmjs.com/package/@canner/canner-api
- Repository: https://github.com/Canner/canner-api
- Issues: https://github.com/Canner/canner-api/issues
- npm.io page: https://npm.io/package/@canner/canner-api

## Dependencies (5)

- [store](https://npm.io/package/store.md) ^2.0.12
- [lodash](https://npm.io/package/lodash.md) ^4.17.4
- [superagent](https://npm.io/package/superagent.md) ^3.5.2
- [whatwg-fetch](https://npm.io/package/whatwg-fetch.md) ^2.0.3
- [promise-polyfill](https://npm.io/package/promise-polyfill.md) ^6.0.2

## Recent versions

- 0.0.24 (latest) — 2017-10-16
- 0.0.23 — 2017-10-16
- 0.0.21 — 2017-08-29
- 0.0.20 — 2017-08-24
- 0.0.18 — 2017-08-16
- 0.0.17 — 2017-07-20
- 0.0.16 — 2017-07-19
- 0.0.15 — 2017-07-19
- 0.0.14 — 2017-07-11
- 0.0.13 — 2017-07-10
- 0.0.11 — 2017-07-10
- 0.0.10 — 2017-06-27
- 0.0.9 — 2017-06-20
- 0.0.8 — 2017-06-20
- 0.0.7 — 2017-06-20
- … 6 more at https://npm.io/package/@canner/canner-api/versions

## README

# canner-api [![NPM version][npm-image]][npm-url]  [![Dependency Status][daviddm-image]][daviddm-url]

The api of canner.

## Installation

```sh
$ npm install --save canner-api
```

or

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

## Usage

```js
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
  * [array](#array)
  * [object](#object)
* [exec](#exec)
* Operators
  * For array
    * [find](#find)
    * [findOne](#findOne)
    * [delete](#delete)
    * [update](#update)
    * [create](#create)
  * For object
    * [set](#set)
    * [get](#get)
* Conditions (Only for array)
  * [where](#where)
  * [gt](#gt)
  * [gte](#gte)
  * [lt](#lt)
  * [lte](#lte)
  * [equals](#equals) / [eq](#equals)
  * [contains](#contains)
  * [in](#in)
  * [exists](#exists)
* Options (Only for array)
  * [limit](#lmit)
  * [skip](#skip)
  * [sort](#sort)
  * [page](#page)
  * [perPage](#perPage)




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

``` js
db.array('posts');
```

#### object

Declares the specific object of the data.

``` js
db.object('info');
```

### exec

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

``` js
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.

``` js
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.

``` js
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.

``` js
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.

``` js
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.

``` js
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.

``` js
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.

``` js
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.

``` js
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.

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

#### gte

Specifies  `$gte` condition.

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

#### lt

Specifies  `$lt` condition.

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

#### lte

Specifies  `$lte` condition.

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

#### equals

Specifies  `$eq` condition.

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

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

#### contains

Specifies `$contains` condition.

``` js

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

```

#### in

Specifies `$in` condition.

``` js

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

```

#### exists

Specifies `$exists` condition.

``` js

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

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

#### skip

Specifies the `skip` option.

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

#### sort

Specifies the `sort` option.

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

#### page

Specifies the `page` option.

*use with perPage*

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

#### perPage

Specifies the `perPage` option.

*use with page*

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


## License

Apache-2.0 © [abz53378]()


[npm-image]: https://badge.fury.io/js/canner-api.svg
[npm-url]: https://npmjs.org/package/canner-api
[travis-image]: https://travis-ci.org/Canner/canner-api.svg?branch=master
[travis-url]: https://travis-ci.org/Canner/canner-api
[daviddm-image]: https://david-dm.org/Canner/canner-api.svg?theme=shields.io
[daviddm-url]: https://david-dm.org/Canner/canner-api

---
_Source: https://npm.io/package/@canner/canner-api · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
