refactor into an importable library and keep an example

This commit is contained in:
2024-08-22 00:05:50 -06:00
parent cdc8fc4e5e
commit cfd22dfc9c
6 changed files with 18 additions and 8 deletions

View File

@ -0,0 +1,35 @@
package main
import (
"embed"
"fmt"
"git.sa.vin/payne8/libsqldb"
"os"
)
//go:embed migrations/*.sql
var migrationFiles embed.FS
func main() {
primaryUrl := os.Getenv("LIBSQL_DATABASE_URL")
authToken := os.Getenv("LIBSQL_AUTH_TOKEN")
tdb, err := libsqldb.NewLibSqlDB(
primaryUrl,
migrationFiles,
libsqldb.WithAuthToken(authToken),
libsqldb.WithLocalDBName("local.db"),
)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to open db %s: %s", primaryUrl, err)
os.Exit(1)
}
err = tdb.Migrate()
if err != nil {
fmt.Fprintf(os.Stderr, "failed to migrate db %s: %s", primaryUrl, err)
os.Exit(1)
}
defer tdb.Close()
}