Compare commits

..

No commits in common. "ea5954a9ff125b2011666cf0f7cf649cf9d75d0d" and "67b10d949ad2285ef2f359080050eac0c1c1b670" have entirely different histories.

11 changed files with 43 additions and 53 deletions

6
package-lock.json generated
View file

@ -1,12 +1,12 @@
{ {
"name": "dblang", "name": "dblang",
"version": "0.7.0", "version": "1.0.0",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "dblang", "name": "dblang",
"version": "0.7.0", "version": "1.0.0",
"license": "UNLICENSED", "license": "UNLICENSED",
"dependencies": { "dependencies": {
"mariadb": "^3.0.2", "mariadb": "^3.0.2",
@ -19,7 +19,7 @@
"typescript": "^4.9.4" "typescript": "^4.9.4"
}, },
"engines": { "engines": {
"node": ">= 16" "node": ">= 14"
} }
}, },
"node_modules/@esbuild/android-arm": { "node_modules/@esbuild/android-arm": {

View file

@ -1,10 +1,10 @@
{ {
"name": "dblang", "name": "dblang",
"version": "0.7.0", "version": "0.6.2",
"description": "", "description": "",
"main": "dist/db.js", "main": "dist/db.js",
"types": "dist/db.d.ts", "types": "dist/db.d.ts",
"type": "module", "type": "commonjs",
"directories": { "directories": {
"dist": "dist" "dist": "dist"
}, },
@ -22,7 +22,7 @@
"pg": "^8.9.0" "pg": "^8.9.0"
}, },
"engines": { "engines": {
"node": ">= 16" "node": ">= 14"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^18.11.18", "@types/node": "^18.11.18",

View file

@ -1,5 +1,5 @@
import { Attribute, DB, Table } from "./db.js" import { Attribute, DB, Table } from "./db"
import { Handler } from "./defaultHandler.js"; import { Handler } from "./defaultHandler";
export class AttributeAlias { export class AttributeAlias {
name: string; name: string;

View file

@ -1,17 +1,12 @@
import mariadb from 'mariadb'; import mariadb from 'mariadb';
import { checkConstraint, Constraint, Datatype, foreignConstraint, uniqueConstraint } from './dbStructure.js'; import { checkConstraint, Constraint, Datatype, foreignConstraint, uniqueConstraint } from './dbStructure';
import { Handler } from './defaultHandler.js'; import { Handler } from './defaultHandler';
import { Query } from './query.js'; import { Query } from './query';
import { attributeSettings, extendedAttributeSettings, onAction, dbType } from './types.js'; import { attributeSettings, extendedAttributeSettings, onAction, dbType } from './types';
import { TableAlias } from "./alias.js" import { TableAlias } from "./alias"
import { insertResponse, readResponse, writeResponse, singleResponse } from "./responses.js" import { insertResponse, readResponse, writeResponse, singleResponse } from "./responses"
//import { postgresHandler } from "./postgresHandler" //import { postgresHandler } from "./postgresHandler"
declare module "mariadb" {
interface Pool{
on(ev: 'error', callback: () => void): Pool;
}
}
export class DB { export class DB {
tables: Table[] = []; tables: Table[] = [];
@ -26,8 +21,6 @@ export class DB {
this.type = databaseType; this.type = databaseType;
if (databaseType == dbType.mariadb) { if (databaseType == dbType.mariadb) {
this.mariaPool = mariadb.createPool({ host, user, password, port, database, connectionLimit, multipleStatements: true }); this.mariaPool = mariadb.createPool({ host, user, password, port, database, connectionLimit, multipleStatements: true });
// catch errors
this.mariaPool.on("error",()=>{});
this.handler = new Handler(this); this.handler = new Handler(this);
} }
/*else if (databaseType == dbType.postgres) { /*else if (databaseType == dbType.postgres) {
@ -177,7 +170,7 @@ export class Table {
} }
} }
export * from './funcs.js'; export * from './funcs';
export { onAction }; export { onAction };
export { dbType as databaseType } export { dbType as databaseType }
export { readResponse, writeResponse, insertResponse, singleResponse } export { readResponse, writeResponse, insertResponse, singleResponse }

View file

@ -1,7 +1,7 @@
import { Attribute, Table } from "./db.js"; import { Attribute, Table } from "./db";
import { Handler } from "./defaultHandler.js"; import { Handler } from "./defaultHandler";
import { QueryBuilder } from "./query.js"; import { QueryBuilder } from "./query";
import { allModifierInput, joinElements, joinType, onAction, primaryData, serializeReturn } from "./types.js"; import { allModifierInput, joinElements, joinType, onAction, primaryData, serializeReturn } from "./types";
export class Datatype { export class Datatype {
type: string; type: string;

View file

@ -1,8 +1,8 @@
import { AttributeAlias, TableAlias } from "./alias.js"; import { AttributeAlias, TableAlias } from "./alias";
import { Attribute, DB, insertResponse, readResponse, Table, writeResponse } from "./db.js" import { Attribute, DB, insertResponse, readResponse, Table, writeResponse } from "./db"
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"
import { insertQuery, Query, QueryBuilder, removeQuery, selectQuery, updateQuery } from "./query.js" import { insertQuery, Query, QueryBuilder, removeQuery, selectQuery, updateQuery } from "./query"
import { allModifierInput, joinType, onAction, primaryData } from "./types.js" import { allModifierInput, joinType, onAction, primaryData } from "./types"
export class Handler { export class Handler {
db: DB; db: DB;

View file

@ -1,7 +1,7 @@
import { Attribute, Table } from "./db.js"; import { Attribute, Table } from "./db";
import { Aggregation, BooleanModifier, checkConstraint, Datatype, foreignConstraint, joinCross, joinNatural, usingJoin, onJoin, NumberModifier, StringModifier, uniqueConstraint } from "./dbStructure.js"; import { Aggregation, BooleanModifier, checkConstraint, Datatype, foreignConstraint, joinCross, joinNatural, usingJoin, onJoin, NumberModifier, StringModifier, uniqueConstraint } from "./dbStructure";
import { insertQuery, removeQuery, selectQuery, updateQuery } from "./query.js"; import { insertQuery, removeQuery, selectQuery, updateQuery } from "./query";
import { allModifierInput, joinType, selectElements, selectFromElements } from "./types.js"; import { allModifierInput, joinType, selectElements, selectFromElements } from "./types";
//modifiers //modifiers
export const and = (...args: BooleanModifier[]) => new BooleanModifier("and", args); export const and = (...args: BooleanModifier[]) => new BooleanModifier("and", args);

View file

@ -1,8 +1,8 @@
import { AttributeAlias } from "./alias.js"; import { AttributeAlias } from "./alias";
import { Attribute, DB, Table } from "./db.js"; import { Attribute, DB, Table } from "./db";
import { BooleanModifier, Modifier } from "./dbStructure.js"; import { BooleanModifier, Modifier } from "./dbStructure";
import { Handler } from "./defaultHandler.js"; import { Handler } from "./defaultHandler";
import { allModifierInput, primaryData, selectElements, selectFromElements, serializeReturn } from "./types.js"; import { allModifierInput, primaryData, selectElements, selectFromElements, serializeReturn } from "./types";
export class Query { export class Query {
@ -101,7 +101,7 @@ export class selectQuery {
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); let readResp = await db.query(s, printQuery);
return handler.responses.readResponse(readResp); return db.getHandler().responses.readResponse(readResp);
} }
} }

View file

@ -1,6 +1,6 @@
import { AttributeAlias } from "./alias.js"; import { AttributeAlias } from "./alias";
import { Attribute } from "./db.js"; import { Attribute } from "./db";
import { primaryData } from "./types.js"; import { primaryData } from "./types";
export class singleResponse { export class singleResponse {
[key: string]: primaryData | any; [key: string]: primaryData | any;
@ -15,9 +15,7 @@ export class singleResponse {
export class readResponse extends Array<singleResponse>{ export class readResponse extends Array<singleResponse>{
constructor(rows: ({ [key: string]: primaryData })[]) { constructor(rows: ({ [key: string]: primaryData })[]) {
super(); super();
for(let i = 0; i < rows.length; i++){ this.push(...rows.map(r => new singleResponse(r)));
this[i] = new singleResponse(rows[i])
}
} }
} }

View file

@ -1,7 +1,7 @@
import { AttributeAlias, TableAlias } from "./alias.js"; import { AttributeAlias, TableAlias } from "./alias";
import { Attribute, Table } from "./db.js"; import { Attribute, Table } from "./db";
import { Aggregation, BooleanModifier, Datatype, Joins, Modifier } from "./dbStructure.js"; import { Aggregation, BooleanModifier, Datatype, Joins, Modifier } from "./dbStructure";
import { QueryBuilder, selectQuery } from "./query.js"; import { QueryBuilder, selectQuery } from "./query";
export type primaryData = string | number | boolean | null; export type primaryData = string | number | boolean | null;
export type allModifierInput = primaryData | Modifier | selectQuery | Attribute | AttributeAlias | Aggregation; export type allModifierInput = primaryData | Modifier | selectQuery | Attribute | AttributeAlias | Aggregation;

View file

@ -1,7 +1,6 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "ES6", "module": "CommonJS",
"module": "ES6",
"lib": ["es6"], "lib": ["es6"],
"types": ["node"], "types": ["node"],
"declaration": true, "declaration": true,