Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

leoric

Package Overview
Dependencies
Maintainers
1
Versions
143
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

leoric - npm Package Compare versions

Comparing version 1.7.1 to 1.8.0

6

History.md

@@ -0,1 +1,7 @@

1.8.0 / 2021-08-30
==================
* feat: silent option fix #164 (#165)
* feat: binary type (#166)
1.7.1 / 2021-08-17

@@ -2,0 +8,0 @@ ==================

2

package.json
{
"name": "leoric",
"version": "1.7.1",
"version": "1.8.0",
"description": "JavaScript Object-relational mapping alchemy",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -402,10 +402,11 @@ 'use strict';

const { where, paranoid } = options;
const spell = super.update(where);
// pass options to update
const spell = super.update(where, undefined, options);
if (Array.isArray(fields)) {
for (const field of fields) spell.$increment(field);
for (const field of fields) spell.$increment(field, undefined, options);
} else if (fields != null && typeof fields === 'object') {
for (const field in fields) spell.$increment(field, fields[field]);
for (const field in fields) spell.$increment(field, fields[field], options);
} else if (typeof fields === 'string') {
spell.$increment(fields);
spell.$increment(fields, undefined, options);
} else {

@@ -614,3 +615,2 @@ throw new Error(`Unexpected fields: ${fields}`);

}
return Model.increment(fields, {

@@ -617,0 +617,0 @@ ...options,

@@ -64,11 +64,25 @@ 'use strict';

this.binary = true;
this.dataType = 'binary';
return this;
}
get VARBINARY() {
this.varbinary = true;
this.dataType = 'varbinary';
return this;
}
static BINARY() {
return new this().BINARY;
}
static VARBINARY() {
return new this().VARBINARY;
}
toSqlString() {
const { length, binary } = this;
const { length } = this;
const dataType = this.dataType.toUpperCase();
const chunks = [];
chunks.push(length > 0 ? `${dataType}(${length})` : dataType);
if (binary) chunks.push('BINARY');
return chunks.join(' ');

@@ -75,0 +89,0 @@ }

@@ -29,7 +29,15 @@ 'use strict';

class Postgres_STRING extends DataTypes.STRING {
toSqlString() {
if (this.binary || this.varbinary) return 'BYTEA';
return super.toSqlString();
}
}
class Postgres_DataTypes extends DataTypes {
static DATE = Postgres_DATE;
static JSONB = Postgres_JSONB;
static STRING = Postgres_STRING;
}
module.exports = Postgres_DataTypes;

@@ -27,2 +27,30 @@ 'use strict';

class Sqlite_STRING extends DataTypes.STRING {
constructor(length = 255) {
super(length);
this.dataType = 'varchar';
}
get BINARY() {
this.binary = true;
return this;
}
get VARBINARY() {
this.varbinary = true;
return this;
}
toSqlString() {
const { length } = this;
const dataType = this.dataType.toUpperCase();
const chunks = [];
chunks.push(dataType);
if (this.binary) chunks.push(length > 0 ? `BINARY(${length})` : 'BINARY');
else if (this.varbinary) chunks.push(length > 0 ? `VARBINARY(${length})` : 'BINARY');
else return super.toSqlString();
return chunks.join(' ');
}
}
class Sqlite_DataTypes extends DataTypes {

@@ -36,4 +64,8 @@ static get DATE() {

}
static get STRING() {
return Sqlite_STRING;
}
}
module.exports = Sqlite_DataTypes;

@@ -289,3 +289,4 @@ 'use strict';

function formatValueSet(spell, obj, strict = true) {
const { Model } = spell;
const { Model, silent = false, command } = spell;
const { timestamps } = Model;
const sets = {};

@@ -301,2 +302,3 @@ for (const name in obj) {

if (silent && timestamps.updatedAt && name === timestamps.updatedAt && command === 'update') continue;
// raw sql don't need to uncast

@@ -621,2 +623,3 @@ if (obj[name] && obj[name].__raw) {

connection: this.connection,
silent: this.silent,
});

@@ -697,4 +700,4 @@ }

$insert(obj) {
this.command = 'insert';
this.sets = parseSet(this, obj);
this.command = 'insert';
return this;

@@ -709,4 +712,4 @@ }

$upsert(obj) {
this.command = 'upsert';
this.sets = parseSet(this, obj);
this.command = 'upsert';
return this;

@@ -716,4 +719,4 @@ }

$bulkInsert(records) {
this.command = 'bulkInsert';
this.sets = parseSet(this, records);
this.command = 'bulkInsert';
return this;

@@ -741,10 +744,12 @@ }

$update(obj) {
this.command = 'update';
this.sets = parseSet(this, obj);
this.command = 'update';
return this;
}
$increment(name, by = 1) {
const { Model } = this;
$increment(name, by = 1, opts = {}) {
let { Model, silent = false } = this;
if (opts.silent != null) silent = opts.silent;
const { timestamps } = Model;
this.command = 'update';
if (!Number.isFinite(by)) throw new Error(`unexpected increment value ${by}`);

@@ -767,8 +772,12 @@ if (!Model.attributes.hasOwnProperty(name)) {

};
this.command = 'update';
if (timestamps.updatedAt && !this.sets[timestamps.updatedAt] && !silent) {
this.sets[timestamps.updatedAt] = new Date();
}
return this;
}
$decrement(name, by = 1) {
return this.$increment(name, -by);
$decrement(name, by = 1, opts = {}) {
return this.$increment(name, -by, opts);
}

@@ -775,0 +784,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc