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

Commit

Permalink
Merge pull request #12 from webcc/v0.3
Browse files Browse the repository at this point in the history
V0.3 Rewrite of API for CriteriaQueries + improvements
  • Loading branch information
Evangelos Vlachogiannis committed Oct 2, 2015
2 parents 838fc63 + 98dc563 commit 3941c60
Show file tree
Hide file tree
Showing 12 changed files with 388 additions and 376 deletions.
4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
"use strict";
module.exports = {
MetaModel: require("./lib/MetaModel"),
Criterion: require("./lib/Criterion"),
CriterionType: require("./lib/CriterionType"),
JPAConfiguration: require("./lib/JPAConfiguration"),
QueryBuilder: require("./lib/QueryBuilder"),
CriteriaBuilder: require("./lib/CriteriaBuilder"),
PersistenceUtils: require("./lib/PersistenceUtils"),
Persistence: require("./lib/Persistence"),
EntityManager: require("./lib/EntityManager"),
Expand Down
73 changes: 0 additions & 73 deletions lib/Criterion.js

This file was deleted.

6 changes: 0 additions & 6 deletions lib/CriterionType.js

This file was deleted.

35 changes: 7 additions & 28 deletions lib/DefaultRowInterceptor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"use strict";
let typly = require("typly").instance();
let err = require("./errors");
let PersistenceUtils = require("./PersistenceUtils");
let TimeUuid = require('cassandra-driver').types.TimeUuid;
Expand All @@ -10,21 +11,21 @@ module.exports = class DefaultRowInterceptor {
this.fieldTypes.set("timeuuid", DefaultRowInterceptor.toUuid);
this.fieldTypes.set("text", DefaultRowInterceptor.toText);
this.fieldTypes.set("varchar", DefaultRowInterceptor.toText);
this.fieldTypes.set("map<text,bigint>", DefaultRowInterceptor.toMapText);
this.fieldTypes.set("list<text>", DefaultRowInterceptor.toListText);
this.fieldTypes.set("list<timeuuid>", DefaultRowInterceptor.toListTimeUuid);
this.validate();
}

toRow(type, propertyValue, entityClass)
{
typly.assertString(type);
typly.assertObject(entityClass);
type = type.replace(/\s+/g, '').toLowerCase();
let row = null;
if (propertyValue === null)
{
return null;
}
// if(typeof type === "undefined" || type === null )
if (this.fieldTypes.has(type))
{
let func = this.fieldTypes.get(type);
Expand All @@ -41,27 +42,6 @@ module.exports = class DefaultRowInterceptor {
return row;
}

static toMapText(propertyValue, entityClass)
{
let row = new Map();
if (propertyValue instanceof Map === false)
{
throw new TypeError("Expecting Map type");
}
propertyValue.forEach((value, key, map) =>
{
if (typeof value === "object" && value instanceof entityClass)
{
row.set(key, JSON.stringify(value));
}
else
{
row.set(key, value);
}
});
return row;
}

static toListTimeUuid(propertyValue, entityClass)
{
if (Array.isArray(propertyValue))
Expand All @@ -75,11 +55,11 @@ module.exports = class DefaultRowInterceptor {
}
}

static toListText(propertyValue, entityClass)
static toListText(propertyValue)
{
let properties = [];
if (Array.isArray(propertyValue))
{
let properties = [];
propertyValue.forEach((pro) =>
{
if (typeof pro === "object")
Expand All @@ -91,8 +71,8 @@ module.exports = class DefaultRowInterceptor {
properties.push(pro);
}
});
return properties;
}
return properties;
}

static toUuid(propertyValue)
Expand Down Expand Up @@ -122,5 +102,4 @@ module.exports = class DefaultRowInterceptor {
}
});
}
};

};
7 changes: 2 additions & 5 deletions lib/Entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,12 @@ module.exports = class Entity {
{
obj[newKey] = property;
}
else if (property instanceof Map)
else if(property instanceof Map)
{
let arr = [];
for (let pair of property)
{
let o = {
key: pair[0],
value: pair[1]
};
let o = [pair[0], pair[1]];
arr.push(o);
}
obj[newKey] = arr;
Expand Down
Loading

0 comments on commit 3941c60

Please sign in to comment.