Documentation ¶
Overview ¶
Package db implements database models, insert and select functions for a postgres database using the "bun" ORM (github.com/uptrace/bun)
Index ¶
- Variables
- func Connect(params *ConnectionParams)
- func EnableDebugLogs()
- func InsertChannel(channel lndclient.ChannelInfo, pubkey string) error
- func InsertMultiChannelBackup(backup string, pubkey string) error
- func InsertNode(node *Node) error
- func InsertUser(user *User) error
- func RunMigrations() error
- func UpdateUserLastSent(user User) error
- type Channel
- type ChannelBackup
- type ConnectionParams
- type MultiChannelBackup
- type Node
- type User
Constants ¶
This section is empty.
Variables ¶
var Instance *bun.DB
Instance is the global database instance
Functions ¶
func Connect ¶
func Connect(params *ConnectionParams)
Connect connects to a Postgres database with the credentials provided
func EnableDebugLogs ¶
func EnableDebugLogs()
EnableDebugLogs logs all database queries to the console
func InsertChannel ¶
func InsertChannel(channel lndclient.ChannelInfo, pubkey string) error
InsertChannel adds a channel to the db
func InsertMultiChannelBackup ¶
InsertMultiChannelBackup adds a static channel backup of all channels to the database
func InsertNode ¶
InsertNode adds a lightning node to the database
func InsertUser ¶
InsertUser adds a lightning node to the database
func RunMigrations ¶
func RunMigrations() error
RunMigrations gets all *.sql files from /migrations and runs them to create tables and constraints
func UpdateUserLastSent ¶
UpdateUserLastSent updates user in the db
Types ¶
type Channel ¶
type Channel struct { bun.BaseModel `bun:"table:channels"` ID int64 `bun:"id,pk,autoincrement"` FundingTxid string `bun:"funding_txid"` OutputIndex int64 `bun:"output_index"` NodeID int64 `bun:"node_id"` }
Channel is a Lightning Channel
func FindAllChannels ¶
FindAllChannels gets channel from the db
func FindChannelByNodeID ¶
FindChannelByNodeID gets channel from the db
type ChannelBackup ¶
type ChannelBackup struct { bun.BaseModel `bun:"table:channel_backups"` ID int64 `bun:"id,pk,autoincrement"` CreatedAt time.Time `bun:"created_at,nullzero,notnull,default:current_timestamp"` FundingTxidBytes string `bun:"funding_txid_bytes"` OutputIndex int64 `bun:"output_index"` Backup string `bun:"backup"` }
ChannelBackup is an encrypted static channel backup of a single lightning channel
type ConnectionParams ¶
type ConnectionParams struct { Host string Port string User string Password string DatabaseName string }
ConnectionParams include database credentials and network details
type MultiChannelBackup ¶
type MultiChannelBackup struct { bun.BaseModel `bun:"table:multi_channel_backups"` ID int64 `bun:"id,pk,autoincrement"` CreatedAt time.Time `bun:"created_at,nullzero,notnull,default:current_timestamp"` Backup string `bun:"backup"` NodeID int64 `bun:"node_id"` }
MultiChannelBackup is an encrypted backup of a lightning channel state
func FindAllMultiChannelBackups ¶
func FindAllMultiChannelBackups(ctx context.Context) ([]MultiChannelBackup, error)
FindAllMultiChannelBackups gets channel from the db
func FindMultiChannelBackupByPubkey ¶
func FindMultiChannelBackupByPubkey(pubkey string) (MultiChannelBackup, error)
FindMultiChannelBackupByPubkey gets the most recent multi-channel backup from the db
type Node ¶
type Node struct { bun.BaseModel `bun:"table:nodes"` ID int64 `bun:"id,pk,autoincrement"` URL string `bun:"url,unique"` Alias string `bun:"alias"` Pubkey string `bun:"pubkey"` Macaroon string `bun:"macaroon"` TLSCert string `bun:"tls_cert"` UserID int64 `bun:"user_id"` }
Node is a Lightning Node
func FindAllNodes ¶
FindAllNodes gets node from the db
func FindNodeByPubkey ¶
FindNodeByPubkey gets node from the db
type User ¶
type User struct { bun.BaseModel `bun:"table:users"` ID int64 `bun:"id,pk,autoincrement"` Email string `bun:"email,unique"` Password string `bun:"password"` PhoneNumber string `bun:"phone_number"` SmsEnabled bool `bun:"sms_enabled"` SmsLastSent time.Time `bun:"sms_last_sent"` SmsNotifyTime time.Time `bun:"sms_notify_time"` }
User is a
func FindAllUsers ¶
FindAllUsers gets users from the db
func FindUserByEmail ¶
FindUserByEmail gets user from the db
func (*User) CheckPassword ¶
CheckPassword checks a password
func (*User) HashPassword ¶
HashPassword hashes a password