• Stars
    star
    144
  • Rank 255,590 (Top 6 %)
  • Language
    JavaScript
  • License
    ISC License
  • Created over 12 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple CRUD based persistence abstraction for storing objects to any backend data store. eg. Memory, MongoDB, Redis, CouchDB, Postgres, Punch Card etc.

save - A simple CRUD based persistence abstraction for storing objects to any backend data store. eg. Memory, MongoDB, Redis, CouchDB, Postgres, Punch Card etc.

NPM Details

build status Dependences Join the chat at https://gitter.im/serby/save

save comes with a fully featured in memory engine which is super handy for testing your models. For real world use you'll need to get one of the database powered engines:

If your data store of choice isn't listed here please create an engine and send me a pull request. To see an example of how to create an engine, please see save-mongodb.

Installation

npm install save

Example

var save = require('save')
  , s = save('person')

s.on('create', function() {
  console.log('New person created!')
})

s.create({ name: 'Dom' }, function(err, person) {
  // Outputs { name: 'Dom', _id: 1 }
  console.log(person)
})

Usage

var save = require('save')

var s = save(name, [options])

Save by default returns an in memory engine which means you can unit test your models independently from your database. name is the name of your model.

Possible options are:

  • idProperty. Defaults to _id for mongodb
  • logger. Defaults to console logging: { info: console.info, verbose: console.info }
  • engine. Persistence engine to use, defaults to memory engine: require(./memory-engine)

s.create(object, [cb])

Creates a new entity. cb called with cb(err, savedObject).

s.read(id, [cb])

Reads a single entity with an idProperty of id. cb called with cb(err, readObject).

s.update(object, overwrite, [cb])

Updates a single entity. Optionally overwrites the entire entity, by default just extends it with the new values. cb called with cb(err, readObject).

s.delete(id, [cb])

Deletes one entity. Returns an error if the object can not be found. cb called with cb(err).

s.deleteMany(query, [cb])

Deletes entities based on a query. Performs a find by query, then calls delete for each item returned Returns an error if no items match the query. cb called with cb(err).

s.find(query, options, cb)

Performs a find on the data. cb called with cb(err, foundObjectsArray).

s.findOne(query, options, cb)

Performs a find on the data and limits the result set to 1. cb called with cb(err, foundObject).

s.count(query, cb)

Performs a count by query. cb called with cb(err, count).

s.idProperty

Provides access to the idProperty. Mostly used for testing.

Events

s.on('create', cb)

This event fires with cb(object) where object is the item that will be created.

s.on('afterCreate', cb)

This event fires with cb(object) where object is the item that has been created.

s.on('update', cb)

This event fires with cb(object, overwrite) where object is the item that will be updated and overwrite is whether the object is to be overwritten or extended.

s.on('afterUpdate', cb)

This event fires with cb(object, overwrite) where object is the item that has been updated and overwrite is whether the object is to be overwritten or extended.

s.on('delete', cb)

This event fires with cb(id) where id is the item that will be deleted.

s.on('afterDelete', cb)

This event fires with cb(id) where id is the item that has been deleted.

s.on('deleteMany', cb)

This event fires with cb(query) where query is the query used to deleteMany.

s.on('afterDeleteMany', cb)

This event fires with cb(query) where query is the query that has used deleteMany.

s.on('read', cb)

This event fires with cb(id) where id is the item that has been read.

s.on('find', cb)

This event fires with cb(query) where query is the query used to find.

s.on('findOne', cb)

This event fires with cb(query) where query is the query used to findOne.

s.on('count', cb)

This event fires with cb(query) where query is the query used to count.

s.on('error', cb)

This event fires with cb(err) where err is any error that may have occured.

Credits

Paul Serby follow me on twitter @serby

Dom Harrington

Licence

Licenced under the New BSD License

More Repositories

1

versionator

Connect middleware to add false versions to static content paths
JavaScript
95
star
2

ctrl

An open source CMS written in node.js
JavaScript
76
star
3

compact

A simple JavaScript compacting middleware for express
JavaScript
50
star
4

schemata

Define, create, and validate your business objects based on specified schema.
JavaScript
45
star
5

uber-cache

A simple caching module for node.js that can support any caching backend
JavaScript
28
star
6

express-graceful-shutdown

Ensure that during shutdown express returns correctly with a 503
JavaScript
19
star
7

service-locator

node.js service locator to perform inversion of control
JavaScript
18
star
8

ttl-lru-cache

A fast in memory cache with TTL and LRU support
JavaScript
15
star
9

maiden

A build tool for php
PHP
14
star
10

