Skip to content

Commit

Permalink
Add support for sqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
jrauh01 committed Dec 9, 2024
1 parent f365c82 commit 8e45b33
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
18 changes: 14 additions & 4 deletions database/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,24 @@ func NewDbFromConfig(c *Config, logger *logging.Logger, connectorCallbacks Retry
addr = utils.JoinHostPort(c.Host, port)
}
db = sqlx.NewDb(sql.OpenDB(NewConnector(connector, logger, connectorCallbacks)), PostgreSQL)
case "sqlite":
addr = c.Database

liteDb, err := sql.Open(SQLite, fmt.Sprintf("file:%s?cache=shared", c.Database))
if err != nil {
return nil, errors.Wrap(err, "can't open sqlite database")
}
db = sqlx.NewDb(liteDb, SQLite)
default:
return nil, unknownDbType(c.Type)
}

if c.TlsOptions.Enable {
addr = fmt.Sprintf("%s+tls://%s@%s/%s", c.Type, c.User, addr, c.Database)
} else {
addr = fmt.Sprintf("%s://%s@%s/%s", c.Type, c.User, addr, c.Database)
if c.Type != "sqlite" {
if c.TlsOptions.Enable {
addr = fmt.Sprintf("%s+tls://%s@%s/%s", c.Type, c.User, addr, c.Database)
} else {
addr = fmt.Sprintf("%s://%s@%s/%s", c.Type, c.User, addr, c.Database)
}
}

db.SetMaxIdleConns(c.Options.MaxConnections / 3)
Expand Down
1 change: 1 addition & 0 deletions database/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
const (
MySQL string = "mysql"
PostgreSQL string = "postgres"
SQLite string = "sqlite"
)

// OnInitConnFunc can be used to execute post Connect() arbitrary actions.
Expand Down

0 comments on commit 8e45b33

Please sign in to comment.