https://github.com/lithdew/bun-sqlite-migrator
A bun:sqlite port of kysely's migrator module.
https://github.com/lithdew/bun-sqlite-migrator
Last synced: about 1 year ago
JSON representation
A bun:sqlite port of kysely's migrator module.
- Host: GitHub
- URL: https://github.com/lithdew/bun-sqlite-migrator
- Owner: lithdew
- Created: 2024-11-19T11:12:38.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-02T19:03:27.000Z (over 1 year ago)
- Last Synced: 2025-04-23T22:03:49.907Z (about 1 year ago)
- Language: TypeScript
- Size: 6.84 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# bun-sqlite-migrator
A bun:sqlite port of [kysely](https://github.com/kysely-org/kysely)'s migrator module.
```ts
import { Database } from "bun:sqlite";
import { Migrator, FileMigrationProvider } from "bun-sqlite-migrator";
const sqlite = new Database(filename, {
create: true,
readwrite: true,
safeIntegers: true,
strict: true,
});
sqlite.exec("PRAGMA foreign_keys = ON");
sqlite.exec("PRAGMA journal_mode = WAL");
sqlite.exec("PRAGMA synchronous = NORMAL");
sqlite.exec("PRAGMA temp_store = MEMORY");
sqlite.exec("PRAGMA cache_size = 10000");
sqlite.exec("PRAGMA mmap_size = 30000000000");
const migrator = new Migrator({
db: sqlite,
provider: new FileMigrationProvider({
migrationFolder: "./migrations"
}),
});
const { error, results } = migrator.migrateToLatest();
for (const result of results ?? []) {
if (result.status === "Error") {
throw new Error(
`failed to execute migration "${result.migrationName}"`,
{ cause: error }
);
}
console.log(
`migration "${result.migrationName}" was executed successfully`
);
}
```