Update CRUD functions type defs
This commit is contained in:
parent
83bc501bd1
commit
077a15ed71
12
dist/lib/sqlite/db-delete.d.ts
vendored
12
dist/lib/sqlite/db-delete.d.ts
vendored
@ -1,16 +1,16 @@
|
|||||||
import type { APIResponseObject, ServerQueryParam } from "../../types";
|
import type { APIResponseObject, ServerQueryParam } from "../../types";
|
||||||
type Params<T extends {
|
type Params<Schema extends {
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
} = {
|
} = {
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
}> = {
|
}, Table extends string = string> = {
|
||||||
table: string;
|
table: Table;
|
||||||
query?: ServerQueryParam<T>;
|
query?: ServerQueryParam<Schema>;
|
||||||
targetId?: number | string;
|
targetId?: number | string;
|
||||||
};
|
};
|
||||||
export default function DbDelete<T extends {
|
export default function DbDelete<Schema extends {
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
} = {
|
} = {
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
}>({ table, query, targetId }: Params<T>): Promise<APIResponseObject>;
|
}, Table extends string = string>({ table, query, targetId, }: Params<Schema, Table>): Promise<APIResponseObject>;
|
||||||
export {};
|
export {};
|
||||||
|
|||||||
2
dist/lib/sqlite/db-delete.js
vendored
2
dist/lib/sqlite/db-delete.js
vendored
@ -1,7 +1,7 @@
|
|||||||
import DbClient from ".";
|
import DbClient from ".";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import sqlGenerator from "../../utils/sql-generator";
|
import sqlGenerator from "../../utils/sql-generator";
|
||||||
export default async function DbDelete({ table, query, targetId }) {
|
export default async function DbDelete({ table, query, targetId, }) {
|
||||||
try {
|
try {
|
||||||
let finalQuery = query || {};
|
let finalQuery = query || {};
|
||||||
if (targetId) {
|
if (targetId) {
|
||||||
|
|||||||
12
dist/lib/sqlite/db-insert.d.ts
vendored
12
dist/lib/sqlite/db-insert.d.ts
vendored
@ -1,15 +1,15 @@
|
|||||||
import type { APIResponseObject } from "../../types";
|
import type { APIResponseObject } from "../../types";
|
||||||
type Params<T extends {
|
type Params<Schema extends {
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
} = {
|
} = {
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
}> = {
|
}, Table extends string = string> = {
|
||||||
table: string;
|
table: Table;
|
||||||
data: T[];
|
data: Schema[];
|
||||||
};
|
};
|
||||||
export default function DbInsert<T extends {
|
export default function DbInsert<Schema extends {
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
} = {
|
} = {
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
}>({ table, data }: Params<T>): Promise<APIResponseObject>;
|
}, Table extends string = string>({ table, data }: Params<Schema, Table>): Promise<APIResponseObject>;
|
||||||
export {};
|
export {};
|
||||||
|
|||||||
12
dist/lib/sqlite/db-select.d.ts
vendored
12
dist/lib/sqlite/db-select.d.ts
vendored
@ -1,17 +1,17 @@
|
|||||||
import type { APIResponseObject, ServerQueryParam } from "../../types";
|
import type { APIResponseObject, ServerQueryParam } from "../../types";
|
||||||
type Params<T extends {
|
type Params<Schema extends {
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
} = {
|
} = {
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
}> = {
|
}, Table extends string = string> = {
|
||||||
query?: ServerQueryParam<T>;
|
query?: ServerQueryParam<Schema>;
|
||||||
table: string;
|
table: Table;
|
||||||
count?: boolean;
|
count?: boolean;
|
||||||
targetId?: number | string;
|
targetId?: number | string;
|
||||||
};
|
};
|
||||||
export default function DbSelect<T extends {
|
export default function DbSelect<Schema extends {
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
} = {
|
} = {
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
}>({ table, query, count, targetId }: Params<T>): Promise<APIResponseObject<T>>;
|
}, Table extends string = string>({ table, query, count, targetId, }: Params<Schema, Table>): Promise<APIResponseObject<Schema>>;
|
||||||
export {};
|
export {};
|
||||||
|
|||||||
2
dist/lib/sqlite/db-select.js
vendored
2
dist/lib/sqlite/db-select.js
vendored
@ -2,7 +2,7 @@ import mysql from "mysql";
|
|||||||
import DbClient from ".";
|
import DbClient from ".";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import sqlGenerator from "../../utils/sql-generator";
|
import sqlGenerator from "../../utils/sql-generator";
|
||||||
export default async function DbSelect({ table, query, count, targetId }) {
|
export default async function DbSelect({ table, query, count, targetId, }) {
|
||||||
try {
|
try {
|
||||||
let finalQuery = query || {};
|
let finalQuery = query || {};
|
||||||
if (targetId) {
|
if (targetId) {
|
||||||
|
|||||||
14
dist/lib/sqlite/db-update.d.ts
vendored
14
dist/lib/sqlite/db-update.d.ts
vendored
@ -1,17 +1,17 @@
|
|||||||
import type { APIResponseObject, ServerQueryParam } from "../../types";
|
import type { APIResponseObject, ServerQueryParam } from "../../types";
|
||||||
type Params<T extends {
|
type Params<Schema extends {
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
} = {
|
} = {
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
}> = {
|
}, Table extends string = string> = {
|
||||||
table: string;
|
table: Table;
|
||||||
data: T;
|
data: Schema;
|
||||||
query?: ServerQueryParam<T>;
|
query?: ServerQueryParam<Schema>;
|
||||||
targetId?: number | string;
|
targetId?: number | string;
|
||||||
};
|
};
|
||||||
export default function DbUpdate<T extends {
|
export default function DbUpdate<Schema extends {
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
} = {
|
} = {
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
}>({ table, data, query, targetId }: Params<T>): Promise<APIResponseObject>;
|
}, Table extends string = string>({ table, data, query, targetId, }: Params<Schema, Table>): Promise<APIResponseObject>;
|
||||||
export {};
|
export {};
|
||||||
|
|||||||
2
dist/lib/sqlite/db-update.js
vendored
2
dist/lib/sqlite/db-update.js
vendored
@ -1,7 +1,7 @@
|
|||||||
import DbClient from ".";
|
import DbClient from ".";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import sqlGenerator from "../../utils/sql-generator";
|
import sqlGenerator from "../../utils/sql-generator";
|
||||||
export default async function DbUpdate({ table, data, query, targetId }) {
|
export default async function DbUpdate({ table, data, query, targetId, }) {
|
||||||
try {
|
try {
|
||||||
let finalQuery = query || {};
|
let finalQuery = query || {};
|
||||||
if (targetId) {
|
if (targetId) {
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/bun-sqlite",
|
"name": "@moduletrace/bun-sqlite",
|
||||||
"version": "1.0.4",
|
"version": "1.0.5",
|
||||||
"description": "SQLite manager for Bun",
|
"description": "SQLite manager for Bun",
|
||||||
"author": "Benjamin Toby",
|
"author": "Benjamin Toby",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
|||||||
@ -3,15 +3,23 @@ import _ from "lodash";
|
|||||||
import type { APIResponseObject, ServerQueryParam } from "../../types";
|
import type { APIResponseObject, ServerQueryParam } from "../../types";
|
||||||
import sqlGenerator from "../../utils/sql-generator";
|
import sqlGenerator from "../../utils/sql-generator";
|
||||||
|
|
||||||
type Params<T extends { [k: string]: any } = { [k: string]: any }> = {
|
type Params<
|
||||||
table: string;
|
Schema extends { [k: string]: any } = { [k: string]: any },
|
||||||
query?: ServerQueryParam<T>;
|
Table extends string = string,
|
||||||
|
> = {
|
||||||
|
table: Table;
|
||||||
|
query?: ServerQueryParam<Schema>;
|
||||||
targetId?: number | string;
|
targetId?: number | string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default async function DbDelete<
|
export default async function DbDelete<
|
||||||
T extends { [k: string]: any } = { [k: string]: any },
|
Schema extends { [k: string]: any } = { [k: string]: any },
|
||||||
>({ table, query, targetId }: Params<T>): Promise<APIResponseObject> {
|
Table extends string = string,
|
||||||
|
>({
|
||||||
|
table,
|
||||||
|
query,
|
||||||
|
targetId,
|
||||||
|
}: Params<Schema, Table>): Promise<APIResponseObject> {
|
||||||
try {
|
try {
|
||||||
let finalQuery = query || {};
|
let finalQuery = query || {};
|
||||||
|
|
||||||
|
|||||||
@ -2,14 +2,18 @@ import DbClient from ".";
|
|||||||
import type { APIResponseObject } from "../../types";
|
import type { APIResponseObject } from "../../types";
|
||||||
import sqlInsertGenerator from "../../utils/sql-insert-generator";
|
import sqlInsertGenerator from "../../utils/sql-insert-generator";
|
||||||
|
|
||||||
type Params<T extends { [k: string]: any } = { [k: string]: any }> = {
|
type Params<
|
||||||
table: string;
|
Schema extends { [k: string]: any } = { [k: string]: any },
|
||||||
data: T[];
|
Table extends string = string,
|
||||||
|
> = {
|
||||||
|
table: Table;
|
||||||
|
data: Schema[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export default async function DbInsert<
|
export default async function DbInsert<
|
||||||
T extends { [k: string]: any } = { [k: string]: any },
|
Schema extends { [k: string]: any } = { [k: string]: any },
|
||||||
>({ table, data }: Params<T>): Promise<APIResponseObject> {
|
Table extends string = string,
|
||||||
|
>({ table, data }: Params<Schema, Table>): Promise<APIResponseObject> {
|
||||||
try {
|
try {
|
||||||
const finalData: { [k: string]: any }[] = data.map((d) => ({
|
const finalData: { [k: string]: any }[] = data.map((d) => ({
|
||||||
...d,
|
...d,
|
||||||
|
|||||||
@ -4,16 +4,25 @@ import _ from "lodash";
|
|||||||
import type { APIResponseObject, ServerQueryParam } from "../../types";
|
import type { APIResponseObject, ServerQueryParam } from "../../types";
|
||||||
import sqlGenerator from "../../utils/sql-generator";
|
import sqlGenerator from "../../utils/sql-generator";
|
||||||
|
|
||||||
type Params<T extends { [k: string]: any } = { [k: string]: any }> = {
|
type Params<
|
||||||
query?: ServerQueryParam<T>;
|
Schema extends { [k: string]: any } = { [k: string]: any },
|
||||||
table: string;
|
Table extends string = string,
|
||||||
|
> = {
|
||||||
|
query?: ServerQueryParam<Schema>;
|
||||||
|
table: Table;
|
||||||
count?: boolean;
|
count?: boolean;
|
||||||
targetId?: number | string;
|
targetId?: number | string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default async function DbSelect<
|
export default async function DbSelect<
|
||||||
T extends { [k: string]: any } = { [k: string]: any },
|
Schema extends { [k: string]: any } = { [k: string]: any },
|
||||||
>({ table, query, count, targetId }: Params<T>): Promise<APIResponseObject<T>> {
|
Table extends string = string,
|
||||||
|
>({
|
||||||
|
table,
|
||||||
|
query,
|
||||||
|
count,
|
||||||
|
targetId,
|
||||||
|
}: Params<Schema, Table>): Promise<APIResponseObject<Schema>> {
|
||||||
try {
|
try {
|
||||||
let finalQuery = query || {};
|
let finalQuery = query || {};
|
||||||
|
|
||||||
@ -38,10 +47,10 @@ export default async function DbSelect<
|
|||||||
|
|
||||||
const sql = mysql.format(sqlObj.string, sqlObj.values);
|
const sql = mysql.format(sqlObj.string, sqlObj.values);
|
||||||
|
|
||||||
const res = DbClient.query<T, T[]>(sql);
|
const res = DbClient.query<Schema, Schema[]>(sql);
|
||||||
const batchRes = res.all();
|
const batchRes = res.all();
|
||||||
|
|
||||||
let resp: APIResponseObject<T> = {
|
let resp: APIResponseObject<Schema> = {
|
||||||
success: Boolean(batchRes[0]),
|
success: Boolean(batchRes[0]),
|
||||||
payload: batchRes,
|
payload: batchRes,
|
||||||
singleRes: batchRes[0],
|
singleRes: batchRes[0],
|
||||||
|
|||||||
@ -3,16 +3,25 @@ import _ from "lodash";
|
|||||||
import type { APIResponseObject, ServerQueryParam } from "../../types";
|
import type { APIResponseObject, ServerQueryParam } from "../../types";
|
||||||
import sqlGenerator from "../../utils/sql-generator";
|
import sqlGenerator from "../../utils/sql-generator";
|
||||||
|
|
||||||
type Params<T extends { [k: string]: any } = { [k: string]: any }> = {
|
type Params<
|
||||||
table: string;
|
Schema extends { [k: string]: any } = { [k: string]: any },
|
||||||
data: T;
|
Table extends string = string,
|
||||||
query?: ServerQueryParam<T>;
|
> = {
|
||||||
|
table: Table;
|
||||||
|
data: Schema;
|
||||||
|
query?: ServerQueryParam<Schema>;
|
||||||
targetId?: number | string;
|
targetId?: number | string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default async function DbUpdate<
|
export default async function DbUpdate<
|
||||||
T extends { [k: string]: any } = { [k: string]: any },
|
Schema extends { [k: string]: any } = { [k: string]: any },
|
||||||
>({ table, data, query, targetId }: Params<T>): Promise<APIResponseObject> {
|
Table extends string = string,
|
||||||
|
>({
|
||||||
|
table,
|
||||||
|
data,
|
||||||
|
query,
|
||||||
|
targetId,
|
||||||
|
}: Params<Schema, Table>): Promise<APIResponseObject> {
|
||||||
try {
|
try {
|
||||||
let finalQuery = query || {};
|
let finalQuery = query || {};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user