sqlite

package
v1.0.0-rc.9 Latest Latest
Warning

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

Go to latest
Published: May 10, 2025 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetThreshold added in v1.0.0

func GetThreshold() float64

GetThreshold returns the current threshold for the fuzzy search.

func IsURLCandidate added in v1.0.0

func IsURLCandidate(query string) bool

Returns true if the query value looks like a domain or a URL to match against a counterparty website or endpoint. This is not a strict URL check and may miss things that are valid URLs and catch things that are not; however it handles the most cases where http://example.com or example.com are passed in.

func NormURL added in v1.0.0

func NormURL(query string) string

Normalize the URL to a domain name and port, stripping off the scheme and path if present. This is used to assist a like query in the database for URL lookup.

func Rank added in v1.0.0

func Rank(term, query string) (int, float64)

Rank attempts to perform a substring match of the term on the query using unicode normalized case-insensitive fuzzy search. If the term is longer than the query then the query is matched to the term to find similarity regardless of substring containment. E.g. a query for example.com should match the example and a query for ample should match the same term. The distance and the similarity is returned.

func SetThreshold added in v1.0.0

func SetThreshold(t float64)

SetThreshold sets the threshold for the fuzzy search. The threshold must be a number between 0.0 and 1.0 where a higher threshold requires stricter matching. Setting a threshold of 0.0 will allow any rank fold matches.

Types

type Migration

type Migration struct {
	ID      int       // The unique sequence ID of the migration
	Name    string    // The human readable name of the migration
	Version string    // The package version when the migration was applied
	Created time.Time // The timestamp when the migration was applied
	Path    string    // The path of the migration in the filesystem
}

Migration is used to represent both a SQL migration from the embedded file system and a migration record in the database. These records are compared to ensure the database is as up to date as possible before the application starts.

func Migrations

func Migrations() (data []*Migration, err error)

Migrations returns the migration files from the embedded file system.

func (*Migration) SQL

func (m *Migration) SQL() (_ string, err error)

SQL loads the schema sql query from the embedded file on disk.

type PreparedTransaction

type PreparedTransaction struct {
	// contains filtered or unexported fields
}

func (*PreparedTransaction) AddCounterparty

func (p *PreparedTransaction) AddCounterparty(in *models.Counterparty) (err error)

TODO: this method needs to be tested extensively!!

func (*PreparedTransaction) AddEnvelope

func (p *PreparedTransaction) AddEnvelope(in *models.SecureEnvelope) (err error)

func (*PreparedTransaction) Commit

func (p *PreparedTransaction) Commit() error

func (*PreparedTransaction) CreateSunrise added in v0.28.0

func (p *PreparedTransaction) CreateSunrise(in *models.Sunrise) error

func (*PreparedTransaction) Created

func (p *PreparedTransaction) Created() bool

func (*PreparedTransaction) Fetch

func (p *PreparedTransaction) Fetch() (transaction *models.Transaction, err error)

func (*PreparedTransaction) LookupCounterparty added in v0.30.0

func (p *PreparedTransaction) LookupCounterparty(field, value string) (*models.Counterparty, error)

func (*PreparedTransaction) Rollback

func (p *PreparedTransaction) Rollback() error

func (*PreparedTransaction) Update

func (p *PreparedTransaction) Update(in *models.Transaction) (err error)

func (*PreparedTransaction) UpdateCounterparty added in v0.28.0

func (p *PreparedTransaction) UpdateCounterparty(in *models.Counterparty) (err error)

func (*PreparedTransaction) UpdateSunrise added in v0.28.0

func (p *PreparedTransaction) UpdateSunrise(in *models.Sunrise) error

type RankItem added in v1.0.0

type RankItem struct {
	ID         ulid.ULID
	Name       string
	Distance   int
	Similarity float64
}

type RankList added in v1.0.0

type RankList []RankItem

func (RankList) Len added in v1.0.0

func (r RankList) Len() int

func (RankList) Less added in v1.0.0

func (r RankList) Less(i, j int) bool

func (RankList) Swap added in v1.0.0

func (r RankList) Swap(i, j int)

type SearchRank added in v1.0.0

type SearchRank struct {
	// contains filtered or unexported fields
}

func NewSearchRank added in v1.0.0

func NewSearchRank(query string, limit int) *SearchRank

func (*SearchRank) Add added in v1.0.0

func (s *SearchRank) Add(id ulid.ULID, name string) bool

func (*SearchRank) Append added in v1.0.0

func (s *SearchRank) Append(item *RankItem) bool

func (*SearchRank) Results added in v1.0.0

func (s *SearchRank) Results() RankList

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store implements the store.Store interface using SQLite3 as the storage backend.

func Open

