I have a contact form but want a blob type. When I try to insert into the database I get:
D1_type_error: Type object is not supported for value [object Object]
server/database/schema.ts:
import { sqliteTable, integer, blob } from "drizzle-orm/sqlite-core"
import type { TranslatedText } from "../utils/types"
export const products = sqliteTable("products", {
id: integer("id").primaryKey({autoIncrement: true}),
description: blob("description").$type<TranslatedText>()
})
server/utils/types.ts:
export type TranslatedText = {
en: string
fr: string
}
app/pages/test.vue:
<script setup lang="ts">
const newProduct: {
description: {
en: "Hello world",
fr: "Bonjour le monde"
}
}
const createdProduct = await $fetch("/api/test/product/edit", {
method: "POST",
body: newProduct
})
console.log(createdProduct);
</script>
/server/api/test/product/edit.post.ts:
export default eventHandler(async (event) => {
const obj = await readBody(event)
// const wrappedObj = [obj]
if (!obj.id || obj.id <= 0) {
// create new
try {
const result = await useDrizzle()
.insert(tables.products)
.values(obj)
return result
} catch (err) {
console.log("error :")
console.log(err)
}
}
// Edit existing product
// ...
})
Migrations are OK, table is created with the right type. Other inserts are working. I tried to wrap the object in an array but no luck.