-
Notifications
You must be signed in to change notification settings - Fork 1
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
18 changed files
with
344 additions
and
495 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 |
---|---|---|
|
@@ -3,3 +3,4 @@ certs/** | |
config.yaml | ||
config.yml | ||
packagelock.pid | ||
packagelock/** |
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 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,72 @@ | ||
package db | ||
|
||
import ( | ||
"fmt" | ||
"packagelock/config" | ||
|
||
"github.com/surrealdb/surrealdb.go" | ||
) | ||
|
||
var DB *surrealdb.DB | ||
|
||
func InitDB() error { | ||
dbAddress := config.Config.GetString("database.address") | ||
dbPort := config.Config.GetString("database.port") | ||
dbUsername := config.Config.GetString("database.username") | ||
dbPasswd := config.Config.GetString("database.password") | ||
|
||
db, err := surrealdb.New("ws://" + dbAddress + ":" + dbPort + "/rpc") | ||
if err != nil { | ||
errorMessage := fmt.Sprintf(` Couldn't connect to DB! Got: '%s'. | ||
1. Check the config for a wrong Address/Port (Currently: %s:%s) | ||
2. Check if the DB is reachable (eg. a Ping). Check the Firewalls if there. | ||
3. Consult the PackageLock Doc's! 🚀 | ||
Golang Trace Logs: | ||
`, err.Error(), dbAddress, dbPort) | ||
fmt.Println(errorMessage) | ||
panic(err) | ||
} | ||
|
||
if _, err = db.Signin(map[string]interface{}{ | ||
// TODO: get user&password from Conf | ||
"user": dbUsername, | ||
"pass": dbPasswd, | ||
}); err != nil { | ||
errorMessage := fmt.Sprintf(` Couldn't connect to DB! Got: '%s'. | ||
1. Check the config for a wrong DB-Username/Password (Currently: %s/<read the config!>) | ||
3. Consult the PackageLock Doc's! 🚀 | ||
Golang Trace Logs: | ||
`, err.Error(), dbUsername) | ||
fmt.Println(errorMessage) | ||
panic(err) | ||
} | ||
|
||
if _, err = db.Use("PackageLock", "db1.0"); err != nil { | ||
// No error handling possible, as we need to use this db | ||
panic(err) | ||
} | ||
|
||
DB = db | ||
|
||
return nil | ||
} | ||
|
||
// INFO: If you use this, fix it! | ||
func Select(tablename string, SliceOfType interface{}) error { | ||
transaction, err := DB.Select(tablename) | ||
if err != nil { | ||
// FIXME: logging? | ||
// Error handling | ||
panic(err) | ||
} | ||
|
||
err = surrealdb.Unmarshal(transaction, &SliceOfType) | ||
if err != nil { | ||
// FIXME: Logging? | ||
// Error Handling? | ||
panic(err) | ||
} | ||
|
||
// FIXME: Add Success msg in Log! | ||
return nil | ||
} |
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,3 @@ | ||
package db | ||
|
||
// this package is for future DB migrations |
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
Oops, something went wrong.