Compare commits
No commits in common. "main" and "v0.9.3" have entirely different histories.
7 changed files with 15 additions and 72 deletions
4
package-lock.json
generated
4
package-lock.json
generated
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "dblang",
|
"name": "dblang",
|
||||||
"version": "0.9.6",
|
"version": "0.9.3",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "dblang",
|
"name": "dblang",
|
||||||
"version": "0.9.6",
|
"version": "0.9.3",
|
||||||
"license": "UNLICENSED",
|
"license": "UNLICENSED",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"mariadb": "^3.0.2",
|
"mariadb": "^3.0.2",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "dblang",
|
"name": "dblang",
|
||||||
"version": "0.9.6",
|
"version": "0.9.3",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "dist/db.js",
|
"main": "dist/db.js",
|
||||||
"types": "dist/db.d.ts",
|
"types": "dist/db.d.ts",
|
||||||
|
|
|
@ -2,7 +2,7 @@ import mariadb from 'mariadb';
|
||||||
import { checkConstraint, Constraint, Datatype, foreignConstraint, uniqueConstraint } from './dbStructure.js';
|
import { checkConstraint, Constraint, Datatype, foreignConstraint, uniqueConstraint } from './dbStructure.js';
|
||||||
import { Handler } from './defaultHandler.js';
|
import { Handler } from './defaultHandler.js';
|
||||||
import { Query } from './query.js';
|
import { Query } from './query.js';
|
||||||
import { attributeSettings, extendedAttributeSettings, onAction, dbType, order } from './types.js';
|
import { attributeSettings, extendedAttributeSettings, onAction, dbType } from './types.js';
|
||||||
import { TableAlias } from "./alias.js"
|
import { TableAlias } from "./alias.js"
|
||||||
import { insertResponse, readResponse, writeResponse, singleResponse } from "./responses.js"
|
import { insertResponse, readResponse, writeResponse, singleResponse } from "./responses.js"
|
||||||
//import { postgresHandler } from "./postgresHandler"
|
//import { postgresHandler } from "./postgresHandler"
|
||||||
|
@ -180,6 +180,6 @@ export class Table {
|
||||||
}
|
}
|
||||||
|
|
||||||
export * from './funcs.js';
|
export * from './funcs.js';
|
||||||
export { onAction, order };
|
export { onAction };
|
||||||
export { dbType as databaseType }
|
export { dbType as databaseType }
|
||||||
export { readResponse, writeResponse, insertResponse, singleResponse }
|
export { readResponse, writeResponse, insertResponse, singleResponse }
|
|
@ -2,7 +2,7 @@ import { Alias, AttributeAlias, TableAlias } from "./alias.js";
|
||||||
import { Attribute, DB, insertResponse, readResponse, Table, writeResponse } from "./db.js"
|
import { Attribute, DB, insertResponse, readResponse, Table, writeResponse } from "./db.js"
|
||||||
import { Aggregation, checkConstraint, joinCross, Datatype, foreignConstraint, Modifier, joinNatural, onJoin, uniqueConstraint, usingJoin } from "./dbStructure.js"
|
import { Aggregation, checkConstraint, joinCross, Datatype, foreignConstraint, Modifier, joinNatural, onJoin, uniqueConstraint, usingJoin } from "./dbStructure.js"
|
||||||
import { insertQuery, Query, QueryBuilder, removeQuery, selectQuery, updateQuery } from "./query.js"
|
import { insertQuery, Query, QueryBuilder, removeQuery, selectQuery, updateQuery } from "./query.js"
|
||||||
import { allModifierInput, joinType, onAction, order, primaryData } from "./types.js"
|
import { allModifierInput, joinType, onAction, primaryData } from "./types.js"
|
||||||
import { sha256 } from "./tools.js"
|
import { sha256 } from "./tools.js"
|
||||||
|
|
||||||
export class Handler {
|
export class Handler {
|
||||||
|
@ -121,7 +121,7 @@ export class Handler {
|
||||||
return found == fromAttrs.length && found == toAttrs.length;
|
return found == fromAttrs.length && found == toAttrs.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
function freeForUpdate(attr: string, table: string, start = false, pool = del) {
|
function freeForUpdate(attr: string, table: string, start = false) {
|
||||||
for (let i = 0; i < key.length; i++) {
|
for (let i = 0; i < key.length; i++) {
|
||||||
const k = key[i];
|
const k = key[i];
|
||||||
if (
|
if (
|
||||||
|
@ -130,7 +130,7 @@ export class Handler {
|
||||||
|| (start && (k.TABLE_NAME ?? k.table_name) == table
|
|| (start && (k.TABLE_NAME ?? k.table_name) == table
|
||||||
&& (k.COLUMN_NAME ?? k.column_name).toLowerCase() == attr.toLowerCase() && (k.REFERENCED_COLUMN_NAME ?? k.referenced_column_name) != null)
|
&& (k.COLUMN_NAME ?? k.column_name).toLowerCase() == attr.toLowerCase() && (k.REFERENCED_COLUMN_NAME ?? k.referenced_column_name) != null)
|
||||||
) {
|
) {
|
||||||
pool.appendEnding(handler.querys.removeForeignKey(handler, (k.TABLE_NAME ?? k.table_name), (k.CONSTRAINT_NAME ?? k.constraint_name)));
|
del.appendEnding(handler.querys.removeForeignKey(handler, (k.TABLE_NAME ?? k.table_name), (k.CONSTRAINT_NAME ?? k.constraint_name)));
|
||||||
key.splice(i--, 1);
|
key.splice(i--, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -195,13 +195,7 @@ export class Handler {
|
||||||
const a = table.dbLangTableAttributes[keys[j]];
|
const a = table.dbLangTableAttributes[keys[j]];
|
||||||
const attrData = tableD[keys[j]];
|
const attrData = tableD[keys[j]];
|
||||||
if (attrData == null) {
|
if (attrData == null) {
|
||||||
if (a.ops.autoIncrement) {
|
create.appendEnding(handler.querys.addColumn(handler, a));
|
||||||
a.ops.autoIncrement = false;
|
|
||||||
create.appendEnding(handler.querys.addColumn(handler, a));
|
|
||||||
a.ops.autoIncrement = true;
|
|
||||||
connst.appendEnding(handler.querys.addColumn(handler, a));
|
|
||||||
}
|
|
||||||
else create.appendEnding(handler.querys.addColumn(handler, a));
|
|
||||||
if (a.ops.primaryKey) changePrimary = true;
|
if (a.ops.primaryKey) changePrimary = true;
|
||||||
} else if (
|
} else if (
|
||||||
!handler.builders.compareDatatypes(handler, a.type, attrData.Type) ||
|
!handler.builders.compareDatatypes(handler, a.type, attrData.Type) ||
|
||||||
|
@ -209,6 +203,10 @@ export class Handler {
|
||||||
(!!a.ops.notNull || !!a.ops.autoIncrement || !!a.ops.primaryKey) != (attrData.Null == "NO") ||
|
(!!a.ops.notNull || !!a.ops.autoIncrement || !!a.ops.primaryKey) != (attrData.Null == "NO") ||
|
||||||
(!!a.ops.autoIncrement) != (attrData.Extra == "auto_increment")
|
(!!a.ops.autoIncrement) != (attrData.Extra == "auto_increment")
|
||||||
) {
|
) {
|
||||||
|
/*console.log(!handler.builders.compareDatatypes(handler, a.type, attrData.Type), "|",
|
||||||
|
a.ops.default, attrData.Default, "|",
|
||||||
|
(!!a.ops.notNull || !!a.ops.autoIncrement || !!a.ops.primaryKey), (attrData.Null == "NO"), "|",
|
||||||
|
(!!a.ops.autoIncrement), (attrData.Extra == "auto_increment"));*/
|
||||||
freeForUpdate(a.name, a.table.dbLangTableName);
|
freeForUpdate(a.name, a.table.dbLangTableName);
|
||||||
if (a.ops.autoIncrement) {
|
if (a.ops.autoIncrement) {
|
||||||
a.ops.autoIncrement = false;
|
a.ops.autoIncrement = false;
|
||||||
|
@ -233,7 +231,6 @@ export class Handler {
|
||||||
a.ops.autoIncrement = true;
|
a.ops.autoIncrement = true;
|
||||||
connst.appendEnding(handler.querys.changeColumn(handler, a));
|
connst.appendEnding(handler.querys.changeColumn(handler, a));
|
||||||
}
|
}
|
||||||
freeForUpdate(a.name, a.table.dbLangTableName, true, create);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (changePrimary) {
|
if (changePrimary) {
|
||||||
|
@ -307,25 +304,6 @@ export class Handler {
|
||||||
builder.append(q.havingD.serialize(handler));
|
builder.append(q.havingD.serialize(handler));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (q.orderByD.length > 0) {
|
|
||||||
builder.addCode(" order by ");
|
|
||||||
for (let i = 0; i < q.orderByD.length; i++) {
|
|
||||||
const d = q.orderByD[i];
|
|
||||||
if (d[0] instanceof Attribute || d[0] instanceof AttributeAlias) builder.addCode(d[0].getString(handler));
|
|
||||||
else if (d[0] instanceof Alias)
|
|
||||||
builder.addCode(handler.builders.escapeID(d.toString()));
|
|
||||||
else if (d[0] instanceof Modifier || d[0] instanceof selectQuery || d[0] instanceof Aggregation) {
|
|
||||||
builder.addCode("(");
|
|
||||||
builder.append(d[0].serialize(handler));
|
|
||||||
builder.addCode(")");
|
|
||||||
} else {
|
|
||||||
builder.addInjection(d[0]);
|
|
||||||
}
|
|
||||||
if(d[1] == order.DESC) builder.addCode(" DESC");
|
|
||||||
else builder.addCode(" ASC");
|
|
||||||
if (i + 1 < q.orderByD.length) builder.addCode(", ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (q.limitD != null) {
|
if (q.limitD != null) {
|
||||||
if (q.limitOffsetD == null) {
|
if (q.limitOffsetD == null) {
|
||||||
builder.addCode(" limit ");
|
builder.addCode(" limit ");
|
||||||
|
@ -847,25 +825,7 @@ export class Handler {
|
||||||
}
|
}
|
||||||
builder.addCode(")");
|
builder.addCode(")");
|
||||||
return builder;
|
return builder;
|
||||||
},
|
}
|
||||||
coalesce: (handler: Handler, a: allModifierInput[]): QueryBuilder => {
|
|
||||||
const builder = new QueryBuilder();
|
|
||||||
builder.addCode("COALESCE(");
|
|
||||||
for (let i = 0; i < a.length; i++) {
|
|
||||||
const e = a[i];
|
|
||||||
if (e instanceof Attribute || e instanceof AttributeAlias) builder.addCode(e.getString());
|
|
||||||
else if (e instanceof Alias)
|
|
||||||
builder.addCode(handler.builders.escapeID(e.toString()));
|
|
||||||
else if (e instanceof Modifier || e instanceof selectQuery || e instanceof Aggregation) {
|
|
||||||
builder.append(e.serialize(handler));
|
|
||||||
} else {
|
|
||||||
builder.addInjection(e);
|
|
||||||
}
|
|
||||||
if (i < a.length - 1) builder.addCode(", ");
|
|
||||||
}
|
|
||||||
builder.addCode(")");
|
|
||||||
return builder;
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
datatypes = {
|
datatypes = {
|
||||||
|
|
|
@ -24,7 +24,6 @@ export const regexp = (a: allModifierInput, b: allModifierInput) => new BooleanM
|
||||||
export const exists = (q: selectQuery) => new BooleanModifier("exists", [q]);
|
export const exists = (q: selectQuery) => new BooleanModifier("exists", [q]);
|
||||||
|
|
||||||
export const concat = (...args: allModifierInput[]) => new StringModifier("concat", args);
|
export const concat = (...args: allModifierInput[]) => new StringModifier("concat", args);
|
||||||
export const coalesce = (...args: allModifierInput[]) => new StringModifier("coalesce", args);
|
|
||||||
|
|
||||||
//aggregations
|
//aggregations
|
||||||
export const count = (a: Attribute) => new Aggregation("count", a);
|
export const count = (a: Attribute) => new Aggregation("count", a);
|
||||||
|
|
13
src/query.ts
13
src/query.ts
|
@ -2,7 +2,7 @@ import { AttributeAlias } from "./alias.js";
|
||||||
import { Attribute, DB, Table } from "./db.js";
|
import { Attribute, DB, Table } from "./db.js";
|
||||||
import { BooleanModifier, Modifier } from "./dbStructure.js";
|
import { BooleanModifier, Modifier } from "./dbStructure.js";
|
||||||
import { Handler } from "./defaultHandler.js";
|
import { Handler } from "./defaultHandler.js";
|
||||||
import { allModifierInput, order, primaryData, selectElements, selectFromElements, serializeReturn } from "./types.js";
|
import { allModifierInput, primaryData, selectElements, selectFromElements, serializeReturn } from "./types.js";
|
||||||
|
|
||||||
|
|
||||||
export class Query {
|
export class Query {
|
||||||
|
@ -84,17 +84,6 @@ export class selectQuery {
|
||||||
this.havingD = m;
|
this.havingD = m;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
orderByD: ([allModifierInput, order])[] = [];
|
|
||||||
addOrderBy(a: allModifierInput, o: order = order.ASC) {
|
|
||||||
this.orderByD.push([a, o]);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
orderBY(a: allModifierInput, o: order = order.ASC) {
|
|
||||||
this.orderByD = [[a, o]];
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
limitD: number | null = null;
|
limitD: number | null = null;
|
||||||
limitOffsetD: number | null = null;
|
limitOffsetD: number | null = null;
|
||||||
limit(i: number, offset: number = 0) {
|
limit(i: number, offset: number = 0) {
|
||||||
|
|
|
@ -64,8 +64,3 @@ export enum dbType {
|
||||||
//mysql,
|
//mysql,
|
||||||
postgres,
|
postgres,
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum order {
|
|
||||||
ASC,
|
|
||||||
DESC
|
|
||||||
}
|
|
Loading…
Reference in a new issue