is there any guide to setup d1 with drizzle properly
is there any guide to setup d1 with drizzle properly

db.batch operation where a step requires the result of the previous one (the id of an inserted element)?
batch call are executed inside a single transaction: https://developers.cloudflare.com/d1/build-with-d1/d1-client-api/#batch-statementsBatched statements are SQL transactions. If a statement in the sequence fails, then an error is returned for that specific statement, and it aborts or rolls back the entire sequence.
googleUser.email and use that in your INSERT.batch(), but your second INSERT should do a nested SELECT to figure out the user ID that was added in the first insert.nanoid() into a local variable before you create your statements, and use that in both queries. Isn't that nanoid what you want in the second insert or is it an autoincrement key?.get().then((res) => res?.id!) part needs the query to actually run I imagine. I am not familiar with this framework you are using for constructing your queries.db.batchsharedDB.batch([
sharedDB.insert(usersTable).values({
publicId: nanoid(),
name: googleUser.name,
email: googleUser.email
}).onConflictDoNothing()
.returning(),
sharedDB.insert(oauthAccountsTable).values({
providerId: "google",
providerUserId: googleUser.sub,
userId:// !!! no id
})
])batchnpx prisma migrate diff --from-url ????here remote d1 --to-schema-datamodel ./prisma/schema.prisma --script --output migrations/0002_second.sqlgoogleUser.emailbatch()nanoid()await sharedDB.batch([
sharedDB.insert(usersTable).values({
publicId: nanoid(),
name: googleUser.name,
email: googleUser.email
}).onConflictDoNothing()
.returning(),
sharedDB.insert(oauthAccountsTable).values({
providerId: "google",
providerUserId: googleUser.sub,
userId: await sharedDB.select({ id: usersTable.id }).from(usersTable).where(eq(usersTable.email, googleUser.email)).get().then((res) => res?.id!),
})
]).get().then((res) => res?.id!) const hash = utils.hashPassword(request.json.password);
const account = await env.DB.prepare("INSERT INTO users (email, password, firstname, lastname) VALUES (?, ?, ?, ?) RETURNING pk;")
.bind(request.json.email, hash, request.json.firstname, request.json.lastname)
.run();
if (!account.success) throw new Error();
const snowflake = utils.createSnowflake(account.results[0].pk);
const set_id = await env.DB.prepare("UPDATE users SET id = ? WHERE pk = ?;")
.bind(snowflake, account.results[0].pk)
.run();
if (!set_id.success) throw new Error();