Files
libredesk/internal/dbutil/scanner.go
Abhinav Raut 50188352a5 fix: Use SyncedEnforcer in casbin, fixes panics.
feat: store user roles in user roles table, drops the roles table on users table.
feat: standardize column names in schema, renames disabled bool to enables.
- vue router fixes to allow components / pages to rerender after creating an object in db.
- minor fixes and refactors.
2025-01-22 03:40:32 +05:30

32 lines
767 B
Go

// Package dbutil provides utility functions for database operations.
package dbutil
import (
"io/fs"
"github.com/jmoiron/sqlx"
"github.com/knadh/goyesql/v2"
goyesqlx "github.com/knadh/goyesql/v2/sqlx"
)
// ScanSQLFile scans a goyesql .sql file from the given fs and prepares the queries in the given struct.
func ScanSQLFile(path string, o interface{}, db *sqlx.DB, f fs.FS) error {
// Read the SQL file from the embedded filesystem.
b, err := fs.ReadFile(f, path)
if err != nil {
return err
}
// Parse the SQL file.
q, err := goyesql.ParseBytes(b)
if err != nil {
return err
}
// Scan the parsed queries into the provided struct and prepare them.
if err := goyesqlx.ScanToStruct(o, q, db.Unsafe()); err != nil {
return err
}
return nil
}