Artem Sukhodolskyi 820879b79f initial commit
2025-10-21 12:55:17 +02:00

46 lines
780 B
Go

package app
import (
"database/sql"
_ "github.com/mattn/go-sqlite3"
)
type SQLiteEngine struct {
connection *sql.DB
}
func CreateSQLite(url string) (*SQLiteEngine, error) {
sqliteDatabase, err := sql.Open("sqlite3", url)
if err != nil {
return nil, err
}
return &SQLiteEngine{connection: sqliteDatabase}, nil
}
func (e *SQLiteEngine) Query(sql string, args ...any) (*sql.Rows, error) {
result, err := e.connection.Query(sql, args...)
if err != nil {
return nil, err
}
return result, nil
}
func (e *SQLiteEngine) Execute(sql string, args ...any) error {
_, err := e.connection.Exec(sql, args...)
if err != nil {
return err
}
return nil
}
func (e *SQLiteEngine) Close() error {
if e.connection != nil {
return e.connection.Close()
}
return nil
}