Skip to content

Commit

Permalink
Merge branch 'dep_bot_8090-97d08dfd' into 'master'
Browse files Browse the repository at this point in the history
Dependency_Bot: Auto-Update 1.0.0

See merge request grandlinex/bundle/bundle-sqlight!20
  • Loading branch information
Elschnagoo committed Jul 30, 2024
2 parents 97d08df + 894f480 commit 9b365d8
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 17 deletions.
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@grandlinex/bundle-sqlight",
"version": "0.32.1",
"version": "1.0.0",
"description": "",
"type": "module",
"exports": {
Expand Down Expand Up @@ -45,32 +45,32 @@
},
"license": "BSD-3-Clause",
"dependencies": {
"@grandlinex/core": "0.32.0",
"better-sqlite3": "10.0.0",
"@types/better-sqlite3": "7.6.10"
"@grandlinex/core": "1.0.0",
"better-sqlite3": "11.1.2",
"@types/better-sqlite3": "7.6.11"
},
"devDependencies": {
"@types/jest": "29.5.12",
"@types/node": "20.12.12",
"@typescript-eslint/eslint-plugin": "7.11.0",
"@typescript-eslint/parser": "7.11.0",
"@types/node": "22.0.0",
"@typescript-eslint/eslint-plugin": "7.18.0",
"@typescript-eslint/parser": "7.18.0",
"cross-env": "7.0.3",
"eslint": "8.57.0",
"eslint-config-airbnb": "19.0.4",
"eslint-config-airbnb-typescript": "18.0.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-jest": "28.5.0",
"eslint-plugin-jsx-a11y": "6.8.0",
"eslint-plugin-prettier": "5.1.3",
"eslint-plugin-jest": "28.6.0",
"eslint-plugin-jsx-a11y": "6.9.0",
"eslint-plugin-prettier": "5.2.1",
"jest": "29.7.0",
"jest-junit": "16.0.0",
"prettier": "3.2.5",
"ts-jest": "29.1.4",
"prettier": "3.3.3",
"ts-jest": "29.1.5",
"ts-loader": "9.5.1",
"ts-node": "10.9.2",
"typedoc": "0.25.13",
"typescript": "5.4.5"
"typedoc": "0.26.5",
"typescript": "5.5.4"
},
"repository": {
"type": "git",
Expand Down
54 changes: 51 additions & 3 deletions src/class/SQLCon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
ICoreKernelModule,
ICorePresenter,
IDataBase,
IEntity,
QueryInterface,
RawQuery,
} from '@grandlinex/core';
Expand Down Expand Up @@ -93,6 +94,24 @@ export default class SQLCon<
return result[0] !== null;
}

async updateBulkEntity<E extends IEntity>(
config: EntityConfig<E>,
e_id: string[],
entity: EUpDateProperties<E>,
): Promise<boolean> {
const [, values, params] = objToTable(entity, config, true);
const result = await this.execScripts([
{
exec: `UPDATE ${this.schemaName}.${config.className}
SET ${values.join(', ')}
WHERE e_id in (${e_id.map(() => '?').join(',')});`,
param: [...params, ...e_id],
},
]);

return result[0] !== null;
}

async getEntityById<E extends CoreEntity>(
config: EntityConfig<E>,
id: string,
Expand All @@ -110,6 +129,23 @@ export default class SQLCon<
return null;
}

async getEntityBulkById<E extends CoreEntity>(
config: EntityConfig<E>,
e_id: string[],
): Promise<E[]> {
const query = this.db?.prepare(
`SELECT *
FROM ${this.schemaName}.${config.className}
WHERE e_id in (${e_id.map(() => '?').join(',')});`,
);

const res = query?.all(e_id);
if (res) {
return tableToObj<E>(config, res);
}
return [];
}

async findEntity<E extends CoreEntity>(
config: EntityConfig<E>,
search: { [D in keyof E]?: E[D] | undefined },
Expand Down Expand Up @@ -140,6 +176,18 @@ export default class SQLCon<
return query?.run([id]).changes === 1;
}

async deleteEntityBulkById(
className: string,
e_id: string[],
): Promise<boolean> {
const query = this.db?.prepare(
`DELETE
FROM ${this.schemaName}.${className}
WHERE e_id in (${e_id.map(() => '?').join(',')});`,
);
return (query?.run([...e_id]).changes ?? 0) > 1;
}

async getEntityList<E extends CoreEntity>(
q: QueryInterface<E>,
): Promise<E[]> {
Expand All @@ -164,9 +212,9 @@ export default class SQLCon<
}
const query = this.db?.prepare(
`SELECT *
FROM ${this.schemaName}.${config.className}
${searchQ}
${orderByQ}
FROM ${this.schemaName}.${config.className}
${searchQ}
${orderByQ}
${range};`,
);

Expand Down

0 comments on commit 9b365d8

Please sign in to comment.