Comparing version 0.0.3 to 0.0.4
{ | ||
"name": "js-jpa", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "jpa for node", | ||
@@ -5,0 +5,0 @@ "author": "stone", |
@@ -125,2 +125,10 @@ const ErrorUtils = require('./ErrorUtils') | ||
}, | ||
getCountBy (jpa, where, argumentsLength){ | ||
return async function (context, ...values) { | ||
if (argumentsLength !== values.length) { | ||
throw new Error('illegal arguments') | ||
} | ||
return await jpa.count(context, this.schema, where, values) | ||
} | ||
}, | ||
getAllBy (jpa, where, argumentsLength) { | ||
@@ -190,2 +198,6 @@ return async function (context, ...values) { | ||
} | ||
repository.count = async (context, specification) => { | ||
let where = specification ? this._criteriaBuilder.build(repository.schema, specification) : null | ||
return await this.count(context, repository.schema, where) | ||
} | ||
repository.getAll = async (context, specification, pageRequest) => { | ||
@@ -236,2 +248,7 @@ let where = specification ? this._criteriaBuilder.build(repository.schema, specification) : null | ||
async count (context, schema, where, values) { | ||
let result = await context.query(this._sqlGenerator.count(schema, where), values) | ||
return result[0].value | ||
} | ||
async select (context, schema, where, order, pageRequest, values) { | ||
@@ -238,0 +255,0 @@ return await context.query(this._sqlGenerator.select(schema, where, order, pageRequest), values) |
@@ -19,3 +19,3 @@ const mysql = require('mysql') | ||
this._pool.on('enqueue', () => { | ||
console.log('waiting for available connection slot') | ||
console.warn('waiting for available connection slot') | ||
this._recycleConnections() | ||
@@ -25,3 +25,2 @@ }) | ||
this._connections.delete(instance) | ||
console.log('mysql connection %d released. [%d]', instance.threadId, this._connections.size) | ||
}) | ||
@@ -43,3 +42,2 @@ } | ||
this._connections.set(instance, connection) | ||
console.info('get connection %d. [%d]', connection.id, this._connections.size) | ||
resolve(connection) | ||
@@ -60,3 +58,3 @@ } | ||
for (let table of tables) { | ||
descriptions[table] = (await connection.query('desc ' + table)).map(field => { | ||
descriptions[table] = (await connection.query('desc `' + table + '`')).map(field => { | ||
return {name: field.Field} | ||
@@ -63,0 +61,0 @@ }) |
@@ -0,1 +1,2 @@ | ||
const schemaUtil = require('../SchemaUtil') | ||
const SQLGenerator = require('../SQLGenerator') | ||
@@ -39,3 +40,3 @@ | ||
let fields = schema.fields.map((field, index) => Columns[field.type](field, index === 0, field.auto)) | ||
fields.push(`PRIMARY KEY (${schema.fields[0].name})`) | ||
fields.push(`PRIMARY KEY (\`${schema.fields[0].name}\`)`) | ||
return `CREATE TABLE \`${schema.name}\` (${fields.join(',')}) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8` | ||
@@ -87,2 +88,11 @@ } | ||
count (schema, where) { | ||
let primaryKey = schemaUtil.getPrimaryKey(schema) | ||
let sql = `SELECT COUNT(\`${primaryKey}\`) as value FROM \`${schema.name}\`` | ||
if (where) { | ||
sql += ' WHERE ' + where | ||
} | ||
return sql | ||
} | ||
select (schema, where, order, pageRequest) { | ||
@@ -89,0 +99,0 @@ let sql = `FROM \`${schema.name}\`` |
@@ -33,2 +33,6 @@ const ErrorUtils = require('./ErrorUtils') | ||
count (schema, where) { | ||
throw new Error(ErrorUtils.ERROR_METHOD_NOT_OVERRIDE) | ||
} | ||
select (schema, where, order, pageRequest) { | ||
@@ -35,0 +39,0 @@ throw new Error(ErrorUtils.ERROR_METHOD_NOT_OVERRIDE) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21085
661