0.0.2-4 • Published 9 years ago

parse-osmos-driver v0.0.2-4

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

Parse Osmos Driver

Driver for Osmos ODM that uses the Parse SDK. It abstracts away the parse sdk database layer and lets you do queries using simple models and JSON schemas. Most find Queries can be done the same way you'd do with the MongoDB Driver. Great for when you can't use a professional DB, but have the possibility of moving to one in the future.

Example usage

var Osmos = require('osmos-odm');
var Schema = Osmos.Schema;
var Model = Osmos.Model;

var ParseDriver = require('parse-osmos-driver');
var Parse = require('parse').Parse;

var schema = new Schema('https://example.org/tokens', {
      id: 'https://example.org/tokens',
      $schema: 'http://json-schema.org/draft-04/schema#',

      title: 'Token Object',
      description: 'Token Object',

      type: 'object',

      required: ['account', ],

      properties: {

        objectId: {
          type: 'string',
          description: 'Token ID',
        },
        name: {
          type: 'string',
          description: 'The Account name'
        }

      });


schema.primaryKey = 'objectId';

Parse.initialize('13qrdsg3sdrt34vwefwrgisfdis4drtojiovjiwv', 'wiqoejf9endoaisldfj223fd9a9aidasfoimowf');

Osmos.drivers.register('parse', Parse);

model = new Model('TestModel', schema, 'person', 'parse');

model.create(function (err, doc) {
  doc.name = 'Marco';

  doc.save(function (err) {
    expect(err).to.be.null;

    expect(doc.primaryKey).to.be.ok();
    expect(doc.name).to.equal('Macro');

    done();
  });
});

Primary Key

Parse requires that the schema.primaryKey be set to 'objectId'.

Implemented methods

Baiscs

  • create(model, cb)

    Creates a new document and pass it to the callback. The document should be a simple hash—create's only job is to initialize any arbitrary values that are required by the specific data store.

  • get(model, key, cb)

    Retrieves a document from the store. A document-not-found error should be passed to the callback as (null, null).

  • post(document, data, cb)

    Inserts a new document into the data store. The data represents the serialized document and, under most circumstances, can be inserted directly into the data store.

    The document argument, which references the Osmos document that is requesting the insertion operation, is also passed along for convenience.

  • put(document, data, cb)

    Like post(), but for a document that has already been saved in the past.

  • del(model, key, cb)

    Deletes the document with the given key. Document-not-found errors should not result in errors being reported to the callback.

Search operations

  • findOne(model, query, cb)

    Retrieves any result that matches the given query, represented as a simple hash. query should match Parse.Query.protype._where syntax

    A not-found error should be reported as (null, null)

    For example:

    model.findOne({ email: 'marcot@tabini.ca' }, function (err, doc) {
        console.log(doc.email);
    });
  • find(model, spec, cb)

    Retrieves all results that match the given query, returning an array of all the documents that match the query, represented as simple hashes. A not-found error should be reported as (null, []).

0.0.2-4

9 years ago

0.0.2-3

9 years ago

0.0.2-2

9 years ago

0.0.2-1

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago