sails-disk
Advanced tools
Comparing version 1.1.2 to 2.0.0-0
43
index.js
@@ -6,5 +6,5 @@ /** | ||
var _ = require('@sailshq/lodash'); | ||
var path = require('path'); | ||
var async = require('async'); | ||
var nedb = require('nedb'); | ||
var path = require('path'); | ||
var Filesystem = require('machinepack-fs'); | ||
@@ -119,5 +119,10 @@ | ||
// Ensure that the model's primary key has either `autoIncrement` or `required` | ||
if (primaryKeyAttr.required !== true && (!primaryKeyAttr.autoMigrations || primaryKeyAttr.autoMigrations.autoIncrement !== true)) { | ||
return next(new Error('In model `' + modelIdentity + '`, primary key `' + modelDef.primaryKey + '` must have either `required` or `autoIncrement` set.')); | ||
// Ensure that the model's primary key has either `autoIncrement`, `required`, or `type: string` with no default | ||
// (in the latter scenario, mongo-like object ids will be used) | ||
if ( | ||
(!primaryKeyAttr.autoMigrations || primaryKeyAttr.autoMigrations.autoIncrement !== true) && | ||
primaryKeyAttr.required !== true && | ||
(primaryKeyAttr.type !== 'string' || primaryKeyAttr.required) | ||
) { | ||
return next(new Error('In model `' + modelIdentity + '`, primary key `' + modelDef.primaryKey + '` must have either `autoIncrement` set (for SQL-like ids), `required: true` for explicitly-set PKs (rare), or `type: \'string\'` and optional w/ no `defaultsTo` (for mongo-like object IDs).')); | ||
} | ||
@@ -275,7 +280,12 @@ | ||
// If there is a sequence for this table, and the column name referenced in the table | ||
// does not have a value set, set it to the next value of the sequence. | ||
// does not have a value set, set it to the next value of the sequence. Otherwise, | ||
// delete `_id` so a mongo-style object id will be used. | ||
var primaryKeyCol = datastore.primaryKeyCols[query.using]; | ||
var sequenceName = query.using + '_' + primaryKeyCol + '_seq'; | ||
if (!_.isUndefined(datastore.sequences[sequenceName]) && _.isNull(query.newRecord[primaryKeyCol]) || query.newRecord[primaryKeyCol] === 0) { | ||
query.newRecord[primaryKeyCol] = ++datastore.sequences[sequenceName]; | ||
if (!query.newRecord[primaryKeyCol]) { | ||
if (datastore.sequences[sequenceName] !== undefined) { | ||
query.newRecord[primaryKeyCol] = ++datastore.sequences[sequenceName]; | ||
} else { | ||
delete query.newRecord[primaryKeyCol]; | ||
} | ||
} | ||
@@ -305,3 +315,3 @@ | ||
if (query.meta && query.meta.fetch) { | ||
// If the primary key col for this table isn't `_id`, exclude it from the returned records. | ||
// If the primary key col for this table isn't `_id`, exclude `_id` from the returned records. | ||
if (primaryKeyCol !== '_id') { delete newRecord._id; } | ||
@@ -342,6 +352,11 @@ return cb(undefined, newRecord); | ||
// If there is a sequence and `null` is being sent in for this record's primary key, | ||
// set it to the next value of the sequence. | ||
if (!_.isUndefined(datastore.sequences[sequenceName]) && _.isNull(newRecord[primaryKeyCol]) || newRecord[primaryKeyCol] === 0) { | ||
newRecord[primaryKeyCol] = ++datastore.sequences[sequenceName]; | ||
// If there is a sequence for this table, and the column name referenced in the table | ||
// does not have a value set, set it to the next value of the sequence. Otherwise, | ||
// delete `_id` so a mongo-style object id will be used. | ||
if (!newRecord[primaryKeyCol]) { | ||
if (datastore.sequences[sequenceName] !== undefined) { | ||
newRecord[primaryKeyCol] = ++datastore.sequences[sequenceName]; | ||
} else { | ||
delete newRecord[primaryKeyCol]; | ||
} | ||
} | ||
@@ -367,3 +382,3 @@ | ||
if (query.meta && query.meta.fetch) { | ||
// If the primary key col for this table isn't `_id`, exclude it from the returned records. | ||
// If the primary key col for this table isn't `_id`, exclude `_id` from the returned records. | ||
if (primaryKeyCol !== '_id') { | ||
@@ -537,3 +552,3 @@ newRecords = _.map(newRecords, function(newRecord) {delete newRecord._id; return newRecord;}); | ||
if (query.meta && query.meta.fetch) { | ||
// If the primary key col for this table isn't `_id`, exclude it from the returned records. | ||
// If the primary key col for this table isn't `_id`, exclude `_id` from the returned records. | ||
if (primaryKeyCol !== '_id') { | ||
@@ -540,0 +555,0 @@ updatedRecords = _.map(updatedRecords, function(updatedRecord) {delete updatedRecord._id; return updatedRecord;}); |
{ | ||
"name": "sails-disk", | ||
"version": "1.1.2", | ||
"version": "2.0.0-0", | ||
"description": "Persistent local-disk (and/or memory) adapter for Sails.js / Waterline.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
56169
820
2