Skip to content

Commit

Permalink
Merge branch 'release/v0.6.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
sebelga committed Aug 26, 2016
2 parents 2caf04d + 5819642 commit 44cd38c
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 51 deletions.
6 changes: 3 additions & 3 deletions lib/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@
* @param name : model name
*/
model(name) {
return this.constructor.base.model(name);
return this.constructor.gstore.model(name);
}

// return entity from Datastore
datastoreEntity(cb) {
let _this = this;
this.ds.get(this.entityKey, (err, entity) => {
this.gstore.ds.get(this.entityKey, (err, entity) => {
if (err) {
return cb(err);
}
Expand Down Expand Up @@ -142,7 +142,7 @@
if (namespace && !is.array(path)) {
path = [path];
}
return namespace ? self.ds.key({namespace:namespace, path:path}) : self.ds.key(path);
return namespace ? self.gstore.ds.key({namespace:namespace, path:path}) : self.gstore.ds.key(path);
}

function buildEntityData(self, data) {
Expand Down
3 changes: 1 addition & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@
return this.models[name];
}

var ds = options.ds || this._ds;
model = Model.compile(name, schema, ds, this);
model = Model.compile(name, schema, this);

if (!skipInit) {
model.init();
Expand Down
39 changes: 19 additions & 20 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
var datastoreSerializer = require('./serializer').Datastore;
var utils = require('./utils');
var queryHelpers = require('./helper').QueryHelpers;
var GstoreError = require('./error.js');
var GstoreError = require('./error.js');

class Model extends Entity{
constructor (data, id, ancestors, namespace, key) {
super(data, id, ancestors, namespace, key);
}

static compile(kind, schema, ds, base) {
static compile(kind, schema, gstore) {
var ModelInstance = class extends Model {
constructor (data, id, ancestors, namespace, key) {
super(data, id, ancestors, namespace, key);
Expand All @@ -37,9 +37,8 @@
applyStatics(ModelInstance, schema);

ModelInstance.prototype.entityKind = ModelInstance.entityKind = kind;
ModelInstance.prototype.ds = ModelInstance.ds = ds;
ModelInstance.hooks = schema.s.hooks.clone();
ModelInstance.base = base;
ModelInstance.prototype.gstore = ModelInstance.gstore = gstore;

return ModelInstance;
}
Expand All @@ -64,7 +63,7 @@
return transaction.get(key, onEntity);
}

this.ds.get(key, onEntity);
this.gstore.ds.get(key, onEntity);

////////////////////

Expand Down Expand Up @@ -125,7 +124,7 @@
}

if (typeof transaction === 'undefined' || transaction === null) {
transaction = this.ds.transaction();
transaction = this.gstore.ds.transaction();
transaction.run(function(err){
if (err) {
return onTransaction(err);
Expand Down Expand Up @@ -223,7 +222,7 @@
options = args.length > 0 ? args[0] : {};
options = extend(true, {}, _this.schema.options.queries, options);

_this.ds.runQuery(query, onQuery);
_this.gstore.ds.runQuery(query, onQuery);

////////////////////

Expand Down Expand Up @@ -266,12 +265,12 @@
let query = initQuery(this, options.namespace);

// Build query from options passed
query = queryHelpers.buildFromOptions(query, options, this.ds);
query = queryHelpers.buildFromOptions(query, options, this.gstore.ds);

// merge options inside entities option
options = extend({}, this.schema.options.queries, options);

this.ds.runQuery(query, (err, entities, info) => {
this.gstore.ds.runQuery(query, (err, entities, info) => {
if (err) {
return cb(err);
}
Expand Down Expand Up @@ -341,7 +340,7 @@

function executeDelete(callback) {
if (!transaction) {
_this.ds.delete(key, onDelete);
_this.gstore.ds.delete(key, onDelete);
} else {
transaction.delete(key);
transaction.addHook('post', function() {
Expand Down Expand Up @@ -389,10 +388,10 @@
let query = initQuery(this, namespace);

if (ancestors) {
query.hasAncestor(this.ds.key(ancestors.slice()));
query.hasAncestor(this.gstore.ds.key(ancestors.slice()));
}

this.ds.runQuery(query, (err, entities) => {
this.gstore.ds.runQuery(query, (err, entities) => {
if (err) {
return cb(err);
}
Expand Down Expand Up @@ -448,12 +447,12 @@
});

if (ancestors) {
query.hasAncestor(this.ds.key(ancestors.slice()));
query.hasAncestor(this.gstore.ds.key(ancestors.slice()));
}

this.hooks.execPre('findOne', _this, () => {
// Pre methods done
_this.ds.runQuery(query, (err, entities) => {
_this.gstore.ds.runQuery(query, (err, entities) => {
if (err) {
return cb(err);
}
Expand Down Expand Up @@ -526,7 +525,7 @@
query.order(property, {descending: descending});
query.limit(options.after ? options.after : options.before);

this.ds.runQuery(query, (err, entities) => {
this.gstore.ds.runQuery(query, (err, entities) => {
if (err) {
return cb(err);
}
Expand Down Expand Up @@ -573,12 +572,12 @@
let path = getPath(id, ancestors);
let key;
if (typeof namespace !== 'undefined' && namespace !== null) {
key = _this.ds.key({
key = _this.gstore.ds.key({
namespace : namespace,
path : path
});
} else {
key = _this.ds.key(path);
key = _this.gstore.ds.key(path);
}
return key;
}
Expand Down Expand Up @@ -673,7 +672,7 @@
* @private
*/
static __model(data, id, ancestors, namespace, key) {
let M = this.compile(this.entityKind, this.schema, this.ds, this.base);
let M = this.compile(this.entityKind, this.schema, this.gstore);
return new M(data, id, ancestors, namespace, key);
}

Expand Down Expand Up @@ -728,7 +727,7 @@
};

if (!transaction) {
this.ds.save(entity, (err) => {
this.gstore.ds.save(entity, (err) => {
if (err) {
return cb(err);
}
Expand Down Expand Up @@ -921,7 +920,7 @@
if (transaction) {
return transaction.createQuery.apply(transaction, createQueryArgs);
} else {
return self.ds.createQuery.apply(self.ds, createQueryArgs);
return self.gstore.ds.createQuery.apply(self.gstore.ds, createQueryArgs);
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gstore-node",
"version": "0.6.1",
"version": "0.6.2",
"description": "gstore-node is a Google Datastore Entity Models tools",
"main": "index.js",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion test/error/validation-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var chai = require('chai');
var expect= chai.expect;

var gstore = require('../../');
var Model = require('../../lib/model');
var Schema = require('../../lib/schema');
var ValidationError = require('../../lib/error/validation');
Expand All @@ -25,7 +26,7 @@ describe('ValidationError', () => {
it('should return "{entityKind} validation failed" if called with entity instance', () => {
let entityKind = 'Blog';
let schema = new Schema({});
let ModelInstance = Model.compile(entityKind, schema, {key:()=> {}});
let ModelInstance = Model.compile(entityKind, schema, gstore);
let model = new ModelInstance({});
let error = new ValidationError(model);

Expand Down
Loading

0 comments on commit 44cd38c

Please sign in to comment.