Skip to content
This repository has been archived by the owner on Oct 25, 2018. It is now read-only.

Commit

Permalink
Simplify TimeUuid - expecting String or Date or DateString
Browse files Browse the repository at this point in the history
  • Loading branch information
evlach committed Nov 18, 2015
1 parent 5223d29 commit da2e703
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
12 changes: 6 additions & 6 deletions lib/CriteriaBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ module.exports = class CriteriaBuilder {

doOp(x, y, op)
{
let fieldType = this.metaModel.fields.get(x);
if(fieldType.toLowerCase().indexOf("uuid")>-1){
y = PersistenceUtils.toTimeUuid(y);
}
if (typeof y === "string")
let fieldType = this.metaModel.fields.get(x.trim());
if (fieldType === "text" || fieldType === "varchar")
{
return "\"" + x + "\"" + op + "'" + y + "'";
}
return "\"" + x + "\"" + "=" + y;
else{
y = this.metaModel.rowInterceptor.toRow(fieldType, y, this.metaModel.entityClass);
return "\"" + x + "\"" + op + y;
}
}
};
6 changes: 4 additions & 2 deletions lib/DefaultRowInterceptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ module.exports = class DefaultRowInterceptor {
toRow(type, propertyValue, entityClass)
{
typly.assertString(type);
typly.assertObject(entityClass);
if(entityClass){
typly.assertObject(entityClass);
}
type = type.replace(/\s+/g, '').toLowerCase();
let row = null;
if (propertyValue === null)
Expand Down Expand Up @@ -89,7 +91,7 @@ module.exports = class DefaultRowInterceptor {

static toUuid(propertyValue)
{
return PersistenceUtils.toTimeUuid(propertyValue);
return PersistenceUtils.toTimeUuid(propertyValue).toString();
}

static toText(propertyValue, entityClass)
Expand Down
1 change: 1 addition & 0 deletions lib/EntityManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ module.exports = class EntityManager {
{
this.metaModel = metaModel || this.metaModel;
let row = this.metaModel.toRow(entity);
row.id = row.id.toString();
const queryObject = this.getCriteriaQuery().insert(row);
return this.query(queryObject, callback);
}
Expand Down
3 changes: 1 addition & 2 deletions test/EntityManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ describe("cassandra-jpa::EntityManager", function ()
it("should convert entity toRow", function ()
{
let row = fooMetaModel.toRow(foo);
assert.equal(typeof row.id === "object", true);
assert.equal(row.id instanceof m.PersistenceUtils.getDriver().types.TimeUuid, true);
assert.equal(typeof row.id === "string", true);
assert.equal(typeof row.entity === "string", true);
assert.equal(row.entities.length, 2);
assert.equal(row.entities[0] instanceof Foo, false);
Expand Down
5 changes: 5 additions & 0 deletions test/PersistenceUtils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ describe("cassandra-jpa::PersistenceUtils", function ()
let entity = new Foo();
assert.equal(m.PersistenceUtils.isImplementationOf(entity, Foo), true);
});
it("should find instance of Entity Class", function ()
{
let entity = new m.examples.Foo();
assert.equal(m.PersistenceUtils.isImplementationOf(entity, m.examples.Foo), true);
});
it("should find instance of Class", function ()
{
let FooFunc = function(){
Expand Down

0 comments on commit da2e703

Please sign in to comment.