diff --git a/database/db.go b/database/db.go index a33cd56a..a4314550 100644 --- a/database/db.go +++ b/database/db.go @@ -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) diff --git a/database/driver.go b/database/driver.go index 5aa03aea..e8f52f97 100644 --- a/database/driver.go +++ b/database/driver.go @@ -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.