This commit is contained in:
2026-05-23 16:40:20 +01:00
parent 47f85d8343
commit bcdd1f4b7e
11 changed files with 35 additions and 14 deletions
+1 -1
View File
@@ -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
View File
@@ -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);
+1
View File
@@ -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),
+3
View File
@@ -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") {
+5 -4
View File
@@ -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,
+4
View File
@@ -210,6 +210,10 @@ WHERE embedding MATCH ? AND k = 1;
```
*/
sideCar?: boolean;
/**
* Eg. `cosine`
*/
vectorDistanceMetric?: string;
} & {
[key in (typeof TextFieldTypesArray)[number]["value"]]?: boolean;
};