Comparing version 0.0.9 to 0.0.10
declare interface IDataSource { | ||
initialize(config: Config): Promise<any>; | ||
createContext(): Promise<IContext>; | ||
registerRepository(context: IContext, repository: Repository): Promise<any>; | ||
createContext(): Promise<ISqlContext>; | ||
registerRepository(context: ISqlContext, repository: Repository): Promise<any>; | ||
} | ||
declare interface IContext { | ||
query(sql: string, values: Array<any> | void): Promise<any>; | ||
declare interface ISqlContext { | ||
query(sql: string, values?: Array<any>): Promise<any>; | ||
beginTransaction(): Promise<any>; | ||
@@ -16,9 +16,8 @@ commit(): Promise<any>; | ||
declare interface Api { | ||
insert(context: IContext, entity: any): void; | ||
update(context: IContext, entity: any): void; | ||
get(context: IContext, key: any): Promise<any>; | ||
delete(context: IContext, key: any): void; | ||
select(context: IContext, specification: Specification, pageRequest: PageRequest): Promise<any>; | ||
count(context: IContext, specification: Specification): Promise<number>; | ||
insert(context: ISqlContext, entity: any): void; | ||
update(context: ISqlContext, entity: any): void; | ||
get(context: ISqlContext, key: any): Promise<any>; | ||
delete(context: ISqlContext, key: any): void; | ||
select(context: ISqlContext, specification?: Specification, pageRequest?: PageRequest): Promise<any>; | ||
count(context: ISqlContext, specification?: Specification): Promise<number>; | ||
} | ||
@@ -31,3 +30,3 @@ | ||
size: number, | ||
orders: Array<PageOrder> | void | ||
orders?: Array<PageOrder> | ||
} | ||
@@ -34,0 +33,0 @@ |
// | ||
module.exports = class Context { | ||
module.exports = class Context { | ||
@@ -13,3 +13,3 @@ | ||
async query(sql , values ) { | ||
async query(sql , values ) { | ||
if (this._logger) { | ||
@@ -16,0 +16,0 @@ console.log(sql, values ? values : '') |
@@ -25,9 +25,9 @@ // | ||
async createContext() { | ||
async createContext() { | ||
return new Context(await this._driver.getConnection(), this._config.logger) | ||
} | ||
async registerRepository(context , repository ) { | ||
async registerRepository(context , repository ) { | ||
await this._jpaBuilder.build(context, repository) | ||
} | ||
} |
@@ -40,3 +40,3 @@ // | ||
getSelect(schema , where , pageRequest ) { | ||
getSelect(schema , where , pageRequest ) { | ||
let order = (pageRequest && pageRequest.orders) ? this.getOrders(pageRequest.orders) : false | ||
@@ -43,0 +43,0 @@ let sql = `FROM \`${schema.name}\`` |
@@ -31,3 +31,3 @@ // | ||
async prepare(context , schema ) { | ||
async prepare(context , schema ) { | ||
let originSchema = this._tables.get(schema.name) | ||
@@ -42,3 +42,3 @@ if (originSchema) { | ||
async executeInsert(context , schema , entity ) { | ||
async executeInsert(context , schema , entity ) { | ||
let result = await super.executeInsert(context, schema, entity) | ||
@@ -45,0 +45,0 @@ SchemaUtil.setPrimaryValue(schema, entity, result.insertId) |
@@ -6,7 +6,7 @@ // | ||
getOneBy(jpa , where , argumentsLength ) { | ||
return async function (context , ...values ) { | ||
return async function (context , ...values ) { | ||
if (argumentsLength !== values.length) { | ||
throw new Error('illegal arguments') | ||
} | ||
let list = await jpa.executeSelect(context, this.schema, where, null, values) | ||
let list = await jpa.executeSelect(context, this.schema, where, undefined, values) | ||
return list.length > 0 ? list[0] : null | ||
@@ -16,3 +16,3 @@ } | ||
getCountBy(jpa , where , argumentsLength ) { | ||
return async function (context , ...values ) { | ||
return async function (context , ...values ) { | ||
if (argumentsLength !== values.length) { | ||
@@ -25,7 +25,7 @@ throw new Error('illegal arguments') | ||
getAllBy(jpa , where , argumentsLength ) { | ||
return async function (context , ...values ) { | ||
return async function (context , ...values ) { | ||
if (argumentsLength !== values.length && argumentsLength !== values.length - 1) { | ||
throw new Error('illegal arguments') | ||
} | ||
let pageRequest = argumentsLength < values.length ? values.pop() : null | ||
let pageRequest = argumentsLength < values.length ? values.pop() : undefined | ||
return await jpa.executeSelect(context, this.schema, where, pageRequest, values) | ||
@@ -35,3 +35,3 @@ } | ||
deleteBy(jpa , where , argumentsLength ) { | ||
return async function (context , ...values ) { | ||
return async function (context , ...values ) { | ||
if (argumentsLength !== values.length) { | ||
@@ -44,3 +44,3 @@ throw new Error('illegal arguments') | ||
exec(sql ) { | ||
return async function (context , values ) { | ||
return async function (context , values ) { | ||
return await context.query(sql, values) | ||
@@ -47,0 +47,0 @@ } |
@@ -30,7 +30,7 @@ // | ||
prepare(context , schema ) { | ||
prepare(context , schema ) { | ||
throw new Error(Constants.ERROR_METHOD_NOT_OVERRIDE) | ||
} | ||
async build(context , repository ) { | ||
async build(context , repository ) { | ||
if (!repository.schema) { | ||
@@ -63,3 +63,3 @@ throw new Error('not found schema in repository') | ||
let values = [key] | ||
let list = await this.executeSelect(context, repository.schema, where, null, values) | ||
let list = await this.executeSelect(context, repository.schema, where, undefined, values) | ||
return list.length > 0 ? list[0] : null | ||
@@ -185,7 +185,7 @@ } | ||
async executeInsert(context , schema , entity ) { | ||
async executeInsert(context , schema , entity ) { | ||
return await context.query(this.generator.getInsert(schema, entity)) | ||
} | ||
async executeUpdate(context , schema , entity ) { | ||
async executeUpdate(context , schema , entity ) { | ||
let sql = this.generator.getUpdate(schema, entity) | ||
@@ -197,3 +197,3 @@ if (sql) { | ||
async executeCount(context , schema , where , values ) { | ||
async executeCount(context , schema , where , values ) { | ||
let result = await context.query(this.generator.getCount(schema, where), values) | ||
@@ -203,9 +203,9 @@ return result[0].value | ||
async executeSelect(context , schema , where , pageRequest , values ) { | ||
async executeSelect(context , schema , where , pageRequest , values ) { | ||
return await context.query(this.generator.getSelect(schema, where, pageRequest), values) | ||
} | ||
async executeDelete(context , schema , where , values ) { | ||
async executeDelete(context , schema , where , values ) { | ||
return await context.query(this.generator.getDelete(schema, where), values) | ||
} | ||
} |
@@ -38,3 +38,3 @@ // | ||
getUpdate(schema , entity ) { | ||
getUpdate(schema , entity ) { | ||
let settings = [] | ||
@@ -54,7 +54,11 @@ for (let i = 1; i < schema.fields.length; i++) { | ||
getDelete(schema , where ) { | ||
return `DELETE FROM \`${schema.name}\` WHERE ${where}` | ||
getDelete(schema , where ) { | ||
let sql = `DELETE FROM \`${schema.name}\`` | ||
if (where) { | ||
sql += ` WHERE ${where}` | ||
} | ||
return sql | ||
} | ||
getCount(schema , where ) { | ||
getCount(schema , where ) { | ||
let primaryKey = SchemaUtil.getPrimaryKey(schema) | ||
@@ -68,3 +72,3 @@ let sql = `SELECT COUNT(\`${primaryKey}\`) as value FROM \`${schema.name}\`` | ||
getSelect(schema , where , pageRequest ) { | ||
getSelect(schema , where , pageRequest ) { | ||
throw new Error(Constants.ERROR_METHOD_NOT_OVERRIDE) | ||
@@ -71,0 +75,0 @@ } |
{ | ||
"name": "js-jpa", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"description": "jpa for node", | ||
@@ -5,0 +5,0 @@ "author": "stone", |
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
26318
737