Skip to content

Commit

Permalink
different query formatting for MySQL, new build scripts and makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
darcys22 committed Apr 13, 2020
1 parent f70cf5e commit 82128f6
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ password.txt

# Ignore Build
build
release
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
BINARY := godbledger
VERSION ?= latest
PLATFORMS := linux
os = $(word 1, $@)

.PHONY: $(PLATFORMS)
$(PLATFORMS):
mkdir -p release/$(BINARY)-$(os)-x64-v$(VERSION)/
GOOS=$(os) GOARCH=amd64 go build -o release/$(BINARY)-$(os)-x64-v$(VERSION)/ ./...

.PHONY: release
release: linux

PHONY: clean
clean:
rm -rf release/
4 changes: 2 additions & 2 deletions godbledger/db/mysql/mysqldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (db *Database) InitDB() error {
//USERS
createDB := `
CREATE TABLE IF NOT EXISTS users (
user_id INT NOT NULL,
user_id VARCHAR(255) NOT NULL,
username VARCHAR(255) NOT NULL,
PRIMARY KEY(user_id)
);`
Expand All @@ -77,7 +77,7 @@ func (db *Database) InitDB() error {
//TAGS
createDB = `
CREATE TABLE IF NOT EXISTS tags (
tag_id INTEGER PRIMARY KEY,
tag_id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
tag_name VARCHAR(100) NOT NULL UNIQUE
);`
log.Debug("Query: " + createDB)
Expand Down
20 changes: 10 additions & 10 deletions godbledger/db/mysql/mysqlfuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (db *Database) DeleteTransaction(txnID string) error {

sqlStatement := `
DELETE FROM transactions
WHERE transaction_id = $1;`
WHERE transaction_id = ?;`
_, err := db.DB.Exec(sqlStatement, txnID)
if err != nil {
return err
Expand All @@ -114,7 +114,7 @@ func (db *Database) DeleteTransaction(txnID string) error {
func (db *Database) FindTag(tag string) (int, error) {
var resp int
log.Info("Searching Tag in DB")
err := db.DB.QueryRow(`SELECT tag_id FROM tags WHERE tag_name = $1 LIMIT 1`, tag).Scan(&resp)
err := db.DB.QueryRow(`SELECT tag_id FROM tags WHERE tag_name = ? LIMIT 1`, tag).Scan(&resp)
if err != nil {
log.Debug("Find Tag Failed: ", err)
return 0, err
Expand Down Expand Up @@ -172,7 +172,7 @@ func (db *Database) SafeAddTagToAccount(account, tag string) error {
tagID, _ := db.FindTag(tag)

var accountID string
err = db.DB.QueryRow(`SELECT account_id FROM accounts WHERE name = $1 LIMIT 1`, account).Scan(&accountID)
err = db.DB.QueryRow(`SELECT account_id FROM accounts WHERE name = ? LIMIT 1`, account).Scan(&accountID)
if err != nil {
log.Debug(err)
return err
Expand All @@ -183,7 +183,7 @@ func (db *Database) SafeAddTagToAccount(account, tag string) error {

func (db *Database) AddTagToAccount(accountID string, tag int) error {
var exists int
err := db.DB.QueryRow(`SELECT EXISTS(SELECT * FROM account_tag where (account_id = $1) AND (tag_id = $2));`, accountID, tag).Scan(&exists)
err := db.DB.QueryRow(`SELECT EXISTS(SELECT * FROM account_tag where (account_id = ?) AND (tag_id = ?));`, accountID, tag).Scan(&exists)
if err != nil {
log.Debug(err)
return err
Expand Down Expand Up @@ -233,9 +233,9 @@ func (db *Database) DeleteTagFromAccount(account, tag string) error {
sqlStatement := `
DELETE FROM account_tag
WHERE
tag_id = $1
tag_id = ?
AND
account_id = $2
account_id = ?
;`
_, err = db.DB.Exec(sqlStatement, tagID, account)
if err != nil {
Expand All @@ -247,8 +247,8 @@ func (db *Database) DeleteTagFromAccount(account, tag string) error {

func (db *Database) FindCurrency(cur string) (*core.Currency, error) {
var resp core.Currency
log.Info("Searching Currency in DB")
err := db.DB.QueryRow(`SELECT * FROM currencies WHERE name = $1 LIMIT 1`, cur).Scan(&resp.Name, &resp.Decimals)
log.Info("Searching Currency in DB: ", cur)
err := db.DB.QueryRow(`SELECT * FROM currencies WHERE name = ? LIMIT 1`, cur).Scan(&resp.Name, &resp.Decimals)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -295,7 +295,7 @@ func (db *Database) SafeAddCurrency(cur *core.Currency) error {
func (db *Database) FindAccount(code string) (*core.Account, error) {
var resp core.Account
log.Info("Searching Account in DB")
err := db.DB.QueryRow(`SELECT * FROM accounts WHERE account_id = $1 LIMIT 1`, code).Scan(&resp.Code, &resp.Name)
err := db.DB.QueryRow(`SELECT * FROM accounts WHERE account_id = ? LIMIT 1`, code).Scan(&resp.Code, &resp.Name)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -343,7 +343,7 @@ func (db *Database) SafeAddAccount(acc *core.Account) error {
func (db *Database) FindUser(pubKey string) (*core.User, error) {
var resp core.User
log.Info("Searching User in DB")
err := db.DB.QueryRow(`SELECT * FROM users WHERE username = $1 LIMIT 1`, pubKey).Scan(&resp.Id, &resp.Name)
err := db.DB.QueryRow(`SELECT * FROM users WHERE username = ? LIMIT 1`, pubKey).Scan(&resp.Id, &resp.Name)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions reporter/trialbalance.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ If you want to see all the transactions in the database, or export to CSV
panic(fmt.Sprintf("Database does not already exist at %s.", databasefilepath))
}

SqliteDB, err := sql.Open("sqlite3", databasefilepath)
DB, err := sql.Open(cfg.DatabaseType, databasefilepath)
if err != nil {
log.Fatal(err)
}
Expand All @@ -68,7 +68,7 @@ If you want to see all the transactions in the database, or export to CSV
GROUP BY split_accounts.account_id
;`

rows, err := SqliteDB.Query(queryDB)
rows, err := DB.Query(queryDB)
if err != nil {
log.Fatal(err)
}
Expand Down
9 changes: 6 additions & 3 deletions utils/make-release.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
#!/bin/bash

version=$1
build=linux

if [ -z "$version" ]
then
echo "Usage: $0 <version>"
exit
fi

WORKING_DIR=godbledger-$version
make VERSION=$version release

WORKING_DIR=release/

echo "Working in $WORKING_DIR..."

mkdir -p $WORKING_DIR
cd $WORKING_DIR

tar -czvf godbledger-$build-x64-$version.tar.gz godbledger-$build-x64-$version
tar -czvf godbledger-$build-x64-v$version.tar.gz godbledger-$build-x64-v$version

echo '#### sha256sum'
sha256sum godbledger-*-x64-$version.zip
sha256sum godbledger-*-x64-v$version.tar.gz

0 comments on commit 82128f6

Please sign in to comment.