bun:sqlite built-in module.
Create a fresh project with
bun init and install Drizzle.
terminal
Then connect to a SQLite database with the
bun:sqlite module and create the Drizzle database instance.
To see the database in action, add these lines to
index.ts.
Then run
index.ts with Bun. Bun creates sqlite.db and executes the query.
terminal
Now give the database a schema. Create a
schema.ts file and define a movies table.
Generate an initial SQL migration with the
drizzle-kit CLI.
terminal
The command creates a
drizzle directory containing a .sql migration file and a meta directory.
File Tree
Execute these migrations with a
migrate.ts script. It connects to sqlite.db, then executes all unexecuted migrations in the drizzle directory.
Run the script with
bun to execute the migration.
terminal
Now add some data to the database. Create a
seed.ts file with the following contents.
Then run this file.
terminal
The database now has a schema and some sample data. Query it with Drizzle by replacing the contents of
index.ts with the following.
Then run the file. You should see the three movies you inserted.
terminal
See the Drizzle docs.