src/mdx/get-started/QueryDatabase.mdx
import CodeWithProps from "@mdx/CodeWithProps.astro";
Let's update the src/index.ts file with queries to create, read, update, and delete users
const db = drizzle(process.env.$env_variable$!);
async function main() { const user: typeof usersTable.$inferInsert = { name: 'John', age: 30, email: '[email protected]', };
await db.insert(usersTable).values(user); console.log('New user created!')
const users = await db.select().from(usersTable); console.log('Getting all users from the database: ', users) /* const users: { id: number; name: string; age: number; email: string; }[] */
await db .update(usersTable) .set({ age: 31, }) .where(eq(usersTable.email, user.email)); console.log('User info updated!')
await db.delete(usersTable).where(eq(usersTable.email, user.email)); console.log('User deleted!') }
main();
</CodeWithProps>