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