forked from opentdp/tdp-cloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
67 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,6 @@ var Logger struct { | |
} | ||
|
||
var Server struct { | ||
DSN string | ||
Listen string | ||
JwtKey string | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ logger: | |
dir: /var/log/tdp-cloud | ||
level: info | ||
server: | ||
dsn: server.db | ||
listen: :7800 | ||
EOF | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,7 +84,6 @@ logger: | |
dir: /var/log/tdp-cloud | ||
level: info | ||
server: | ||
dsn: server.db | ||
listen: :7800 | ||
EOF | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package dborm | ||
|
||
import ( | ||
"github.com/glebarez/sqlite" | ||
"gorm.io/driver/mysql" | ||
"gorm.io/gorm" | ||
|
||
"tdp-cloud/cmd/args" | ||
"tdp-cloud/helper/logman" | ||
) | ||
|
||
func dialector() gorm.Dialector { | ||
|
||
switch args.Database.Type { | ||
case "sqlite": | ||
return useSqlite() | ||
case "mysql": | ||
return useMysql() | ||
default: | ||
logman.Fatal("Database Type error:", args.Database.Type) | ||
} | ||
|
||
return nil | ||
|
||
} | ||
|
||
func useSqlite() gorm.Dialector { | ||
|
||
dir := args.Dataset.Dir | ||
name := args.Database.Name | ||
|
||
option := args.Database.Option | ||
if option == "" { | ||
option = "?_pragma=busy_timeout=5000&_pragma=journa_mode(WAL)" | ||
} | ||
|
||
return sqlite.Open(dir + "/" + name + option) | ||
|
||
} | ||
|
||
func useMysql() gorm.Dialector { | ||
|
||
host := args.Database.Host | ||
user := args.Database.User | ||
passwd := args.Database.Passwd | ||
name := args.Database.Name | ||
|
||
option := args.Database.Option | ||
if option == "" { | ||
option = "?charset=utf8mb4&parseTime=True&loc=Local" | ||
} | ||
|
||
return mysql.Open(user + ":" + passwd + "@tcp(" + host + ")/" + name + option) | ||
|
||
} |