refactor into an importable library and keep an example
This commit is contained in:
35
examples/basic-usage/main.go
Normal file
35
examples/basic-usage/main.go
Normal 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()
|
||||
}
|
Reference in New Issue
Block a user