src/mdx/get-started/sqlite/QueryTurso.mdx
import CodeWithProps from "@mdx/CodeWithProps.astro";
Let's update the src/index.ts file with queries to create, read, update, and delete users
async function main() { const db = drizzle({ connection: { url: process.env.TURSO_DATABASE_URL!, authToken: process.env.TURSO_AUTH_TOKEN! } });
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>