db

package
v0.0.0-...-672e050 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package db implements database models, insert and select functions for a postgres database using the "bun" ORM (github.com/uptrace/bun)

Index

Constants

This section is empty.

Variables

View Source
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

func InsertMultiChannelBackup(backup string, pubkey string) error

InsertMultiChannelBackup adds a static channel backup of all channels to the database

func InsertNode

func InsertNode(node *Node) error

InsertNode adds a lightning node to the database

func InsertUser

func InsertUser(user *User) error

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

func UpdateUserLastSent(user User) error

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

func FindAllChannels(ctx context.Context) ([]Channel, error)

FindAllChannels gets channel from the db

func FindChannelByNodeID

func FindChannelByNodeID(id int64) (Channel, error)

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

func FindAllNodes(ctx context.Context) ([]Node, error)

FindAllNodes gets node from the db

func FindNodeByPubkey

func FindNodeByPubkey(pubkey string) (Node, error)

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

func FindAllUsers(ctx context.Context) ([]User, error)

FindAllUsers gets users from the db

func FindUserByEmail

func FindUserByEmail(email string) (User, error)

FindUserByEmail gets user from the db

func FindUserByID

func FindUserByID(id int64) (User, error)

FindUserByID gets user from the db

func (*User) CheckPassword

func (user *User) CheckPassword(providedPassword string) error

CheckPassword checks a password

func (*User) HashPassword

func (user *User) HashPassword(password string) error

HashPassword hashes a password

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL