32 lines
740 B
Go
32 lines
740 B
Go
package storage
|
|
|
|
import (
|
|
"embed"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
//go:embed schema_sqlite.sql
|
|
var sqliteSchemaFS embed.FS
|
|
|
|
//go:embed schema_postgres.sql
|
|
var postgresSchemaFS embed.FS
|
|
|
|
func SchemaForDBType(dbType string) (string, error) {
|
|
switch strings.ToLower(dbType) {
|
|
case DBTypeSQLite:
|
|
b, err := sqliteSchemaFS.ReadFile("schema_sqlite.sql")
|
|
if err != nil {
|
|
return "", fmt.Errorf("failed to read sqlite schema: %w", err)
|
|
}
|
|
return string(b), nil
|
|
case "postgres", "postgresql":
|
|
b, err := postgresSchemaFS.ReadFile("schema_postgres.sql")
|
|
if err != nil {
|
|
return "", fmt.Errorf("failed to read postgres schema: %w", err)
|
|
}
|
|
return string(b), nil
|
|
default:
|
|
return "", fmt.Errorf("unsupported database type: %s", dbType)
|
|
}
|
|
}
|