func Open(uri *dsn.DSN) (_ *Store, err error)

func (*Store) ArchiveTransaction added in v0.29.0

func (s *Store) ArchiveTransaction(ctx context.Context, transactionID uuid.UUID) (err error)

func (*Store) BeginTx

func (s *Store) BeginTx(ctx context.Context, opts *sql.TxOptions) (tx *sql.Tx, err error)

func (*Store) Close

func (s *Store) Close() error

func (*Store) CountTransactions added in v1.0.0

func (s *Store) CountTransactions(ctx context.Context) (counts *models.TransactionCounts, err error)

func (*Store) CreateAPIKey

func (s *Store) CreateAPIKey(ctx context.Context, key *models.APIKey) (err error)

func (*Store) CreateAccount

func (s *Store) CreateAccount(ctx context.Context, account *models.Account) (err error)

Create an account and any crypto addresses associated with the account.

func (*Store) CreateContact added in v0.28.0

func (s *Store) CreateContact(ctx context.Context, contact *models.Contact) (err error)

func (*Store) CreateCounterparty

func (s *Store) CreateCounterparty(ctx context.Context, counterparty *models.Counterparty) (err error)

func (*Store) CreateCryptoAddress

func (s *Store) CreateCryptoAddress(ctx context.Context, addr *models.CryptoAddress) (err error)

func (*Store) CreateDaybreak added in v1.0.0

func (s *Store) CreateDaybreak(ctx context.Context, counterparty *models.Counterparty) (err error)

Create the counterparty and any associated contacts in the database. If the counterparty already exists and it is a daybreak record, then the record will try to be fixed, otherwise an error will be returned; if a contact already exists associated with another counterparty, an error will be returned. The counterparty and all associated contacts will be created in a single transaction; if any contact fails to be created, the transaction will be rolled back and an error will be returned.

func (*Store) CreateSecureEnvelope

func (s *Store) CreateSecureEnvelope(ctx context.Context, env *models.SecureEnvelope) (err error)

func (*Store) CreateSunrise added in v0.28.0

func (s *Store) CreateSunrise(ctx context.Context, msg *models.Sunrise) (err error)

Create a sunrise message in the database.

func (*Store) CreateTransaction

func (s *Store) CreateTransaction(ctx context.Context, transaction *models.Transaction) (err error)

func (*Store) CreateUser

func (s *Store) CreateUser(ctx context.Context, user *models.User) (err error)

func (*Store) DeleteAPIKey

func (s *Store) DeleteAPIKey(ctx context.Context, keyID ulid.ULID) (err error)

func (*Store) DeleteAccount

func (s *Store) DeleteAccount(ctx context.Context, id ulid.ULID) (err error)

Delete account and all associated crypto addresses

func (*Store) DeleteContact added in v0.28.0

func (s *Store) DeleteContact(ctx context.Context, contactID, counterparty any) (err error)

Delete contact associated with the specified counterparty. The counterparty can either be a ULID of the counterparty or a pointer to the Counterparty model. If the ID is specified then the associated counterparty is used to identify the contact to delete. If the model is specified, then the contact is deleted from the model as well.

func (*Store) DeleteCounterparty

func (s *Store) DeleteCounterparty(ctx context.Context, counterpartyID ulid.ULID) (err error)

func (*Store) DeleteCryptoAddress

func (s *Store) DeleteCryptoAddress(ctx context.Context, accountID, cryptoAddressID ulid.ULID) (err error)

func (*Store) DeleteSecureEnvelope

func (s *Store) DeleteSecureEnvelope(ctx context.Context, txID uuid.UUID, envID ulid.ULID) (err error)

func (*Store) DeleteSunrise added in v0.28.0

func (s *Store) DeleteSunrise(ctx context.Context, id ulid.ULID) (err error)

Delete sunrise message from the database.

func (*Store) DeleteTransaction

func (s *Store) DeleteTransaction(ctx context.Context, id uuid.UUID) (err error)

func (*Store) DeleteUser

func (s *Store) DeleteUser(ctx context.Context, userID ulid.ULID) (err error)

func (*Store) GetOrCreateSunriseCounterparty added in v0.28.0

func (s *Store) GetOrCreateSunriseCounterparty(ctx context.Context, email, name string) (out *models.Counterparty, err error)

Get or create a sunrise counterparty from an email address.

func (*Store) InitializeSchema

func (s *Store) InitializeSchema(empty bool) (err error)

Initialize schema applies any unapplied migrations to the database and should be run when the database is first connected to. If empty is true then the migration table is created and all migrations are applied. If it is not true then the current migration of the database is fetched and all unapplied migrations are applied.

This method is called on Open() and should not be directly applied by the user.

