xeon06
xeon06
Explore posts from servers
DTDrizzle Team
Created by xeon06 on 8/14/2024 in #help
D1 Blobs as ArrayBuffer?
Hey folks, I'm trying to store ArrayBuffers in D1 as Blobs. This Cloudflare page seems to indicate that D1 will automatically do the marshalling of blobs <> ArrayBuffers https://developers.cloudflare.com/d1/build-with-d1/d1-client-api/#type-conversion But I am just getting plain number arrays back unless I use a custom type:
export const arrayBuffer = (name: string) =>
customType<{ data: ArrayBuffer; driverData: number[] }>({
dataType: () => "blob",
toDriver: (value) => [...new Uint8Array(value)],
fromDriver: (value) => new Uint8Array([...value]).buffer,
})(name)
export const arrayBuffer = (name: string) =>
customType<{ data: ArrayBuffer; driverData: number[] }>({
dataType: () => "blob",
toDriver: (value) => [...new Uint8Array(value)],
fromDriver: (value) => new Uint8Array([...value]).buffer,
})(name)
It feels like doing this operation on every query will be slow, so I'm wondering if there's another way to get an ArrayBuffer out of this whole thing?
1 replies
DTDrizzle Team
Created by xeon06 on 1/12/2024 in #help
Update with inner join?
Hey folks, is it possible to do an update with an inner join in order to have more complicated filter logic, with values coming from other tables, for our where?
14 replies
DTDrizzle Team
Created by xeon06 on 1/9/2024 in #help
Shifted properties in join
I'm getting some very strange join behavior. This query:
const foreignExchangeTransactions = await db
.select()
.from(transactions)
.innerJoin(inboxes, eq(transactions.inboxId, inboxes.id))
const foreignExchangeTransactions = await db
.select()
.from(transactions)
.innerJoin(inboxes, eq(transactions.inboxId, inboxes.id))
Returns a proper transaction, but the inboxes object is completely out of whack, missing some properties but also a lot of the properties are shifted:
inboxes: {
id: 'ayrmg4fy63',
createdAt: 'Budget',
cuid: 'CAD',
name: 'America/Toronto',
currencyCode: 1
}
inboxes: {
id: 'ayrmg4fy63',
createdAt: 'Budget',
cuid: 'CAD',
name: 'America/Toronto',
currencyCode: 1
}
It should be:
id: 1,
createdAt: '2024-01-09',
name: 'Budget',
cuid: 'ayrmg4fy63',
timezone: 'America/Toronto',
currencyCode: 'CAD'
id: 1,
createdAt: '2024-01-09',
name: 'Budget',
cuid: 'ayrmg4fy63',
timezone: 'America/Toronto',
currencyCode: 'CAD'
Tried with one other table and same result as well, weird shifted properties in the joiend table
2 replies
DTDrizzle Team
Created by xeon06 on 1/9/2024 in #help
Select fields with the same name in two different tables in a join
Is it possible to select two fields of the same name, but from a different table, as part of a join? e.g.
db
.select({
inboxCurrencyCode: inboxes.currencyCode,
cardCurrencyCode: cards.currencyCode,
})
.from(transactions)
.leftJoin(inboxes, eq(transactions.inboxId, inboxes.id))
.leftJoin(cards, eq(transactions.cardId, cards.id))
db
.select({
inboxCurrencyCode: inboxes.currencyCode,
cardCurrencyCode: cards.currencyCode,
})
.from(transactions)
.leftJoin(inboxes, eq(transactions.inboxId, inboxes.id))
.leftJoin(cards, eq(transactions.cardId, cards.id))
As-is, it only ever gives me one of two currencyCode fields, even if they are technically renamed by the partial select
2 replies
DTDrizzle Team
Created by xeon06 on 1/3/2024 in #help
String default for integer timestamps?
Hey folks, I'm using Drizzle with SQLite on CloudFlare D1. Using the following column schema:
createdAt: integer("created_at", { mode: "timestamp" }).default(sql`CURRENT_TIMESTAMP`),
createdAt: integer("created_at", { mode: "timestamp" }).default(sql`CURRENT_TIMESTAMP`),
From the D1 database viewer I am seeing that Drizzle creates values that look like this 2024-01-03 03:55:45, whereas values inserted via direct SQL are integers properly e.g. 1703894400. In addition, the string values show up as NULL in Drizzle Studio. Could I be doing something wrong or have I encountered a bug?
9 replies