This commit is contained in:
Benjamin Toby 2026-04-16 17:18:50 +01:00
parent 959465a006
commit b73309e9d5
5 changed files with 22 additions and 22 deletions

View File

@ -10,21 +10,20 @@ export default function generateTypeDefinition({ paradigm, table, query, typeDef
const fields = table.fields;
function typeMap(schemaType) {
if (schemaType.options && schemaType.options.length > 0) {
return schemaType.options
.map((opt) => schemaType.dataType?.match(/int/i) ||
typeof opt == "number"
let opts = schemaType.options.map((opt) => schemaType.dataType?.match(/int/i) || typeof opt == "number"
? `${opt}`
: `"${opt}"`)
.join(" | ");
: `"${opt}"`);
opts.push(`""`);
return opts.join(" | ");
}
if (schemaType.dataType?.match(/blob/i)) {
return "Float32Array<ArrayBuffer> | Buffer<ArrayBuffer>";
return `Float32Array<ArrayBuffer> | Buffer<ArrayBuffer> | null`;
}
if (schemaType.dataType?.match(/int|double|decimal|real/i)) {
return "number";
return `number | ""`;
}
if (schemaType.dataType?.match(/text|varchar|timestamp/i)) {
return "string";
return `string`;
}
if (schemaType.dataType?.match(/boolean/i)) {
return "0 | 1";

View File

@ -29,7 +29,7 @@ export default function sqlInsertGenerator({ tableName, data, dbFullName, }) {
? value
: null;
if (!finalValue) {
queryValues.push("");
queryValues.push(null);
return "?";
}
queryValues.push(finalValue);

View File

@ -1,6 +1,6 @@
{
"name": "@moduletrace/bun-sqlite",
"version": "1.0.40",
"version": "1.0.41",
"description": "SQLite manager for Bun",
"author": "Benjamin Toby",
"main": "dist/index.js",

View File

@ -36,26 +36,27 @@ export default function generateTypeDefinition({
function typeMap(schemaType: BUN_SQLITE_FieldSchemaType) {
if (schemaType.options && schemaType.options.length > 0) {
return schemaType.options
.map((opt) =>
schemaType.dataType?.match(/int/i) ||
typeof opt == "number"
? `${opt}`
: `"${opt}"`,
)
.join(" | ");
let opts = schemaType.options.map((opt) =>
schemaType.dataType?.match(/int/i) || typeof opt == "number"
? `${opt}`
: `"${opt}"`,
);
opts.push(`""`);
return opts.join(" | ");
}
if (schemaType.dataType?.match(/blob/i)) {
return "Float32Array<ArrayBuffer> | Buffer<ArrayBuffer>";
return `Float32Array<ArrayBuffer> | Buffer<ArrayBuffer> | null`;
}
if (schemaType.dataType?.match(/int|double|decimal|real/i)) {
return "number";
return `number | ""`;
}
if (schemaType.dataType?.match(/text|varchar|timestamp/i)) {
return "string";
return `string`;
}
if (schemaType.dataType?.match(/boolean/i)) {

View File

@ -47,7 +47,7 @@ export default function sqlInsertGenerator({
: null;
if (!finalValue) {
queryValues.push("");
queryValues.push(null);
return "?";
}