SQLite

/app/lib/database/sqlite-yes.go (1.1 KB)

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//go:build darwin || (!android && linux && 386) || (!android && linux && amd64) || (!android && linux && arm) || (!android && linux && arm64) || (!android && linux && riscv64) || (windows && amd64)
package database

import (
"context"

"github.com/jmoiron/sqlx"
"github.com/pkg/errors"
_ "modernc.org/sqlite" // load sqlite driver.

"{{{ .Package }}}/app/lib/telemetry"
"{{{ .Package }}}/app/util"
)

const SQLiteEnabled = true

var typeSQLite = &DBType{Key: "sqlite", Title: "SQLite", Quote: `"`, Placeholder: "$", SupportsReturning: true}

func OpenSQLiteDatabase(ctx context.Context, key string, params *SQLiteParams, logger util.Logger) (*Service, error) {
_, span, logger := telemetry.StartSpan(ctx, "database:open", logger)
defer span.Complete()
if params.File == "" {
return nil, errors.New("need filename for SQLite database")
}
db, err := sqlx.Open("sqlite", params.File)
if err != nil {
return nil, errors.Wrap(err, "error opening database")
}
return NewService(typeSQLite, key, key, params.Schema, "sqlite", params.Debug, db, logger)
}