This commit is contained in:
2026-04-10 21:13:11 +01:00
parent 5799a2586e
commit e6af7de865
14 changed files with 176 additions and 65 deletions
+2 -1
View File
@@ -6,10 +6,11 @@ type Params<Schema extends {
}, Table extends string = string> = {
table: Table;
data: Schema[];
update_on_duplicate?: boolean;
};
export default function DbInsert<Schema extends {
[k: string]: any;
} = {
[k: string]: any;
}, Table extends string = string>({ table, data }: Params<Schema, Table>): Promise<APIResponseObject>;
}, Table extends string = string>({ table, data, update_on_duplicate, }: Params<Schema, Table>): Promise<APIResponseObject>;
export {};
+8 -2
View File
@@ -1,6 +1,7 @@
import DbClient from ".";
import sqlInsertGenerator from "../../utils/sql-insert-generator";
export default async function DbInsert({ table, data }) {
import grabDuplicateSafeInsertSql from "../grab-duplicate-safe-insert-sql";
export default async function DbInsert({ table, data, update_on_duplicate, }) {
let sqlObj = null;
try {
const finalData = data.map((d) => ({
@@ -13,7 +14,12 @@ export default async function DbInsert({ table, data }) {
tableName: table,
data: finalData,
}) || null;
const res = DbClient.run(sqlObj?.query || "", sqlObj?.values || []);
let sql = sqlObj?.query || "";
if (update_on_duplicate && data[0]) {
sql = await grabDuplicateSafeInsertSql({ data, table, sql });
}
(sqlObj || {}).query = sql;
const res = DbClient.run(sql, sqlObj?.values || []);
return {
success: Boolean(Number(res.lastInsertRowid)),
postInsertReturn: {
+1 -6
View File
@@ -290,12 +290,7 @@ class SQLiteSchemaManager {
const parts = [fieldName];
// Data type mapping
const dataType = this.mapDataType(field);
if (dataType == "BLOB") {
parts.push("FLOAT[128]");
}
else {
parts.push(dataType);
}
parts.push(dataType);
// Primary key
if (field.primaryKey) {
parts.push("PRIMARY KEY");