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

leoric

Package Overview
Dependencies
Maintainers
1
Versions
141
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 0.4.2 to 0.4.3

7

History.md

@@ -1,4 +0,9 @@

0.4.2 / 2019-03-29
0.4.3 / 2019-05-09
==================
* Fix: prevent Bone.dispatch from creating duplicated records of main table
0.4.2 / 2019-04-26
==================
* New: `Spell#orWhere()` and `Spell#orHaving()`

@@ -5,0 +10,0 @@ * New: arithmetic operators

54

lib/bone.js

@@ -758,33 +758,33 @@ 'use strict'

static dispatch(spell, rows, fields) {
if (Object.keys(spell.joins).length == 0) {
return Collection.from(rows, row => this.instantiate(Object.values(row)[0]))
}
const results = new Collection()
const { aliasName, table, primaryColumn, primaryKey } = this
if (Object.keys(spell.joins).length == 0) {
for (const row of rows) {
results.push(this.instantiate(Object.values(row)[0]))
for (const row of rows) {
// If SQL contains subqueries, such as `SELECT * FROM (SELECT * FROM foo) AS bar`,
// the table name of the columns in SQLite is the original table name instead of the alias.
// Hence we need to fallback to original table name here.
const main = row[aliasName] || row[table]
let current = results.find(result => result[primaryKey] == main[primaryColumn])
if (!current) {
current = this.instantiate(main)
results.push(current)
}
} else {
const { aliasName, table, primaryColumn, primaryKey } = this
let current
for (const row of rows) {
// If SQL contains subqueries, such as `SELECT * FROM (SELECT * FROM foo) AS bar`,
// the table name of the columns in SQLite is the original table name instead of the alias.
// Hence we need to fallback to original table name here.
const main = row[aliasName] || row[table]
if (!current || current[primaryKey] != main[primaryColumn]) {
current = this.instantiate(main)
results.push(current)
for (const qualifier in spell.joins) {
const { Model, hasMany } = spell.joins[qualifier]
// It seems mysql2 nests rows with table name instead of qualifier.
const values = row[qualifier] || row[Model.table]
const id = values[Model.primaryColumn]
if (hasMany) {
if (!current[qualifier]) current[qualifier] = new Collection()
if (!id || current[qualifier].some(item => item[Model.primaryKey] == id)) continue
current[qualifier].push(Model.instantiate(values))
} else {
current[qualifier] = id ? Model.instantiate(values) : null
}
for (const qualifier in spell.joins) {
const { Model, hasMany } = spell.joins[qualifier]
// It seems mysql2 nests rows with table name instead of qualifier.
const values = row[qualifier] || row[Model.table]
const id = values[Model.primaryColumn]
if (hasMany) {
if (!current[qualifier]) current[qualifier] = new Collection()
if (!id || current[qualifier].some(item => item[Model.primaryKey] == id)) continue
current[qualifier].push(Model.instantiate(values))
} else {
current[qualifier] = id ? Model.instantiate(values) : null
}
}
}

@@ -791,0 +791,0 @@ }

{
"name": "leoric",
"version": "0.4.2",
"version": "0.4.3",
"description": "JavaScript Object-relational mapping alchemy",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.js",
"index.d.ts",
"lib"
],
"scripts": {

@@ -8,0 +13,0 @@ "jsdoc": "rm -rf docs/api && jsdoc -c .jsdoc.json -d docs/api -t node_modules/@cara/minami",

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