Skip to content

Commit f378667

Browse files
committed
fixed hash and range key
1 parent dd4b447 commit f378667

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

index.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ module.exports = (function () {
103103
return Vogels.define(collectionName, function (schema) {
104104
//console.log("_getModel", collectionName);
105105
var columns = global.Hook.models[collectionName].attributes;
106-
var primaryKey = false;
106+
var primaryKeys = []
107107
var indexes = [];
108108
// set columns
109109
for(var columnName in columns){
@@ -112,21 +112,23 @@ module.exports = (function () {
112112
// console.log(columnName+":", attributes);
113113
if(typeof attributes !== "function"){
114114
adapter._setColumnType(schema, columnName, attributes);
115-
116115
// search primarykey
117-
if(!primaryKey){
118-
if("primaryKey" in attributes)
119-
primaryKey = columnName;
120-
}
116+
if("primaryKey" in attributes)primaryKeys.push( columnName );
121117
// search index
122118
if("index" in attributes) indexes.push(columnName);
123119
}
124120
}
125121

126-
if(!primaryKey)
122+
if(primaryKeys.length < 1)
127123
schema.UUID( adapter.keyId, {hashKey: true});
128-
else
129-
adapter._setColumnType(schema, primaryKey, columns[primaryKey], {hashKey: true});
124+
else{
125+
if(! require("underscore").isUndefined(primaryKeys[0])){
126+
adapter._setColumnType(schema, primaryKeys[0], columns[primaryKeys[0]], {hashKey: true});
127+
if(! require("underscore").isUndefined(primaryKeys[1])){
128+
adapter._setColumnType(schema, primaryKeys[1], columns[primaryKeys[1]], {rangeKey: true});
129+
}
130+
}
131+
}
130132
// schema.String( primaryKey, {hashKey: true});
131133
for(var i = 0; i < indexes.length; i++){
132134
var key = indexes[i];

0 commit comments

Comments
 (0)