cormo
Advanced tools
Comparing version 0.12.4 to 0.12.5
@@ -26,2 +26,3 @@ import { Transaction } from '../transaction'; | ||
transaction?: Transaction; | ||
node?: 'master' | 'read'; | ||
} | ||
@@ -33,2 +34,3 @@ export interface IAdapterCountOptions { | ||
transaction?: Transaction; | ||
node?: 'master' | 'read'; | ||
} | ||
@@ -35,0 +37,0 @@ /** |
@@ -29,3 +29,6 @@ export interface IAdapterSettingsMySQL { | ||
*/ | ||
query(text: string, values?: any[], transaction?: Transaction): Promise<any>; | ||
query(text: string, values?: any[], options?: { | ||
transaction?: Transaction; | ||
node?: 'master' | 'read'; | ||
}): Promise<any>; | ||
/** | ||
@@ -32,0 +35,0 @@ * Remove all unused connections from pool. |
@@ -255,3 +255,3 @@ "use strict"; | ||
try { | ||
result = await this.query(sql, values, options.transaction); | ||
result = await this.query(sql, values, { transaction: options.transaction }); | ||
} | ||
@@ -283,3 +283,3 @@ catch (error) { | ||
try { | ||
result = await this.query(sql, values, options.transaction); | ||
result = await this.query(sql, values, { transaction: options.transaction }); | ||
} | ||
@@ -305,3 +305,3 @@ catch (error) { | ||
try { | ||
await this.query(sql, values, options.transaction); | ||
await this.query(sql, values, { transaction: options.transaction }); | ||
} | ||
@@ -328,3 +328,3 @@ catch (error) { | ||
try { | ||
result = await this.query(sql, values, options.transaction); | ||
result = await this.query(sql, values, { transaction: options.transaction }); | ||
} | ||
@@ -381,7 +381,7 @@ catch (error) { | ||
if (options.explain) { | ||
return await this.query(`EXPLAIN ${sql}`, id, options.transaction); | ||
return await this.query(`EXPLAIN ${sql}`, id, { transaction: options.transaction, node: options.node }); | ||
} | ||
let result; | ||
try { | ||
result = await this.query(sql, id, options.transaction); | ||
result = await this.query(sql, id, { transaction: options.transaction, node: options.node }); | ||
} | ||
@@ -405,7 +405,7 @@ catch (error) { | ||
if (options.explain) { | ||
return await this.query(`EXPLAIN ${sql}`, params, options.transaction); | ||
return await this.query(`EXPLAIN ${sql}`, params, { transaction: options.transaction, node: options.node }); | ||
} | ||
let result; | ||
try { | ||
result = await this.query(sql, params, options.transaction); | ||
result = await this.query(sql, params, { transaction: options.transaction, node: options.node }); | ||
} | ||
@@ -467,3 +467,3 @@ catch (error) { | ||
try { | ||
result = await this.query(sql, params, options.transaction); | ||
result = await this.query(sql, params, { transaction: options.transaction, node: options.node }); | ||
} | ||
@@ -488,3 +488,3 @@ catch (error) { | ||
try { | ||
result = await this.query(sql, params, options.transaction); | ||
result = await this.query(sql, params, { transaction: options.transaction }); | ||
} | ||
@@ -612,3 +612,4 @@ catch (error) { | ||
*/ | ||
async query(text, values, transaction) { | ||
async query(text, values, options) { | ||
const transaction = options && options.transaction; | ||
if (transaction && transaction._adapter_connection) { | ||
@@ -621,3 +622,4 @@ this._connection._logger.logQuery(text, values); | ||
let client = this._client; | ||
if (this._read_clients.length > 0 && text.substring(0, 6).toUpperCase() === 'SELECT') { | ||
if (options && options.node === 'read' && this._read_clients.length > 0 | ||
&& text.substring(0, 6).toUpperCase() === 'SELECT') { | ||
this._read_client_index++; | ||
@@ -624,0 +626,0 @@ if (this._read_client_index >= this._read_clients.length || this._read_client_index < 0) { |
@@ -25,2 +25,3 @@ /// <reference types="node" /> | ||
transaction?: Transaction; | ||
node?: 'master' | 'read'; | ||
} | ||
@@ -53,2 +54,3 @@ export interface IQuerySingle<M extends BaseModel, T = M> extends PromiseLike<T> { | ||
transaction(transaction?: Transaction): IQuerySingle<M, T>; | ||
using(node: 'master' | 'read'): IQuerySingle<M, T>; | ||
exec(options?: { | ||
@@ -90,2 +92,3 @@ skip_log?: boolean; | ||
transaction(transaction?: Transaction): IQueryArray<M, T>; | ||
using(node: 'master' | 'read'): IQueryArray<M, T>; | ||
exec(options?: { | ||
@@ -198,2 +201,3 @@ skip_log?: boolean; | ||
transaction(transaction?: Transaction): this; | ||
using(node: 'master' | 'read'): this; | ||
/** | ||
@@ -200,0 +204,0 @@ * Executes the query |
@@ -28,2 +28,3 @@ "use strict"; | ||
lean: model.lean_query, | ||
node: 'master', | ||
select_single: false, | ||
@@ -229,2 +230,6 @@ }; | ||
} | ||
using(node) { | ||
this._options.node = node; | ||
return this; | ||
} | ||
/** | ||
@@ -465,3 +470,3 @@ * Executes the query | ||
} | ||
return Object.assign({ conditions_of_group: this._options.conditions_of_group, explain: this._options.explain, group_by, group_fields: this._options.group_fields, lean: this._options.lean, limit: this._options.limit, near: this._options.near, orders, skip: this._options.skip, transaction: this._options.transaction }, (select_raw.length > 0 && { select, select_raw })); | ||
return Object.assign({ conditions_of_group: this._options.conditions_of_group, explain: this._options.explain, group_by, group_fields: this._options.group_fields, lean: this._options.lean, limit: this._options.limit, near: this._options.near, node: this._options.node, orders, skip: this._options.skip, transaction: this._options.transaction }, (select_raw.length > 0 && { select, select_raw })); | ||
} | ||
@@ -468,0 +473,0 @@ async _execAndInclude(options) { |
{ | ||
"name": "cormo", | ||
"description": "ORM framework for Node.js", | ||
"version": "0.12.4", | ||
"version": "0.12.5", | ||
"keywords": [ | ||
@@ -69,3 +69,3 @@ "orm", | ||
}, | ||
"gitHead": "33195a08f4524ca49494a956f84b4bae14e53c03" | ||
"gitHead": "21e07b418b02f4e05b07480a5513f5a6a5335a51" | ||
} |
315050
8600