func (*Store) LatestPayloadEnvelope added in v0.24.0

func (s *Store) LatestPayloadEnvelope(ctx context.Context, envelopeID uuid.UUID, direction enum.Direction) (env *models.SecureEnvelope, err error)

func (*Store) LatestSecureEnvelope added in v0.14.0

func (s *Store) LatestSecureEnvelope(ctx context.Context, envelopeID uuid.UUID, direction enum.Direction) (env *models.SecureEnvelope, err error)

func (*Store) ListAPIKeys

func (s *Store) ListAPIKeys(ctx context.Context, page *models.PageInfo) (out *models.APIKeyPage, err error)

func (*Store) ListAccountTransactions added in v1.0.0

func (s *Store) ListAccountTransactions(ctx context.Context, accountID ulid.ULID, page *models.TransactionPageInfo) (out *models.TransactionPage, err error)

List all transactions that have one of the account wallet addresses in either the originator or beneficiary wallet address fields.

func (*Store) ListAccounts

func (s *Store) ListAccounts(ctx context.Context, page *models.PageInfo) (out *models.AccountsPage, err error)

Retrieve summary information for all accounts for the specified page, omitting crypto addresses and any other irrelevant information.

func (*Store) ListContacts added in v0.28.0

func (s *Store) ListContacts(ctx context.Context, counterparty any, page *models.PageInfo) (out *models.ContactsPage, err error)

List contacts associated with the specified counterparty. The counterparty can either be a ULID of the counterparty ID or a pointer to the Counterparty model. If the ID is specified then the associated counterparty is retrieved from the database and attached to all returned contacts. If the model is specified, then the contacts, will be attached to the model.

func (*Store) ListCounterparties

func (s *Store) ListCounterparties(ctx context.Context, page *models.CounterpartyPageInfo) (out *models.CounterpartyPage, err error)

func (*Store) ListCounterpartySourceInfo

func (s *Store) ListCounterpartySourceInfo(ctx context.Context, source enum.Source) (out []*models.CounterpartySourceInfo, err error)

func (*Store) ListCryptoAddresses

func (s *Store) ListCryptoAddresses(ctx context.Context, accountID ulid.ULID, page *models.PageInfo) (out *models.CryptoAddressPage, err error)

List crypto addresses associated with the specified accountID.

func (*Store) ListDaybreak added in v1.0.0

func (s *Store) ListDaybreak(ctx context.Context) (out map[string]*models.CounterpartySourceInfo, err error)

ListDaybreak returns a map of all the daybreak counterparty sources in the database in order to match the directory ID to the internal database record ID.

func (*Store) ListSecureEnvelopes

func (s *Store) ListSecureEnvelopes(ctx context.Context, txID uuid.UUID, page *models.PageInfo) (out *models.SecureEnvelopePage, err error)

func (*Store) ListSunrise added in v0.28.0

func (s *Store) ListSunrise(ctx context.Context, page *models.PageInfo) (out *models.SunrisePage, err error)

Retrieve sunrise messages from the database and return them as a paginated list.

func (*Store) ListTransactions

func (s *Store) ListTransactions(ctx context.Context, page *models.TransactionPageInfo) (out *models.TransactionPage, err error)

func (*Store) ListUsers

func (s *Store) ListUsers(ctx context.Context, page *models.UserPageInfo) (out *models.UserPage, err error)

func (*Store) LookupAccount added in v1.0.0

func (s *Store) LookupAccount(ctx context.Context, cryptoAddress string) (account *models.Account, err error)

Lookup an account by an associated crypto address.

func (*Store) LookupCounterparty

func (s *Store) LookupCounterparty(ctx context.Context, field, value string) (counterparty *models.Counterparty, err error)

func (*Store) LookupRole added in v0.18.0

func (s *Store) LookupRole(ctx context.Context, role string) (model *models.Role, err error)

func (*Store) PrepareTransaction

func (s *Store) PrepareTransaction(ctx context.Context, envelopeID uuid.UUID) (_ models.PreparedTransaction, err error)

func (*Store) RetrieveAPIKey

func (s *Store) RetrieveAPIKey(ctx context.Context, clientIDOrKeyID any) (key *models.APIKey, err error)

func (*Store) RetrieveAccount

func (s *Store) RetrieveAccount(ctx context.Context, id ulid.ULID) (account *models.Account, err error)

Retrieve account detail information including all associated crypto addresses.

func (*Store) RetrieveContact added in v0.28.0

func (s *Store) RetrieveContact(ctx context.Context, contactID, counterparty any) (contact *models.Contact, err error)

