New to SQL... how does one insert into a parent table and a child one?
Assuming the following tables
import { integer, pgTable, serial, text } from 'drizzle-orm/pg-core';
export const users = pgTable('user', {
id: serial('id').primaryKey(),
name: text('name'),
});
export const tokens = pgTable('token', {
id: serial('id').primaryKey(),
userId: text("userId").notNull().references(() => users.id, { onDelete: "cascade" }),
token: string("token"),
});
To create a new user with a token... I think manually looks like this...
const newUser = await db.insert(users).values({name: "Billy"}).returning();
const token = await db.insert(token).values({userId: newUser.id, token: "123"}).returning();
Is this the proper way or is this transaction supposed to be using a view or transactions?