Skip to content

aruberto/node-couchbase-repository

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-couchbase-repository

Create a repository for model backed by couchbase bucket. Based on spring data repository pattern.

Requirements

  • node ^7.6.0

Installation

npm install --save couchbase couchbase-repository

Usage

import couchbase from 'couchbase';
import createCouchbaseRepository from 'couchbase-repository';
import yup from 'yup';

const cluster = new couchbase.Cluster(<insert url here ...>);
const bucket = cluster.openBucket('my-bucket');

// use yup or any other object validation framework you want
const personSchema =
  yup.object().shape({
    name: yup.string().required(),
    email: yup.string().email().required()
  });

const personRepository = createCouchbaseRepository({
  bucket,
  type: 'people',
  async validate (input) { // expecting validate function to return a promise
    return personSchema.validate(input);
  }
});

async function doWork() {
  const newPerson = await personRepository.save({ name: 'Joe Blow', email: '[email protected]' });

  console.log(newPerson.id); // will print a uuid

  const existingPerson = await personRepository.findOne('1231-1213-11-1231');

  await personRepository.del('1231-123-123-1312');
}

License

MIT

About

Repository generator for couchbase.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published