Updates
This commit is contained in:
+1
-1
@@ -1,7 +1,7 @@
|
||||
type Params = {
|
||||
sql: string;
|
||||
table: string;
|
||||
data: any[];
|
||||
data: any | any[];
|
||||
};
|
||||
export default function ({ sql: passed_sql, table, data }: Params): Promise<string>;
|
||||
export {};
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ export default async function ({ sql: passed_sql, table, data }) {
|
||||
const table_schema = dbSchema.tables.find((t) => t.tableName == table);
|
||||
const now = Date.now();
|
||||
if (table_schema?.tableName) {
|
||||
const set_sql_arr = Object.keys(data[0]).map((field) => `${field} = excluded.${field}`);
|
||||
const set_sql_arr = Object.keys(Array.isArray(data) ? data[0] : data).map((field) => `${field} = excluded.${field}`);
|
||||
set_sql_arr.push(`updated_at = ${now}`);
|
||||
const set_sql = set_sql_arr.join(", ");
|
||||
const unique_fields = table_schema.fields.filter((f) => f.unique);
|
||||
|
||||
Vendored
+1
@@ -21,6 +21,7 @@ export default async function DbDelete({ table, query, targetId, }) {
|
||||
const whereClause = sqlObj.string.match(/WHERE .*/)?.[0];
|
||||
if (whereClause) {
|
||||
let sql = `DELETE FROM ${table} ${whereClause}`;
|
||||
sqlObj.string = sql;
|
||||
const res = DbClient.run(sql, sqlObj.values);
|
||||
return {
|
||||
success: Boolean(res.changes),
|
||||
|
||||
Vendored
+3
@@ -308,6 +308,9 @@ class SQLiteSchemaManager {
|
||||
if (field.unique && !field.primaryKey) {
|
||||
parts.push("UNIQUE");
|
||||
}
|
||||
if (field.vectorDistanceMetric) {
|
||||
parts.push(`distance_metric=${field.vectorDistanceMetric}`);
|
||||
}
|
||||
// Default value
|
||||
if (field.defaultValue !== undefined) {
|
||||
if (typeof field.defaultValue === "string") {
|
||||
|
||||
Vendored
+5
-4
@@ -2,9 +2,10 @@ import DbClient from ".";
|
||||
import _ from "lodash";
|
||||
export default async function DbSQL({ sql, values }) {
|
||||
try {
|
||||
const res = sql.match(/^select/i)
|
||||
? DbClient.query(sql).all(...(values || []))
|
||||
: DbClient.run(sql, values || []);
|
||||
const trimmed_sql = sql.trim();
|
||||
const res = trimmed_sql.match(/^select/i)
|
||||
? DbClient.query(trimmed_sql).all(...(values || []))
|
||||
: DbClient.run(trimmed_sql, values || []);
|
||||
return {
|
||||
success: true,
|
||||
payload: Array.isArray(res) ? res : undefined,
|
||||
@@ -17,7 +18,7 @@ export default async function DbSQL({ sql, values }) {
|
||||
},
|
||||
debug: {
|
||||
sqlObj: {
|
||||
sql,
|
||||
sql: trimmed_sql,
|
||||
values,
|
||||
},
|
||||
sql,
|
||||
|
||||
Reference in New Issue
Block a user