save-mongodb

mongodb persistence engine for save
JavaScript
13
star
11

jquery.placeholder.js

Replicates the HTML placeholder functionality
CSS
12
star
12

GitIgnore

A .gitignore file for general use. PHP, Node.js, Vim, Eclipse, OsX and Windows
10
star
13

bundled

A standalone bundle manage which can add an extendable plugin system to any application
JavaScript
9
star
14

stream-grep

Streaming search for an array of regexs in a given stream, emits event when found.
JavaScript
7
star
15

Atrox

A PHP framework and CMS designed for use by small to medium sized build agencies.
PHP
7
star
16

crud-service

Simple crud service for object definition, validation, basic persistance and collection.
JavaScript
7
star
17

flow-control-examples

Different approaches to solving common async flow control problems
JavaScript
6
star
18

Training-MongodbExample

JavaScript
6
star
19

jshint-config

My jshint config
6
star
20

Training-HelloWorld

JavaScript
6
star
21

Training-TwitterClient

JavaScript
6
star
22

vim-historic

This is a simple vim plugin that stores each save vim make to a git repo.
Vim Script
6
star
23

Training-ExpressExample

JavaScript
5
star
24

yonder

A remote monitoring
JavaScript
5
star
25

bowler

Node.js running on a Raspberry PI from my bowler hat
JavaScript
5
star
26

skeleton-npm

A skeleton npm module to be used as a base for all my npm modules
Shell
4
star
27

trunky

Basic truncation and string tools
JavaScript
4
star
28

simplate

A light weight async template parser.
JavaScript
4
star
29

validity

JavaScript
4
star
30

Atrox3

An old version of the clock framework
PHP
4
star
31

uber-cache-redis

JavaScript
3
star
32

piton-pipe

Build and run an Async pipeline of functions
JavaScript
3
star
33

piton-entity

A mixin to be inherited by objects that manager entities.
JavaScript
3
star
34

.vim

My vim config
Vim Script
3
star
35

jangle

Flow control for asynchronous operations that aren't well handled by async
JavaScript
3
star
36

DefaultPhingBuild

Deployment and general build tool
PHP
3
star
37

Piton

The php application framework - WARNING I'm going to rename this repo and use the name piton for the JavaScript toolkit
PHP
2
star
38

deploy-npm-module

A simple little tool to ensure that npm modules are tagged and pushed before publishing
JavaScript
2
star
39

regg

Registry Pattern for JavaScript
JavaScript
2
star
40

ClockCodeSniffs

CodeSniffer Sniffs for the Clock coding standards
PHP
2
star
41

evnet

ZeroMQ based event dispatcher
JavaScript
2
star
42

doorman

JavaScript
2
star
43

clustered

JavaScript
2
star
44

control-cli

Command line helper tool for building projects with control cms
JavaScript
2
star
45

shorten

Convert integer IDs to short textual IDs and vice versa. Ideal for URL shortening.
JavaScript
2
star
46

piton-string-utils

General purpose string parsing and formatting functions
JavaScript
1
star
47

lnug

Site for London Node.js User Group
CoffeeScript
1
star
48

typescript-eslint-prettier-starter

Starter project for NodeJs based TypeScript tool or module
JavaScript
1
star
49

uber-cache-mongodb

JavaScript
1
star
50

piton-mixin

Mixes in the functions from another objects prototype from the piton toolkit
JavaScript
1
star
51

console-histogram

Output a histogram on the console
JavaScript
1
star
52

piton-http-utils

HTTP support functions for nodejs
JavaScript
1
star
53

uber-cache-memcached

JavaScript
1
star
54

entity-store-mongodb

A mongodb engine for entity store
1
star
55

any-newer-files

JavaScript
1
star
56

.dot-ix

I've split my .dot files so can now make public any config that does not contain sensitive information.
Shell
1
star
57

wiki-renderer

Typescript rendering of document components for Media Wiki.
TypeScript
1
star
58

jquery-box.js

1
star
59

scratch.js

A scratch area for JavaScript snippets
JavaScript
1
star
60

configury

Easy management of section/environment based configuration.
JavaScript
1
star
61

uber-memoize

Async memoize module powered by uber-cache
JavaScript
1
star
62

pivotal-tracker-graphql-resolver

Graphql Resolver that interfaces with the Pivotal Tracker Rest API
JavaScript
1
star
63

enlist

1
star
64

piton-validity

A extendible validation framework and collection of standard validators
JavaScript
1
star
65

mucher

Simple Static Web Server With Custom 404 and secure headers
JavaScript
1
star