Retrieve the contact with the specified ID and associate it with the specified counterparty. The counterparty can either be the ULID of the counterparty or a pointer to the Counterparty model. If the ID is specified then the associated counterparty is retrieved from the database and attached to the contact. Note that if a pointer to the Counterparty model is specified, it is not modified in place.

func (*Store) RetrieveCounterparty

func (s *Store) RetrieveCounterparty(ctx context.Context, counterpartyID ulid.ULID) (counterparty *models.Counterparty, err error)

func (*Store) RetrieveCryptoAddress

func (s *Store) RetrieveCryptoAddress(ctx context.Context, accountID, cryptoAddressID ulid.ULID) (addr *models.CryptoAddress, err error)

func (*Store) RetrieveSecureEnvelope

func (s *Store) RetrieveSecureEnvelope(ctx context.Context, txID uuid.UUID, envID ulid.ULID) (env *models.SecureEnvelope, err error)

func (*Store) RetrieveSunrise added in v0.28.0

func (s *Store) RetrieveSunrise(ctx context.Context, id ulid.ULID) (msg *models.Sunrise, err error)

Retrieve sunrise message detail information.

func (*Store) RetrieveTransaction

func (s *Store) RetrieveTransaction(ctx context.Context, id uuid.UUID) (transaction *models.Transaction, err error)

func (*Store) RetrieveUser

func (s *Store) RetrieveUser(ctx context.Context, emailOrUserID any) (user *models.User, err error)

func (*Store) SearchCounterparties added in v0.23.0

func (s *Store) SearchCounterparties(ctx context.Context, query *models.SearchQuery) (out *models.CounterpartyPage, err error)

SearchCounterparties uses an in-memory fuzzy search to find counterparties whose name matches the query using a unicode normalization, case-insensitive method. Additionally, if the query looks like a URL, it will also search for counterparties whose website or endpoint matches the query. The results are sorted by the distance of the match, with the closest matches first. The results are limited to the number of results specified in the query. Note that this in-memory fuzzy search is required for SQLite since there is no native search in SQLite without an extension.

func (*Store) SetUserLastLogin added in v0.18.0

func (s *Store) SetUserLastLogin(ctx context.Context, userID ulid.ULID, lastLogin time.Time) (err error)

func (*Store) SetUserPassword

func (s *Store) SetUserPassword(ctx context.Context, userID ulid.ULID, password string) (err error)

func (*Store) Stats added in v0.28.0

func (s *Store) Stats() sql.DBStats

func (*Store) TransactionState added in v1.0.0

func (s *Store) TransactionState(ctx context.Context, transactionID uuid.UUID) (archived bool, status enum.Status, err error)

func (*Store) UnarchiveTransaction added in v1.0.0

func (s *Store) UnarchiveTransaction(ctx context.Context, transactionID uuid.UUID) (err error)

func (*Store) UpdateAPIKey

func (s *Store) UpdateAPIKey(ctx context.Context, key *models.APIKey) (err error)

NOTE: the only thing that can be updated on an api key right now is last_seen

func (*Store) UpdateAccount

func (s *Store) UpdateAccount(ctx context.Context, a *models.Account) (err error)

Update account information; ignores any associated crypto addresses.

func (*Store) UpdateContact added in v0.28.0

func (s *Store) UpdateContact(ctx context.Context, contact *models.Contact) (err error)

func (*Store) UpdateCounterparty

func (s *Store) UpdateCounterparty(ctx context.Context, counterparty *models.Counterparty) (err error)

func (*Store) UpdateCryptoAddress

func (s *Store) UpdateCryptoAddress(ctx context.Context, addr *models.CryptoAddress) (err error)

func (*Store) UpdateDaybreak added in v1.0.0

func (s *Store) UpdateDaybreak(ctx context.Context, counterparty *models.Counterparty) (err error)

Updates the counterparty and any associated contacts in the database. All of the contacts will be be created or updated in this transaction. If a contact already exists associated with another counterparty, then it will be updated to use this counterparty. If any contact fails to be created or updated, the transaction will be rolled back and an error will be returned.

func (*Store) UpdateSecureEnvelope

func (s *Store) UpdateSecureEnvelope(ctx context.Context, env *models.SecureEnvelope) (err error)

func (*Store) UpdateSunrise added in v0.28.0

func (s *Store) UpdateSunrise(ctx context.Context, msg *models.Sunrise) (err error)

Update sunrise message information.

func (*Store) UpdateTransaction

func (s *Store) UpdateTransaction(ctx context.Context, t *models.Transaction) (err error)

func (*Store) UpdateUser

func (s *Store) UpdateUser(ctx context.Context, user *models.User) (err error)

func (*Store) UseTravelAddressFactory

func (s *Store) UseTravelAddressFactory(f models.TravelAddressFactory)

Jump to

Keyboard shortcuts

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