sqlite3

package
v0.19.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2025 License: Apache-2.0 Imports: 1 Imported by: 3

Documentation

Overview

Integrates with migration tools recognizing the standard "migrate up" and "migrate down" annotations, simplifying asset database schema management and rollbacks in SQLite3.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Migrations

func Migrations() embed.FS
Example
dsn := "test.db"
if v, ok := os.LookupEnv("SQLITE3_DB"); ok {
	dsn = v
}

db, err := gorm.Open(sqlite.Open(dsn), &gorm.Config{})
if err != nil {
	panic("failed to connect database")
}

sqlDb, _ := db.DB()

migrationsSource := migrate.EmbedFileSystemMigrationSource{
	FileSystem: Migrations(),
	Root:       "/",
}

_, err = migrate.Exec(sqlDb, "sqlite3", migrationsSource, migrate.Up)
if err != nil {
	panic(err)
}

tables := []string{"entities", "entity_tags", "edges", "edge_tags"}
for _, table := range tables {
	fmt.Println(db.Migrator().HasTable(table))
}

err = os.Remove(dsn)
if err != nil {
	panic(err)
}
Output:

true
true
true
true

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL