Skip to content

Commit

Permalink
sql db: add sqlite driver
Browse files Browse the repository at this point in the history
  • Loading branch information
agungdwiprasetyo committed May 18, 2023
1 parent 991634a commit 7d5b660
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion cmd/candi/cli_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ stageSelectDependencies:
stageSelectSQLDriver:
cmdInput = readInput("Please select SQL database driver (choose one)\n" +
"1) Postgres\n" +
"2) MySQL")
"2) MySQL\n" +
"3) SQLite3")
srvConfig.SQLDriver, ok = sqlDrivers[cmdInput]
if !ok {
fmt.Printf(RedFormat, "Invalid option, try again")
Expand Down
3 changes: 2 additions & 1 deletion cmd/candi/template_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
"fmt"
"runtime/debug"{{if eq .SQLDriver "postgres"}}
_ "github.com/lib/pq"{{else if eq .SQLDriver "mysql"}}
_ "github.com/go-sql-driver/mysql"{{end}}
_ "github.com/go-sql-driver/mysql"{{else if eq .SQLDriver "sqlite3"}}
_ "github.com/mattn/go-sqlite3"{{end}}
"{{.LibraryName}}/codebase/app"
"{{.LibraryName}}/config"
Expand Down
2 changes: 1 addition & 1 deletion cmd/candi/template_delivery_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (h *TaskQueueHandler) handleTask{{upper (camel .ModuleName)}}(eventContext
// h.uc.SomethingUsecase()
return &candishared.ErrorRetrier{
Delay: 10 * time.Second,
Delay: 2 * time.Second,
Message: "Error retry",
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/candi/template_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ MONGODB_HOST_READ=mongodb://user:pass@localhost:27017/{{.ServiceName}}?authSourc
SQL_DB_READ_DSN={{ if .SQLDeps }}{{.SQLDriver}}://` +
"{{if eq .SQLDriver \"postgres\"}}user:pass@localhost:5432/db_name?sslmode=disable&TimeZone=Asia/Jakarta{{else if eq .SQLDriver \"mysql\"}}" +
"root:pass@tcp(127.0.0.1:3306)/db_name{{end}}" +
"root:pass@tcp(127.0.0.1:3306)/db_name{{else if eq .SQLDriver \"sqlite3\"}}database.db{{end}}" +
`{{ end }}
SQL_DB_WRITE_DSN={{ if .SQLDeps }}{{.SQLDriver}}://` +
"{{if eq .SQLDriver \"postgres\"}}user:pass@localhost:5432/db_name?sslmode=disable&TimeZone=Asia/Jakarta{{else if eq .SQLDriver \"mysql\"}}" +
"root:pass@tcp(127.0.0.1:3306)/db_name{{end}}" +
"root:pass@tcp(127.0.0.1:3306)/db_name{{else if eq .SQLDriver \"sqlite3\"}}database.db{{end}}" +
`{{ end }}
{{if .ArangoDeps}}
ARANGODB_HOST_WRITE=http://user:pass@localhost:8529/{{.ServiceName}}
Expand Down
2 changes: 1 addition & 1 deletion cmd/candi/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var (
"1": RedisDeps, "2": SqldbDeps, "3": MongodbDeps, "4": ArangodbDeps,
}
sqlDrivers = map[string]string{
"1": "postgres", "2": "mysql",
"1": "postgres", "2": "mysql", "3": "sqlite3",
}
optionYesNo = map[string]bool{"y": true, "n": false}
licenseMap = map[string]string{
Expand Down
2 changes: 1 addition & 1 deletion config/database/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func ConnectSQLDatabase(dsn string) *sql.DB {
driverName := sqlDriver

switch sqlDriver {
case "mysql":
case "mysql", "sqlite3":
dsn = conn

case "sqlserver":
Expand Down

0 comments on commit 7d5b660

Please sign in to comment.