mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00

* [NOD-1164] Defined DatabaseContext as the basic object of dbaccess * [NOD-1164] Update everything to use databaseContext * [NOD-1164] Fix tests * [NOD-1164] Add comments * [NOD-1164] Removed databaseContext from blockNode * [NOD-1164] Enforce DatabaseContext != nil * [NOD-1164] Remove redundant and wrong comment line
31 lines
733 B
Go
31 lines
733 B
Go
package dbaccess
|
|
|
|
import (
|
|
"github.com/kaspanet/kaspad/database"
|
|
"github.com/kaspanet/kaspad/database/ffldb"
|
|
)
|
|
|
|
// DatabaseContext represents a context in which all database queries run
|
|
type DatabaseContext struct {
|
|
db database.Database
|
|
*noTxContext
|
|
}
|
|
|
|
// New creates a new DatabaseContext with database is in the specified `path`
|
|
func New(path string) (*DatabaseContext, error) {
|
|
db, err := ffldb.Open(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
databaseContext := &DatabaseContext{db: db}
|
|
databaseContext.noTxContext = &noTxContext{backend: databaseContext}
|
|
|
|
return databaseContext, nil
|
|
}
|
|
|
|
// Close closes the DatabaseContext's connection, if it's open
|
|
func (ctx *DatabaseContext) Close() error {
|
|
return ctx.db.Close()
|
|
}
|