storj/pkg/accounting/db.go
Bill Thorp b2a8a10b16
redo tally query (#742)
* redo tally query

* broken, sharing w/ Jen

* tally tests added, failiing

* fix txn issue in tally

* fix lint
2018-12-05 09:03:23 -05:00

36 lines
776 B
Go

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package accounting
import (
"storj.io/storj/internal/migrate"
dbx "storj.io/storj/pkg/accounting/dbx"
"storj.io/storj/pkg/utils"
)
// LastBandwidthTally is a name in the accounting timestamps database
var LastBandwidthTally dbx.Timestamps_Name_Field
func init() {
LastBandwidthTally = dbx.Timestamps_Name("LastBandwidthTally")
}
// NewDb - constructor for DB
func NewDb(databaseURL string) (*dbx.DB, error) {
dbURL, err := utils.ParseURL(databaseURL)
if err != nil {
return nil, err
}
db, err := dbx.Open(dbURL.Scheme, dbURL.Path)
if err != nil {
return nil, err
}
err = migrate.Create("accounting", db)
if err != nil {
_ = db.Close()
return nil, err
}
return db, nil
}