responses #8
4 changed files with 40 additions and 6 deletions
|
@ -4,6 +4,7 @@ import { Handler } from './defaultHandler';
|
||||||
import { Query } from './query';
|
import { Query } from './query';
|
||||||
import { attributeSettings, extendedAttributeSettings, onAction, dbType } from './types';
|
import { attributeSettings, extendedAttributeSettings, onAction, dbType } from './types';
|
||||||
import { TableAlias } from "./alias"
|
import { TableAlias } from "./alias"
|
||||||
|
import { insertResponse, readResponse, writeResponse } from "./responses"
|
||||||
//import { postgresHandler } from "./postgresHandler"
|
//import { postgresHandler } from "./postgresHandler"
|
||||||
|
|
||||||
|
|
||||||
|
@ -162,4 +163,5 @@ export class Table {
|
||||||
|
|
||||||
export * from './funcs';
|
export * from './funcs';
|
||||||
export { onAction };
|
export { onAction };
|
||||||
export { dbType as databaseType }
|
export { dbType as databaseType }
|
||||||
|
export { readResponse, writeResponse, insertResponse }
|
|
@ -1,5 +1,5 @@
|
||||||
import { AttributeAlias, TableAlias } from "./alias";
|
import { AttributeAlias, TableAlias } from "./alias";
|
||||||
import { Attribute, DB, Table } from "./db"
|
import { Attribute, DB, insertResponse, readResponse, Table, writeResponse } from "./db"
|
||||||
import { Aggregation, checkConstraint, joinCross, Datatype, foreignConstraint, Modifier, joinNatural, onJoin, uniqueConstraint, usingJoin } from "./dbStructure"
|
import { Aggregation, checkConstraint, joinCross, Datatype, foreignConstraint, Modifier, joinNatural, onJoin, uniqueConstraint, usingJoin } from "./dbStructure"
|
||||||
import { insertQuery, Query, QueryBuilder, removeQuery, selectQuery, updateQuery } from "./query"
|
import { insertQuery, Query, QueryBuilder, removeQuery, selectQuery, updateQuery } from "./query"
|
||||||
import { allModifierInput, joinType, onAction, primaryData } from "./types"
|
import { allModifierInput, joinType, onAction, primaryData } from "./types"
|
||||||
|
@ -570,6 +570,12 @@ export class Handler {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
responses = {
|
||||||
|
readResponse: (resp: any) => new readResponse(resp),
|
||||||
|
writeResponse: (resp: any) => new writeResponse(resp.affectedRows),
|
||||||
|
insertResponse: (resp: any) => new insertResponse(resp.affectedRows, resp.insertId),
|
||||||
|
}
|
||||||
|
|
||||||
aggregations = {
|
aggregations = {
|
||||||
count: (handler: Handler, a: Attribute): QueryBuilder => new QueryBuilder([{ data: "count(" + a.toString(handler) + ")" }]),
|
count: (handler: Handler, a: Attribute): QueryBuilder => new QueryBuilder([{ data: "count(" + a.toString(handler) + ")" }]),
|
||||||
sum: (handler: Handler, a: Attribute): QueryBuilder => new QueryBuilder([{ data: "sum(" + a.toString(handler) + ")" }]),
|
sum: (handler: Handler, a: Attribute): QueryBuilder => new QueryBuilder([{ data: "sum(" + a.toString(handler) + ")" }]),
|
||||||
|
|
12
src/query.ts
12
src/query.ts
|
@ -100,7 +100,8 @@ export class selectQuery {
|
||||||
const handler = db.getHandler();
|
const handler = db.getHandler();
|
||||||
const builder = this.serialize(handler);
|
const builder = this.serialize(handler);
|
||||||
const s = handler.builders.query(builder);
|
const s = handler.builders.query(builder);
|
||||||
return await db.query(s);
|
let readResp = await db.query(s);
|
||||||
|
return db.getHandler().responses.readResponse(readResp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +138,8 @@ export class insertQuery {
|
||||||
const handler = db.getHandler();
|
const handler = db.getHandler();
|
||||||
const builder = this.serialize(handler);
|
const builder = this.serialize(handler);
|
||||||
const s = handler.builders.query(builder);
|
const s = handler.builders.query(builder);
|
||||||
return await db.query(s);
|
let readResp = await db.query(s);
|
||||||
|
return db.getHandler().responses.insertResponse(readResp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +167,8 @@ export class updateQuery {
|
||||||
const handler = db.getHandler();
|
const handler = db.getHandler();
|
||||||
const builder = this.serialize(handler);
|
const builder = this.serialize(handler);
|
||||||
const s = handler.builders.query(builder);
|
const s = handler.builders.query(builder);
|
||||||
return await db.query(s);
|
let readResp = await db.query(s);
|
||||||
|
return db.getHandler().responses.writeResponse(readResp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,6 +189,7 @@ export class removeQuery {
|
||||||
const handler = db.getHandler();
|
const handler = db.getHandler();
|
||||||
const builder = this.serialize(handler);
|
const builder = this.serialize(handler);
|
||||||
const s = handler.builders.query(builder);
|
const s = handler.builders.query(builder);
|
||||||
return await db.query(s);
|
let readResp = await db.query(s);
|
||||||
|
return db.getHandler().responses.writeResponse(readResp);
|
||||||
}
|
}
|
||||||
}
|
}
|
22
src/responses.ts
Normal file
22
src/responses.ts
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
|
||||||
|
export class readResponse extends Array{
|
||||||
|
constructor(rows:({[key: string]:any})[]){
|
||||||
|
super();
|
||||||
|
this.push(...rows);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class writeResponse{
|
||||||
|
affectedRows: number;
|
||||||
|
constructor(affectedRows: number){
|
||||||
|
this.affectedRows = affectedRows;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class insertResponse extends writeResponse{
|
||||||
|
insertId: number;
|
||||||
|
constructor(affectedRows: number, insertId: number){
|
||||||
|
super(affectedRows);
|
||||||
|
this.insertId = insertId;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue