Updates
This commit is contained in:
+3
@@ -28,6 +28,9 @@ export default function generateTypeDefinition({ paradigm, table, query, typeDef
|
||||
if (schemaType.dataType?.match(/boolean/i)) {
|
||||
return "0 | 1";
|
||||
}
|
||||
if (schemaType.dataType?.match(/vector/i) || schemaType.isVector) {
|
||||
return `string | number[] | Buffer<ArrayBufferLike> | Float32Array<ArrayBuffer>`;
|
||||
}
|
||||
return "string";
|
||||
}
|
||||
const typesArrayTypeScript = [];
|
||||
|
||||
Vendored
+1
-1
@@ -1302,7 +1302,7 @@ export interface SQLInsertGenReturn {
|
||||
/**
|
||||
* Values accepted by the SQL insert generator, including vector buffers.
|
||||
*/
|
||||
export type SQLInsertGenValueType = string | number | Float32Array<ArrayBuffer> | Buffer<ArrayBuffer> | null;
|
||||
export type SQLInsertGenValueType = string | number | Float32Array<ArrayBuffer> | Buffer<ArrayBuffer> | number[] | null;
|
||||
/**
|
||||
* Callback variant used when a generated insert value needs a custom
|
||||
* placeholder.
|
||||
|
||||
Vendored
+10
-4
@@ -23,14 +23,18 @@ export default function sqlInsertGenerator({ tableName, data, dbFullName, }) {
|
||||
queryBatches.push(`(${insertKeys
|
||||
.map((ky) => {
|
||||
const value = item[ky];
|
||||
const is_embedding = Array.isArray(value) &&
|
||||
typeof value[0] == "number";
|
||||
const finalValue = typeof value == "string" ||
|
||||
typeof value == "number"
|
||||
? value
|
||||
: typeof value == "function"
|
||||
? value().value
|
||||
: value
|
||||
? value
|
||||
: null;
|
||||
: is_embedding
|
||||
? JSON.stringify(value)
|
||||
: value
|
||||
? value
|
||||
: null;
|
||||
if (!finalValue && typeof value !== "number") {
|
||||
queryValues.push(null);
|
||||
return "?";
|
||||
@@ -38,7 +42,9 @@ export default function sqlInsertGenerator({ tableName, data, dbFullName, }) {
|
||||
queryValues.push(finalValue);
|
||||
const placeholder = typeof value == "function"
|
||||
? value().placeholder
|
||||
: "?";
|
||||
: is_embedding
|
||||
? "VEC_FromText(?)"
|
||||
: "?";
|
||||
return placeholder;
|
||||
})
|
||||
.filter((k) => Boolean(k))
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@moduletrace/bun-mariadb",
|
||||
"version": "1.0.19",
|
||||
"version": "1.0.20",
|
||||
"description": "Schema-driven MariaDB manager for Bun",
|
||||
"author": "Benjamin Toby",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -63,6 +63,10 @@ export default function generateTypeDefinition({
|
||||
return "0 | 1";
|
||||
}
|
||||
|
||||
if (schemaType.dataType?.match(/vector/i) || schemaType.isVector) {
|
||||
return `string | number[] | Buffer<ArrayBufferLike> | Float32Array<ArrayBuffer>`;
|
||||
}
|
||||
|
||||
return "string";
|
||||
}
|
||||
|
||||
|
||||
@@ -1479,6 +1479,7 @@ export type SQLInsertGenValueType =
|
||||
| number
|
||||
| Float32Array<ArrayBuffer>
|
||||
| Buffer<ArrayBuffer>
|
||||
| number[]
|
||||
| null;
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,15 +40,21 @@ export default function sqlInsertGenerator({
|
||||
.map((ky) => {
|
||||
const value = item[ky];
|
||||
|
||||
const is_embedding =
|
||||
Array.isArray(value) &&
|
||||
typeof value[0] == "number";
|
||||
|
||||
const finalValue =
|
||||
typeof value == "string" ||
|
||||
typeof value == "number"
|
||||
? value
|
||||
: typeof value == "function"
|
||||
? value().value
|
||||
: value
|
||||
? value
|
||||
: null;
|
||||
: is_embedding
|
||||
? JSON.stringify(value)
|
||||
: value
|
||||
? value
|
||||
: null;
|
||||
|
||||
if (!finalValue && typeof value !== "number") {
|
||||
queryValues.push(null);
|
||||
@@ -60,7 +66,9 @@ export default function sqlInsertGenerator({
|
||||
const placeholder =
|
||||
typeof value == "function"
|
||||
? value().placeholder
|
||||
: "?";
|
||||
: is_embedding
|
||||
? "VEC_FromText(?)"
|
||||
: "?";
|
||||
|
||||
return placeholder;
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user