Merge from main
This commit is contained in:
parent
ef8c9ceccd
commit
94cc769d4b
2 changed files with 5 additions and 4 deletions
|
@ -19,7 +19,7 @@ import (
|
|||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
var config Configuration
|
||||
var config *Configuration
|
||||
var wsServer *WSServer
|
||||
var store *SQLStore
|
||||
|
||||
|
@ -376,7 +376,6 @@ func main() {
|
|||
|
||||
http.Handle("/", r)
|
||||
|
||||
var err error
|
||||
store, err = NewSQLStore(config.DBType, config.DBConfigString)
|
||||
if err != nil {
|
||||
log.Fatal("Unable to start the database", err)
|
||||
|
|
|
@ -10,11 +10,13 @@ import (
|
|||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
// SQLStore is a SQL database
|
||||
type SQLStore struct {
|
||||
db *sql.DB
|
||||
dbType string
|
||||
}
|
||||
|
||||
// NewSQLStore creates a new SQLStore
|
||||
func NewSQLStore(dbType, connectionString string) (*SQLStore, error) {
|
||||
log.Println("connectDatabase")
|
||||
var err error
|
||||
|
@ -149,7 +151,7 @@ func (s *SQLStore) getBlocksWithParent(parentID string) []string {
|
|||
return blocksFromRows(rows)
|
||||
}
|
||||
|
||||
func (s *SQLStore) getBlocksWithType(blockID string) []string {
|
||||
func (s *SQLStore) getBlocksWithType(blockType string) []string {
|
||||
query := `WITH latest AS
|
||||
(
|
||||
SELECT * FROM
|
||||
|
@ -166,7 +168,7 @@ func (s *SQLStore) getBlocksWithType(blockID string) []string {
|
|||
FROM latest
|
||||
WHERE delete_at = 0 and type = $1`
|
||||
|
||||
rows, err := db.Query(query, blockType)
|
||||
rows, err := s.db.Query(query, blockType)
|
||||
if err != nil {
|
||||
log.Printf(`getBlocksWithParentAndType ERROR: %v`, err)
|
||||
panic(err)
|
||||
|
|
Loading…
Reference in a new issue