Compare commits
No commits in common. "24cdcd5c3926ca7c954ecc5ea2684d3a0db35809" and "c532ebcbb766796e6fe07552dc77502cfa4a6524" have entirely different histories.
24cdcd5c39
...
c532ebcbb7
5 changed files with 13 additions and 65 deletions
|
@ -4,7 +4,6 @@ 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"
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,8 +28,8 @@ export class DB {
|
||||||
|
|
||||||
this.name = database;
|
this.name = database;
|
||||||
}
|
}
|
||||||
async query(query: Query, printQuery = false) {
|
async query(query: Query) {
|
||||||
if(printQuery)console.log(query);
|
console.log(query);
|
||||||
if (this.type == dbType.mariadb) return await this.mariaPool.query(query);
|
if (this.type == dbType.mariadb) return await this.mariaPool.query(query);
|
||||||
/*else if (this.type == dbType.postgres) {
|
/*else if (this.type == dbType.postgres) {
|
||||||
let res = await this.pgPool.query(query.sql, query.values);
|
let res = await this.pgPool.query(query.sql, query.values);
|
||||||
|
@ -164,4 +163,3 @@ 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, insertResponse, readResponse, Table, writeResponse } from "./db"
|
import { Attribute, DB, Table } 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,12 +570,6 @@ 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) + ")" }]),
|
||||||
|
@ -714,23 +708,6 @@ export class Handler {
|
||||||
}
|
}
|
||||||
return builder;
|
return builder;
|
||||||
},
|
},
|
||||||
regexp: (handler: Handler, a: allModifierInput[]): QueryBuilder => {
|
|
||||||
const builder = new QueryBuilder();
|
|
||||||
if (a[0] instanceof Attribute || a[0] instanceof AttributeAlias) builder.addCode(a[0].toString());
|
|
||||||
else if (a[0] instanceof Modifier || a[0] instanceof selectQuery || a[0] instanceof Aggregation) {
|
|
||||||
builder.append(a[0].serialize(handler));
|
|
||||||
} else {
|
|
||||||
builder.addInjection(a[0]);
|
|
||||||
}
|
|
||||||
builder.addCode(" REGEXP ");
|
|
||||||
if (a[1] instanceof Attribute || a[1] instanceof AttributeAlias) builder.addCode(a[1].toString());
|
|
||||||
else if (a[1] instanceof Modifier || a[1] instanceof selectQuery || a[1] instanceof Aggregation) {
|
|
||||||
builder.append(a[1].serialize(handler));
|
|
||||||
} else {
|
|
||||||
builder.addInjection(a[1]);
|
|
||||||
}
|
|
||||||
return builder;
|
|
||||||
},
|
|
||||||
concat: (handler: Handler, a: allModifierInput[]): QueryBuilder => {
|
concat: (handler: Handler, a: allModifierInput[]): QueryBuilder => {
|
||||||
const builder = new QueryBuilder();
|
const builder = new QueryBuilder();
|
||||||
builder.addCode("CONCAT(");
|
builder.addCode("CONCAT(");
|
||||||
|
|
|
@ -18,7 +18,6 @@ export const divide = (...args: allModifierInput[]) => new NumberModifier("divid
|
||||||
|
|
||||||
export const not = (arg: allModifierInput) => new BooleanModifier("not", [arg]);
|
export const not = (arg: allModifierInput) => new BooleanModifier("not", [arg]);
|
||||||
export const like = (a: allModifierInput, b: allModifierInput) => new BooleanModifier("like", [a, b]);
|
export const like = (a: allModifierInput, b: allModifierInput) => new BooleanModifier("like", [a, b]);
|
||||||
export const regexp = (a: allModifierInput, b: allModifierInput) => new BooleanModifier("regexp", [a, b]);
|
|
||||||
|
|
||||||
export const concat = (...args: allModifierInput[]) => new StringModifier("concat", args);
|
export const concat = (...args: allModifierInput[]) => new StringModifier("concat", args);
|
||||||
|
|
||||||
|
|
22
src/query.ts
22
src/query.ts
|
@ -49,7 +49,7 @@ export class QueryBuilder {
|
||||||
this.list.push(...qb.list);
|
this.list.push(...qb.list);
|
||||||
}
|
}
|
||||||
appendEnding(qb: QueryBuilder) {
|
appendEnding(qb: QueryBuilder) {
|
||||||
if (qb.isEmpty()) return;
|
if(qb.isEmpty()) return;
|
||||||
this.append(qb);
|
this.append(qb);
|
||||||
this.list.push([false, ";"]);
|
this.list.push([false, ";"]);
|
||||||
}
|
}
|
||||||
|
@ -96,12 +96,11 @@ export class selectQuery {
|
||||||
return handler.querys.select(handler, this);
|
return handler.querys.select(handler, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
async query(db: DB, printQuery = false) {
|
async query(db: DB) {
|
||||||
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);
|
||||||
let readResp = await db.query(s, printQuery);
|
return await db.query(s);
|
||||||
return db.getHandler().responses.readResponse(readResp);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,12 +133,11 @@ export class insertQuery {
|
||||||
serialize(handler: Handler): QueryBuilder {
|
serialize(handler: Handler): QueryBuilder {
|
||||||
return handler.querys.insert(handler, this);
|
return handler.querys.insert(handler, this);
|
||||||
}
|
}
|
||||||
async query(db: DB, printQuery = false) {
|
async query(db: DB) {
|
||||||
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);
|
||||||
let readResp = await db.query(s, printQuery);
|
return await db.query(s);
|
||||||
return db.getHandler().responses.insertResponse(readResp);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,12 +161,11 @@ export class updateQuery {
|
||||||
serialize(handler: Handler): QueryBuilder {
|
serialize(handler: Handler): QueryBuilder {
|
||||||
return handler.querys.update(handler, this);
|
return handler.querys.update(handler, this);
|
||||||
}
|
}
|
||||||
async query(db: DB, printQuery = false) {
|
async query(db: DB) {
|
||||||
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);
|
||||||
let readResp = await db.query(s, printQuery);
|
return await db.query(s);
|
||||||
return db.getHandler().responses.writeResponse(readResp);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,11 +182,10 @@ export class removeQuery {
|
||||||
serialize(handler: Handler): QueryBuilder {
|
serialize(handler: Handler): QueryBuilder {
|
||||||
return handler.querys.remove(handler, this);
|
return handler.querys.remove(handler, this);
|
||||||
}
|
}
|
||||||
async query(db: DB, printQuery = false) {
|
async query(db: DB) {
|
||||||
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);
|
||||||
let readResp = await db.query(s, printQuery);
|
return await db.query(s);
|
||||||
return db.getHandler().responses.writeResponse(readResp);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,22 +0,0 @@
|
||||||
|
|
||||||
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