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

cormo

Package Overview
Dependencies
Maintainers
8
Versions
172
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cormo - npm Package Compare versions

Comparing version 0.17.0 to 0.17.1

9

lib/adapters/base.d.ts

@@ -55,5 +55,14 @@ import { ColumnPropertyInternal } from '../model';

export interface AdapterCountOptions {
select?: string[];
conditions_of_group: any[];
group_fields?: any;
group_by?: string[];
joins: Array<{
model_name: string;
type: string;
alias: string;
base_column: string;
join_column: string;
}>;
distinct?: boolean;
transaction?: Transaction;

@@ -60,0 +69,0 @@ node?: 'master' | 'read';

26

lib/adapters/mysql.js

@@ -571,11 +571,24 @@ "use strict";

/** @internal */
async count(model, conditions, options) {
async count(model_name, conditions, options) {
const model_class = this._connection.models[model_name];
const select = options.select ? this._buildSelect(model_class, options.select) : '*';
const params = [];
const table_name = this._connection.models[model].table_name;
let sql = `SELECT COUNT(*) AS count FROM \`${table_name}\``;
const table_name = model_class.table_name;
const join_schemas = {};
let sql = options.distinct && !options.select
? `SELECT DISTINCT _Base.* FROM \`${table_name}\` AS _Base`
: `SELECT COUNT(${options.distinct ? 'DISTINCT' : ''} ${select}) AS count FROM \`${table_name}\` AS _Base`;
if (options.index_hint) {
sql += ` ${options.index_hint}`;
}
if (options.joins.length > 0) {
const escape_ch = this._escape_ch;
for (const join of options.joins) {
sql += ` ${join.type} ${this._connection.models[join.model_name].table_name} AS _${join.alias}`;
sql += ` ON _Base.${escape_ch}${join.base_column}${escape_ch} = _${join.alias}.${escape_ch}${join.join_column}${escape_ch}`;
join_schemas[join.alias] = this._connection.models[join.model_name]._schema;
}
}
if (conditions.length > 0) {
sql += ' WHERE ' + this._buildWhere(this._connection.models[model]._schema, '', {}, conditions, params);
sql += ' WHERE ' + this._buildWhere(model_class._schema, '_Base', join_schemas, conditions, params);
}

@@ -586,6 +599,9 @@ if (options.group_by) {

if (options.conditions_of_group.length > 0) {
sql += ' HAVING ' + this._buildWhere(options.group_fields, '', {}, options.conditions_of_group, params);
sql += ' HAVING ' + this._buildWhere(options.group_fields, '_Base', {}, options.conditions_of_group, params);
}
sql = `SELECT COUNT(*) AS count FROM (${sql}) _sub`;
}
if (options.distinct && !options.select) {
sql = `SELECT COUNT(*) AS count FROM (${sql}) _sub`;
}
let result;

@@ -592,0 +608,0 @@ try {

@@ -417,8 +417,21 @@ "use strict";

/** @internal */
async count(model, conditions, options) {
async count(model_name, conditions, options) {
const model_class = this._connection.models[model_name];
const select = options.select ? this._buildSelect(model_class, options.select) : '*';
const params = [];
const table_name = this._connection.models[model].table_name;
let sql = `SELECT COUNT(*) AS count FROM "${table_name}"`;
const table_name = model_class.table_name;
const join_schemas = {};
let sql = options.distinct && !options.select
? `SELECT DISTINCT _Base.* FROM "${table_name}" AS _Base`
: `SELECT COUNT(${options.distinct ? 'DISTINCT' : ''} ${select}) AS count FROM "${table_name}" AS _Base`;
if (options.joins.length > 0) {
const escape_ch = this._escape_ch;
for (const join of options.joins) {
sql += ` ${join.type} ${this._connection.models[join.model_name].table_name} AS _${join.alias}`;
sql += ` ON _Base.${escape_ch}${join.base_column}${escape_ch} = _${join.alias}.${escape_ch}${join.join_column}${escape_ch}`;
join_schemas[join.alias] = this._connection.models[join.model_name]._schema;
}
}
if (conditions.length > 0) {
sql += ' WHERE ' + this._buildWhere(this._connection.models[model]._schema, '', {}, conditions, params);
sql += ' WHERE ' + this._buildWhere(model_class._schema, '_Base', join_schemas, conditions, params);
}

@@ -429,6 +442,9 @@ if (options.group_by) {

if (options.conditions_of_group.length > 0) {
sql += ' HAVING ' + this._buildWhere(options.group_fields, '', {}, options.conditions_of_group, params);
sql += ' HAVING ' + this._buildWhere(options.group_fields, '_Base', {}, options.conditions_of_group, params);
}
sql = `SELECT COUNT(*) AS count FROM (${sql}) _sub`;
}
if (options.distinct && !options.select) {
sql = `SELECT COUNT(*) AS count FROM (${sql}) _sub`;
}
let result;

@@ -435,0 +451,0 @@ try {

@@ -407,8 +407,21 @@ "use strict";

/** @internal */
async count(model, conditions, options) {
async count(model_name, conditions, options) {
const model_class = this._connection.models[model_name];
const select = options.select ? this._buildSelect(model_class, options.select) : '*';
const params = [];
const table_name = this._connection.models[model].table_name;
let sql = `SELECT COUNT(*) AS count FROM "${table_name}"`;
const table_name = model_class.table_name;
const join_schemas = {};
let sql = options.distinct && !options.select
? `SELECT DISTINCT _Base.* FROM "${table_name}" AS _Base`
: `SELECT COUNT(${options.distinct ? 'DISTINCT' : ''} ${select}) AS count FROM "${table_name}" AS _Base`;
if (options.joins.length > 0) {
const escape_ch = this._escape_ch;
for (const join of options.joins) {
sql += ` ${join.type} ${this._connection.models[join.model_name].table_name} AS _${join.alias}`;
sql += ` ON _Base.${escape_ch}${join.base_column}${escape_ch} = _${join.alias}.${escape_ch}${join.join_column}${escape_ch}`;
join_schemas[join.alias] = this._connection.models[join.model_name]._schema;
}
}
if (conditions.length > 0) {
sql += ' WHERE ' + this._buildWhere(this._connection.models[model]._schema, '', {}, conditions, params);
sql += ' WHERE ' + this._buildWhere(model_class._schema, '_Base', join_schemas, conditions, params);
}

@@ -419,6 +432,9 @@ if (options.group_by) {

if (options.conditions_of_group.length > 0) {
sql += ' HAVING ' + this._buildWhere(options.group_fields, '', {}, options.conditions_of_group, params);
sql += ' HAVING ' + this._buildWhere(options.group_fields, '_Base', {}, options.conditions_of_group, params);
}
sql = `SELECT COUNT(*) AS count FROM (${sql})`;
}
if (options.distinct && !options.select) {
sql = `SELECT COUNT(*) AS count FROM (${sql}) _sub`;
}
let result;

@@ -425,0 +441,0 @@ try {

2

lib/query.js

@@ -363,3 +363,3 @@ "use strict";

}
return await this._adapter.count(this._name, this._conditions, this._options);
return await this._adapter.count(this._name, this._conditions, this._getAdapterFindOptions());
}

@@ -366,0 +366,0 @@ /**

{
"name": "cormo",
"description": "ORM framework for Node.js",
"version": "0.17.0",
"version": "0.17.1",
"keywords": [

@@ -70,3 +70,3 @@ "orm",

},
"gitHead": "872e1e3c54a371ba6e51a3e26f5fd9b0439e05ed"
"gitHead": "15608998db60020e71640fe24a5f60e485731577"
}
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