mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
Withdraw additional functionality (validation/submission/tracking) (#409)
* reworked request struct and exchange response started work on validation system * removed import cycle until work around * Added intial withdraw support via CLI added * Added Crypto command to gctcli * moved var declartion to single line * Test updates for binance and anx * All exchange tests have been updated test coverage added to validate * First pass at adding withdrawl select from database * started adding basic lru cache system * Added basic LRU cache including Add Get Remove Contains ContainsOrAdd Clear * wording changes on comments * removed exported var's in strut as they are not required * Added README * README updates * corrected ID on commands * rm line :D * merged in origin/cache * linter fixes (gofmt) * Added basic cache lookup to events * swapped to mutex over rwmutex updated comments * unexported getNewest & getOldest * unexported getNewest & getOldest * Updated comments and cited references in source * updated comments * WIP * Migrated exchange WithdrawFiat wrapper to new struct response * Migrated exchange WithdrawFiat wrapper to new struct response * started work on bank management * Added exchange level banking details back with migration to banking package * Removed broken tests for now * Added validation to bank accounts * removed duplicate bank details from withdraw struct * Test coverage increased * gofmt * merged upstream/master with clean up * First pass at adding command line linking to gctcli * added validation for crypto address, added gctcli support to retreive previous withdrawal requests * general cleanup * general cleanup * reordered imports * Increased test coverage moved to database sublogger * Pass incorrect currency no longer return error from c.CheckBankAccountConfig * remove TestMain() for now as other tests in this package will need to be reworked * Happy little race car * Reverted to upstream tests * Added test covarege for validation method, corrected response on cli protobuf * query clean up and removal of duplicated code * cleaned up queries into singlem ethod increased test coverage * Migrated international fund withdraw to new exchange response and added cache size override * Migrated international fund withdraw to new exchange response and added cache size override * Extended gctcli commands * lowered default cache to 25 * small code clean up * added get by date method * add returned error * cli commands cleaing return error on nil results to fix out of bounds * merged write & read helpers into one for test coverage and increased engine/withdraw test coverage * gofmt * Added test coverage for valid ID * removed unused param * converted to use timestamp package from protobuf * gofmt * use built in RFC3339 timestamp * remove setting of CreatedAt & UpdatedAt and allow ORm to take care of it * also use ptype on byid * code flow improvements * remove inverse conditional check and linters run * removed test data * removed comment * removed comment * also write failures to database for auditing * converted to use default time for start & end * Default to time.Now() minus 30 days * Default to time.Now() minus 30 days * small code clean up * fixed missing semicolon on migrations, code clean up * updated sqlite migrations * Added additonal check for exchange level bank account if global is not found * case sensativity fix for currency names * use correct compare * test coverage fixed * removed space * return pointer to banking.Account * return pointer to banking.Account * added else check back to validate() * Added empty string as default to migration over NULL due to retrivial of data
This commit is contained in:
@@ -37,6 +37,9 @@ var (
|
||||
// ErrNoDatabaseProvided error to display when no database is provided
|
||||
ErrNoDatabaseProvided = errors.New("no database provided")
|
||||
|
||||
// ErrDatabaseSupportDisabled error to display when no database is provided
|
||||
ErrDatabaseSupportDisabled = errors.New("database support is disabled")
|
||||
|
||||
// SupportedDrivers slice of supported database driver types
|
||||
SupportedDrivers = []string{DBSQLite, DBSQLite3, DBPostgreSQL}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ CREATE TABLE "audit_event" (
|
||||
identifier text not null,
|
||||
message text not null,
|
||||
created_at timestamp not null default CURRENT_TIMESTAMP
|
||||
|
||||
);
|
||||
-- +goose Down
|
||||
-- SQL in this section is executed when the migration is rolled back.
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
-- +goose Up
|
||||
-- SQL in this section is executed when the migration is applied.
|
||||
CREATE EXTENSION IF NOT EXISTS pgcrypto;
|
||||
CREATE TABLE IF NOT EXISTS withdrawal_history
|
||||
(
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
exchange text NOT NULL,
|
||||
exchange_id text NOT NULL,
|
||||
status varchar(255) NOT NULL,
|
||||
currency text NOT NULL,
|
||||
amount DOUBLE PRECISION NOT NULL,
|
||||
description text NULL,
|
||||
withdraw_type integer NOT NULL,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT (now() at time zone 'utc'),
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT (now() at time zone 'utc')
|
||||
);
|
||||
-- +goose Down
|
||||
-- SQL in this section is executed when the migration is rolled back.
|
||||
DROP TABLE IF EXISTS withdrawal_history;
|
||||
@@ -0,0 +1,19 @@
|
||||
-- +goose Up
|
||||
-- SQL in this section is executed when the migration is applied.
|
||||
CREATE TABLE IF NOT EXISTS "withdrawal_history"
|
||||
(
|
||||
id text PRIMARY KEY NOT NULL,
|
||||
exchange text NOT NULL,
|
||||
exchange_id text NOT NULL,
|
||||
status text NOT NULL,
|
||||
currency text NOT NULL,
|
||||
amount real NOT NULL,
|
||||
description text NULL,
|
||||
withdraw_type integer NOT NULL,
|
||||
created_at timestamp not null default CURRENT_TIMESTAMP,
|
||||
updated_at timestamp not null default CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- +goose Down
|
||||
-- SQL in this section is executed when the migration is rolled back.
|
||||
DROP TABLE IF EXISTS withdrawal_history;
|
||||
@@ -0,0 +1,18 @@
|
||||
-- +goose Up
|
||||
-- SQL in this section is executed when the migration is applied.
|
||||
CREATE TABLE IF NOT EXISTS withdrawal_fiat
|
||||
(
|
||||
id bigserial PRIMARY KEY NOT NULL,
|
||||
withdrawal_fiat_id uuid REFERENCES withdrawal_history(id) ON DELETE RESTRICT,
|
||||
bank_name text not null,
|
||||
bank_address text not null,
|
||||
bank_account_name text not null,
|
||||
bank_account_number text not null,
|
||||
bsb text not null DEFAULT '',
|
||||
swift_code text not null DEFAULT '',
|
||||
iban text not null DEFAULT '',
|
||||
bank_code DOUBLE PRECISION not null
|
||||
);
|
||||
-- +goose Down
|
||||
-- SQL in this section is executed when the migration is rolled back.
|
||||
DROP TABLE IF EXISTS withdrawal_fiat;
|
||||
@@ -0,0 +1,19 @@
|
||||
-- +goose Up
|
||||
-- SQL in this section is executed when the migration is applied.
|
||||
CREATE TABLE IF NOT EXISTS "withdrawal_fiat"
|
||||
(
|
||||
id integer not null primary key,
|
||||
bank_name text not null,
|
||||
bank_address text not null,
|
||||
bank_account_name text not null,
|
||||
bank_account_number text not null,
|
||||
bsb text not null DEFAULT '',
|
||||
swift_code text not null DEFAULT '',
|
||||
iban text not null DEFAULT '',
|
||||
bank_code real not null,
|
||||
withdrawal_history_id text NOT NULL,
|
||||
FOREIGN KEY(withdrawal_history_id) REFERENCES withdrawal_history(id) ON DELETE RESTRICT
|
||||
);
|
||||
-- +goose Down
|
||||
-- SQL in this section is executed when the migration is rolled back.
|
||||
DROP TABLE IF EXISTS withdrawal_fiat;
|
||||
@@ -0,0 +1,13 @@
|
||||
-- +goose Up
|
||||
-- SQL in this section is executed when the migration is applied.
|
||||
CREATE TABLE IF NOT EXISTS withdrawal_crypto
|
||||
(
|
||||
id bigserial PRIMARY KEY NOT NULL,
|
||||
withdrawal_crypto_id uuid REFERENCES withdrawal_history(id) ON DELETE RESTRICT,
|
||||
address text NOT NULL,
|
||||
address_tag text NULL,
|
||||
fee DOUBLE PRECISION NOT NULL
|
||||
);
|
||||
-- +goose Down
|
||||
-- SQL in this section is executed when the migration is rolled back.
|
||||
DROP TABLE IF EXISTS withdrawal_crypto;
|
||||
@@ -0,0 +1,14 @@
|
||||
-- +goose Up
|
||||
-- SQL in this section is executed when the migration is applied.
|
||||
CREATE TABLE IF NOT EXISTS withdrawal_crypto
|
||||
(
|
||||
id integer not null primary key,
|
||||
address text NOT NULL,
|
||||
address_tag text NULL,
|
||||
fee real NOT NULL,
|
||||
withdrawal_history_id text NOT NULL,
|
||||
FOREIGN KEY(withdrawal_history_id) REFERENCES withdrawal_history(id) ON DELETE RESTRICT
|
||||
);
|
||||
-- +goose Down
|
||||
-- SQL in this section is executed when the migration is rolled back.
|
||||
DROP TABLE IF EXISTS withdrawal_crypto;
|
||||
@@ -14,56 +14,67 @@ import "testing"
|
||||
func TestParent(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEvents)
|
||||
t.Run("Scripts", testScripts)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistories)
|
||||
}
|
||||
|
||||
func TestDelete(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsDelete)
|
||||
t.Run("Scripts", testScriptsDelete)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesDelete)
|
||||
}
|
||||
|
||||
func TestQueryDeleteAll(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsQueryDeleteAll)
|
||||
t.Run("Scripts", testScriptsQueryDeleteAll)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesQueryDeleteAll)
|
||||
}
|
||||
|
||||
func TestSliceDeleteAll(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsSliceDeleteAll)
|
||||
t.Run("Scripts", testScriptsSliceDeleteAll)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesSliceDeleteAll)
|
||||
}
|
||||
|
||||
func TestExists(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsExists)
|
||||
t.Run("Scripts", testScriptsExists)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesExists)
|
||||
}
|
||||
|
||||
func TestFind(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsFind)
|
||||
t.Run("Scripts", testScriptsFind)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesFind)
|
||||
}
|
||||
|
||||
func TestBind(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsBind)
|
||||
t.Run("Scripts", testScriptsBind)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesBind)
|
||||
}
|
||||
|
||||
func TestOne(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsOne)
|
||||
t.Run("Scripts", testScriptsOne)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesOne)
|
||||
}
|
||||
|
||||
func TestAll(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsAll)
|
||||
t.Run("Scripts", testScriptsAll)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesAll)
|
||||
}
|
||||
|
||||
func TestCount(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsCount)
|
||||
t.Run("Scripts", testScriptsCount)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesCount)
|
||||
}
|
||||
|
||||
func TestHooks(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsHooks)
|
||||
t.Run("Scripts", testScriptsHooks)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesHooks)
|
||||
}
|
||||
|
||||
func TestInsert(t *testing.T) {
|
||||
@@ -71,6 +82,8 @@ func TestInsert(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsInsertWhitelist)
|
||||
t.Run("Scripts", testScriptsInsert)
|
||||
t.Run("Scripts", testScriptsInsertWhitelist)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesInsert)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesInsertWhitelist)
|
||||
}
|
||||
|
||||
// TestToOne tests cannot be run in parallel
|
||||
@@ -116,24 +129,29 @@ func TestToManyRemove(t *testing.T) {}
|
||||
func TestReload(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsReload)
|
||||
t.Run("Scripts", testScriptsReload)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesReload)
|
||||
}
|
||||
|
||||
func TestReloadAll(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsReloadAll)
|
||||
t.Run("Scripts", testScriptsReloadAll)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesReloadAll)
|
||||
}
|
||||
|
||||
func TestSelect(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsSelect)
|
||||
t.Run("Scripts", testScriptsSelect)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesSelect)
|
||||
}
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsUpdate)
|
||||
t.Run("Scripts", testScriptsUpdate)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesUpdate)
|
||||
}
|
||||
|
||||
func TestSliceUpdateAll(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsSliceUpdateAll)
|
||||
t.Run("Scripts", testScriptsSliceUpdateAll)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesSliceUpdateAll)
|
||||
}
|
||||
|
||||
@@ -4,11 +4,17 @@
|
||||
package postgres
|
||||
|
||||
var TableNames = struct {
|
||||
AuditEvent string
|
||||
Script string
|
||||
ScriptExecution string
|
||||
AuditEvent string
|
||||
Script string
|
||||
ScriptExecution string
|
||||
WithdrawalCrypto string
|
||||
WithdrawalFiat string
|
||||
WithdrawalHistory string
|
||||
}{
|
||||
AuditEvent: "audit_event",
|
||||
Script: "script",
|
||||
ScriptExecution: "script_execution",
|
||||
AuditEvent: "audit_event",
|
||||
Script: "script",
|
||||
ScriptExecution: "script_execution",
|
||||
WithdrawalCrypto: "withdrawal_crypto",
|
||||
WithdrawalFiat: "withdrawal_fiat",
|
||||
WithdrawalHistory: "withdrawal_history",
|
||||
}
|
||||
|
||||
@@ -8,4 +8,5 @@ import "testing"
|
||||
func TestUpsert(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsUpsert)
|
||||
t.Run("Scripts", testScriptsUpsert)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesUpsert)
|
||||
}
|
||||
|
||||
1096
database/models/postgres/withdrawal_crypto.go
Normal file
1096
database/models/postgres/withdrawal_crypto.go
Normal file
File diff suppressed because it is too large
Load Diff
892
database/models/postgres/withdrawal_crypto_test.go
Normal file
892
database/models/postgres/withdrawal_crypto_test.go
Normal file
@@ -0,0 +1,892 @@
|
||||
// Code generated by SQLBoiler 3.5.0-gct (https://github.com/thrasher-corp/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-corp/sqlboiler/boil"
|
||||
"github.com/thrasher-corp/sqlboiler/queries"
|
||||
"github.com/thrasher-corp/sqlboiler/randomize"
|
||||
"github.com/thrasher-corp/sqlboiler/strmangle"
|
||||
)
|
||||
|
||||
var (
|
||||
// Relationships sometimes use the reflection helper queries.Equal/queries.Assign
|
||||
// so force a package dependency in case they don't.
|
||||
_ = queries.Equal
|
||||
)
|
||||
|
||||
func testWithdrawalCryptos(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
query := WithdrawalCryptos()
|
||||
|
||||
if query.Query == nil {
|
||||
t.Error("expected a query, got nothing")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosDelete(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Delete(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosQueryDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := WithdrawalCryptos().DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosSliceDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := WithdrawalCryptoSlice{o}
|
||||
|
||||
if rowsAff, err := slice.DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosExists(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
e, err := WithdrawalCryptoExists(ctx, tx, o.ID)
|
||||
if err != nil {
|
||||
t.Errorf("Unable to check if WithdrawalCrypto exists: %s", err)
|
||||
}
|
||||
if !e {
|
||||
t.Errorf("Expected WithdrawalCryptoExists to return true, but got false.")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosFind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
withdrawalCryptoFound, err := FindWithdrawalCrypto(ctx, tx, o.ID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if withdrawalCryptoFound == nil {
|
||||
t.Error("want a record, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosBind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = WithdrawalCryptos().Bind(ctx, tx, o); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosOne(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if x, err := WithdrawalCryptos().One(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if x == nil {
|
||||
t.Error("expected to get a non nil record")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
withdrawalCryptoOne := &WithdrawalCrypto{}
|
||||
withdrawalCryptoTwo := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, withdrawalCryptoOne, withdrawalCryptoDBTypes, false, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, withdrawalCryptoTwo, withdrawalCryptoDBTypes, false, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = withdrawalCryptoOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = withdrawalCryptoTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := WithdrawalCryptos().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 2 {
|
||||
t.Error("want 2 records, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosCount(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
seed := randomize.NewSeed()
|
||||
withdrawalCryptoOne := &WithdrawalCrypto{}
|
||||
withdrawalCryptoTwo := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, withdrawalCryptoOne, withdrawalCryptoDBTypes, false, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, withdrawalCryptoTwo, withdrawalCryptoDBTypes, false, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = withdrawalCryptoOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = withdrawalCryptoTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 2 {
|
||||
t.Error("want 2 records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func withdrawalCryptoBeforeInsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoAfterInsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoAfterSelectHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoBeforeUpdateHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoAfterUpdateHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoBeforeDeleteHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoAfterDeleteHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoBeforeUpsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoAfterUpsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosHooks(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
empty := &WithdrawalCrypto{}
|
||||
o := &WithdrawalCrypto{}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, false); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto object: %s", err)
|
||||
}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.BeforeInsertHook, withdrawalCryptoBeforeInsertHook)
|
||||
if err = o.doBeforeInsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeInsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeInsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoBeforeInsertHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.AfterInsertHook, withdrawalCryptoAfterInsertHook)
|
||||
if err = o.doAfterInsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterInsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterInsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoAfterInsertHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.AfterSelectHook, withdrawalCryptoAfterSelectHook)
|
||||
if err = o.doAfterSelectHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterSelectHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterSelectHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoAfterSelectHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.BeforeUpdateHook, withdrawalCryptoBeforeUpdateHook)
|
||||
if err = o.doBeforeUpdateHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeUpdateHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeUpdateHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoBeforeUpdateHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.AfterUpdateHook, withdrawalCryptoAfterUpdateHook)
|
||||
if err = o.doAfterUpdateHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterUpdateHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterUpdateHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoAfterUpdateHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.BeforeDeleteHook, withdrawalCryptoBeforeDeleteHook)
|
||||
if err = o.doBeforeDeleteHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeDeleteHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeDeleteHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoBeforeDeleteHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.AfterDeleteHook, withdrawalCryptoAfterDeleteHook)
|
||||
if err = o.doAfterDeleteHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterDeleteHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterDeleteHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoAfterDeleteHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.BeforeUpsertHook, withdrawalCryptoBeforeUpsertHook)
|
||||
if err = o.doBeforeUpsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeUpsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeUpsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoBeforeUpsertHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.AfterUpsertHook, withdrawalCryptoAfterUpsertHook)
|
||||
if err = o.doAfterUpsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterUpsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterUpsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoAfterUpsertHooks = []WithdrawalCryptoHook{}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosInsert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosInsertWhitelist(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Whitelist(withdrawalCryptoColumnsWithoutDefault...)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptoToOneWithdrawalHistoryUsingWithdrawalCrypto(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var local WithdrawalCrypto
|
||||
var foreign WithdrawalHistory
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err := randomize.Struct(seed, &local, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
if err := randomize.Struct(seed, &foreign, withdrawalHistoryDBTypes, false, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
if err := foreign.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
queries.Assign(&local.WithdrawalCryptoID, foreign.ID)
|
||||
if err := local.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
check, err := local.WithdrawalCrypto().One(ctx, tx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !queries.Equal(check.ID, foreign.ID) {
|
||||
t.Errorf("want: %v, got %v", foreign.ID, check.ID)
|
||||
}
|
||||
|
||||
slice := WithdrawalCryptoSlice{&local}
|
||||
if err = local.L.LoadWithdrawalCrypto(ctx, tx, false, (*[]*WithdrawalCrypto)(&slice), nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.WithdrawalCrypto == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
|
||||
local.R.WithdrawalCrypto = nil
|
||||
if err = local.L.LoadWithdrawalCrypto(ctx, tx, true, &local, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.WithdrawalCrypto == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptoToOneSetOpWithdrawalHistoryUsingWithdrawalCrypto(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var a WithdrawalCrypto
|
||||
var b, c WithdrawalHistory
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, &a, withdrawalCryptoDBTypes, false, strmangle.SetComplement(withdrawalCryptoPrimaryKeyColumns, withdrawalCryptoColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &b, withdrawalHistoryDBTypes, false, strmangle.SetComplement(withdrawalHistoryPrimaryKeyColumns, withdrawalHistoryColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &c, withdrawalHistoryDBTypes, false, strmangle.SetComplement(withdrawalHistoryPrimaryKeyColumns, withdrawalHistoryColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for i, x := range []*WithdrawalHistory{&b, &c} {
|
||||
err = a.SetWithdrawalCrypto(ctx, tx, i != 0, x)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if a.R.WithdrawalCrypto != x {
|
||||
t.Error("relationship struct not set to correct value")
|
||||
}
|
||||
|
||||
if x.R.WithdrawalCryptoWithdrawalCryptos[0] != &a {
|
||||
t.Error("failed to append to foreign relationship struct")
|
||||
}
|
||||
if !queries.Equal(a.WithdrawalCryptoID, x.ID) {
|
||||
t.Error("foreign key was wrong value", a.WithdrawalCryptoID)
|
||||
}
|
||||
|
||||
zero := reflect.Zero(reflect.TypeOf(a.WithdrawalCryptoID))
|
||||
reflect.Indirect(reflect.ValueOf(&a.WithdrawalCryptoID)).Set(zero)
|
||||
|
||||
if err = a.Reload(ctx, tx); err != nil {
|
||||
t.Fatal("failed to reload", err)
|
||||
}
|
||||
|
||||
if !queries.Equal(a.WithdrawalCryptoID, x.ID) {
|
||||
t.Error("foreign key was wrong value", a.WithdrawalCryptoID, x.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptoToOneRemoveOpWithdrawalHistoryUsingWithdrawalCrypto(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var a WithdrawalCrypto
|
||||
var b WithdrawalHistory
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, &a, withdrawalCryptoDBTypes, false, strmangle.SetComplement(withdrawalCryptoPrimaryKeyColumns, withdrawalCryptoColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &b, withdrawalHistoryDBTypes, false, strmangle.SetComplement(withdrawalHistoryPrimaryKeyColumns, withdrawalHistoryColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err = a.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err = a.SetWithdrawalCrypto(ctx, tx, true, &b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err = a.RemoveWithdrawalCrypto(ctx, tx, &b); err != nil {
|
||||
t.Error("failed to remove relationship")
|
||||
}
|
||||
|
||||
count, err := a.WithdrawalCrypto().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if count != 0 {
|
||||
t.Error("want no relationships remaining")
|
||||
}
|
||||
|
||||
if a.R.WithdrawalCrypto != nil {
|
||||
t.Error("R struct entry should be nil")
|
||||
}
|
||||
|
||||
if !queries.IsValuerNil(a.WithdrawalCryptoID) {
|
||||
t.Error("foreign key value should be nil")
|
||||
}
|
||||
|
||||
if len(b.R.WithdrawalCryptoWithdrawalCryptos) != 0 {
|
||||
t.Error("failed to remove a from b's relationships")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosReload(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = o.Reload(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosReloadAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := WithdrawalCryptoSlice{o}
|
||||
|
||||
if err = slice.ReloadAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosSelect(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := WithdrawalCryptos().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 1 {
|
||||
t.Error("want one record, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
withdrawalCryptoDBTypes = map[string]string{`ID`: `bigint`, `WithdrawalCryptoID`: `uuid`, `Address`: `text`, `AddressTag`: `text`, `Fee`: `double precision`}
|
||||
_ = bytes.MinRead
|
||||
)
|
||||
|
||||
func testWithdrawalCryptosUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if 0 == len(withdrawalCryptoPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with no primary key columns")
|
||||
}
|
||||
if len(withdrawalCryptoAllColumns) == len(withdrawalCryptoPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Update(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only affect one row but affected", rowsAff)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosSliceUpdateAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if len(withdrawalCryptoAllColumns) == len(withdrawalCryptoPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
// Remove Primary keys and unique columns from what we plan to update
|
||||
var fields []string
|
||||
if strmangle.StringSliceMatch(withdrawalCryptoAllColumns, withdrawalCryptoPrimaryKeyColumns) {
|
||||
fields = withdrawalCryptoAllColumns
|
||||
} else {
|
||||
fields = strmangle.SetComplement(
|
||||
withdrawalCryptoAllColumns,
|
||||
withdrawalCryptoPrimaryKeyColumns,
|
||||
)
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
typ := reflect.TypeOf(o).Elem()
|
||||
n := typ.NumField()
|
||||
|
||||
updateMap := M{}
|
||||
for _, col := range fields {
|
||||
for i := 0; i < n; i++ {
|
||||
f := typ.Field(i)
|
||||
if f.Tag.Get("boil") == col {
|
||||
updateMap[col] = value.Field(i).Interface()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
slice := WithdrawalCryptoSlice{o}
|
||||
if rowsAff, err := slice.UpdateAll(ctx, tx, updateMap); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("wanted one record updated but got", rowsAff)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosUpsert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if len(withdrawalCryptoAllColumns) == len(withdrawalCryptoPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
// Attempt the INSERT side of an UPSERT
|
||||
o := WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, &o, withdrawalCryptoDBTypes, true); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Upsert(ctx, tx, false, nil, boil.Infer(), boil.Infer()); err != nil {
|
||||
t.Errorf("Unable to upsert WithdrawalCrypto: %s", err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
// Attempt the UPDATE side of an UPSERT
|
||||
if err = randomize.Struct(seed, &o, withdrawalCryptoDBTypes, false, withdrawalCryptoPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
if err = o.Upsert(ctx, tx, true, nil, boil.Infer(), boil.Infer()); err != nil {
|
||||
t.Errorf("Unable to upsert WithdrawalCrypto: %s", err)
|
||||
}
|
||||
|
||||
count, err = WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
1106
database/models/postgres/withdrawal_fiat.go
Normal file
1106
database/models/postgres/withdrawal_fiat.go
Normal file
File diff suppressed because it is too large
Load Diff
892
database/models/postgres/withdrawal_fiat_test.go
Normal file
892
database/models/postgres/withdrawal_fiat_test.go
Normal file
@@ -0,0 +1,892 @@
|
||||
// Code generated by SQLBoiler 3.5.0-gct (https://github.com/thrasher-corp/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-corp/sqlboiler/boil"
|
||||
"github.com/thrasher-corp/sqlboiler/queries"
|
||||
"github.com/thrasher-corp/sqlboiler/randomize"
|
||||
"github.com/thrasher-corp/sqlboiler/strmangle"
|
||||
)
|
||||
|
||||
var (
|
||||
// Relationships sometimes use the reflection helper queries.Equal/queries.Assign
|
||||
// so force a package dependency in case they don't.
|
||||
_ = queries.Equal
|
||||
)
|
||||
|
||||
func testWithdrawalFiats(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
query := WithdrawalFiats()
|
||||
|
||||
if query.Query == nil {
|
||||
t.Error("expected a query, got nothing")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsDelete(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Delete(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsQueryDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := WithdrawalFiats().DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsSliceDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := WithdrawalFiatSlice{o}
|
||||
|
||||
if rowsAff, err := slice.DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsExists(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
e, err := WithdrawalFiatExists(ctx, tx, o.ID)
|
||||
if err != nil {
|
||||
t.Errorf("Unable to check if WithdrawalFiat exists: %s", err)
|
||||
}
|
||||
if !e {
|
||||
t.Errorf("Expected WithdrawalFiatExists to return true, but got false.")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsFind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
withdrawalFiatFound, err := FindWithdrawalFiat(ctx, tx, o.ID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if withdrawalFiatFound == nil {
|
||||
t.Error("want a record, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsBind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = WithdrawalFiats().Bind(ctx, tx, o); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsOne(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if x, err := WithdrawalFiats().One(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if x == nil {
|
||||
t.Error("expected to get a non nil record")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
withdrawalFiatOne := &WithdrawalFiat{}
|
||||
withdrawalFiatTwo := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, withdrawalFiatOne, withdrawalFiatDBTypes, false, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, withdrawalFiatTwo, withdrawalFiatDBTypes, false, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = withdrawalFiatOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = withdrawalFiatTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := WithdrawalFiats().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 2 {
|
||||
t.Error("want 2 records, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsCount(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
seed := randomize.NewSeed()
|
||||
withdrawalFiatOne := &WithdrawalFiat{}
|
||||
withdrawalFiatTwo := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, withdrawalFiatOne, withdrawalFiatDBTypes, false, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, withdrawalFiatTwo, withdrawalFiatDBTypes, false, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = withdrawalFiatOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = withdrawalFiatTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 2 {
|
||||
t.Error("want 2 records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func withdrawalFiatBeforeInsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatAfterInsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatAfterSelectHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatBeforeUpdateHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatAfterUpdateHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatBeforeDeleteHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatAfterDeleteHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatBeforeUpsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatAfterUpsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsHooks(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
empty := &WithdrawalFiat{}
|
||||
o := &WithdrawalFiat{}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, false); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat object: %s", err)
|
||||
}
|
||||
|
||||
AddWithdrawalFiatHook(boil.BeforeInsertHook, withdrawalFiatBeforeInsertHook)
|
||||
if err = o.doBeforeInsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeInsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeInsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatBeforeInsertHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.AfterInsertHook, withdrawalFiatAfterInsertHook)
|
||||
if err = o.doAfterInsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterInsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterInsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatAfterInsertHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.AfterSelectHook, withdrawalFiatAfterSelectHook)
|
||||
if err = o.doAfterSelectHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterSelectHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterSelectHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatAfterSelectHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.BeforeUpdateHook, withdrawalFiatBeforeUpdateHook)
|
||||
if err = o.doBeforeUpdateHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeUpdateHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeUpdateHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatBeforeUpdateHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.AfterUpdateHook, withdrawalFiatAfterUpdateHook)
|
||||
if err = o.doAfterUpdateHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterUpdateHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterUpdateHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatAfterUpdateHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.BeforeDeleteHook, withdrawalFiatBeforeDeleteHook)
|
||||
if err = o.doBeforeDeleteHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeDeleteHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeDeleteHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatBeforeDeleteHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.AfterDeleteHook, withdrawalFiatAfterDeleteHook)
|
||||
if err = o.doAfterDeleteHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterDeleteHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterDeleteHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatAfterDeleteHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.BeforeUpsertHook, withdrawalFiatBeforeUpsertHook)
|
||||
if err = o.doBeforeUpsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeUpsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeUpsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatBeforeUpsertHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.AfterUpsertHook, withdrawalFiatAfterUpsertHook)
|
||||
if err = o.doAfterUpsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterUpsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterUpsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatAfterUpsertHooks = []WithdrawalFiatHook{}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsInsert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsInsertWhitelist(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Whitelist(withdrawalFiatColumnsWithoutDefault...)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatToOneWithdrawalHistoryUsingWithdrawalFiat(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var local WithdrawalFiat
|
||||
var foreign WithdrawalHistory
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err := randomize.Struct(seed, &local, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
if err := randomize.Struct(seed, &foreign, withdrawalHistoryDBTypes, false, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
if err := foreign.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
queries.Assign(&local.WithdrawalFiatID, foreign.ID)
|
||||
if err := local.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
check, err := local.WithdrawalFiat().One(ctx, tx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !queries.Equal(check.ID, foreign.ID) {
|
||||
t.Errorf("want: %v, got %v", foreign.ID, check.ID)
|
||||
}
|
||||
|
||||
slice := WithdrawalFiatSlice{&local}
|
||||
if err = local.L.LoadWithdrawalFiat(ctx, tx, false, (*[]*WithdrawalFiat)(&slice), nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.WithdrawalFiat == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
|
||||
local.R.WithdrawalFiat = nil
|
||||
if err = local.L.LoadWithdrawalFiat(ctx, tx, true, &local, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.WithdrawalFiat == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatToOneSetOpWithdrawalHistoryUsingWithdrawalFiat(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var a WithdrawalFiat
|
||||
var b, c WithdrawalHistory
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, &a, withdrawalFiatDBTypes, false, strmangle.SetComplement(withdrawalFiatPrimaryKeyColumns, withdrawalFiatColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &b, withdrawalHistoryDBTypes, false, strmangle.SetComplement(withdrawalHistoryPrimaryKeyColumns, withdrawalHistoryColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &c, withdrawalHistoryDBTypes, false, strmangle.SetComplement(withdrawalHistoryPrimaryKeyColumns, withdrawalHistoryColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for i, x := range []*WithdrawalHistory{&b, &c} {
|
||||
err = a.SetWithdrawalFiat(ctx, tx, i != 0, x)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if a.R.WithdrawalFiat != x {
|
||||
t.Error("relationship struct not set to correct value")
|
||||
}
|
||||
|
||||
if x.R.WithdrawalFiatWithdrawalFiats[0] != &a {
|
||||
t.Error("failed to append to foreign relationship struct")
|
||||
}
|
||||
if !queries.Equal(a.WithdrawalFiatID, x.ID) {
|
||||
t.Error("foreign key was wrong value", a.WithdrawalFiatID)
|
||||
}
|
||||
|
||||
zero := reflect.Zero(reflect.TypeOf(a.WithdrawalFiatID))
|
||||
reflect.Indirect(reflect.ValueOf(&a.WithdrawalFiatID)).Set(zero)
|
||||
|
||||
if err = a.Reload(ctx, tx); err != nil {
|
||||
t.Fatal("failed to reload", err)
|
||||
}
|
||||
|
||||
if !queries.Equal(a.WithdrawalFiatID, x.ID) {
|
||||
t.Error("foreign key was wrong value", a.WithdrawalFiatID, x.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatToOneRemoveOpWithdrawalHistoryUsingWithdrawalFiat(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var a WithdrawalFiat
|
||||
var b WithdrawalHistory
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, &a, withdrawalFiatDBTypes, false, strmangle.SetComplement(withdrawalFiatPrimaryKeyColumns, withdrawalFiatColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &b, withdrawalHistoryDBTypes, false, strmangle.SetComplement(withdrawalHistoryPrimaryKeyColumns, withdrawalHistoryColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err = a.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err = a.SetWithdrawalFiat(ctx, tx, true, &b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err = a.RemoveWithdrawalFiat(ctx, tx, &b); err != nil {
|
||||
t.Error("failed to remove relationship")
|
||||
}
|
||||
|
||||
count, err := a.WithdrawalFiat().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if count != 0 {
|
||||
t.Error("want no relationships remaining")
|
||||
}
|
||||
|
||||
if a.R.WithdrawalFiat != nil {
|
||||
t.Error("R struct entry should be nil")
|
||||
}
|
||||
|
||||
if !queries.IsValuerNil(a.WithdrawalFiatID) {
|
||||
t.Error("foreign key value should be nil")
|
||||
}
|
||||
|
||||
if len(b.R.WithdrawalFiatWithdrawalFiats) != 0 {
|
||||
t.Error("failed to remove a from b's relationships")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsReload(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = o.Reload(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsReloadAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := WithdrawalFiatSlice{o}
|
||||
|
||||
if err = slice.ReloadAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsSelect(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := WithdrawalFiats().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 1 {
|
||||
t.Error("want one record, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
withdrawalFiatDBTypes = map[string]string{`ID`: `bigint`, `WithdrawalFiatID`: `uuid`, `BankName`: `text`, `BankAddress`: `text`, `BankAccountName`: `text`, `BankAccountNumber`: `text`, `BSB`: `text`, `SwiftCode`: `text`, `Iban`: `text`, `BankCode`: `double precision`}
|
||||
_ = bytes.MinRead
|
||||
)
|
||||
|
||||
func testWithdrawalFiatsUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if 0 == len(withdrawalFiatPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with no primary key columns")
|
||||
}
|
||||
if len(withdrawalFiatAllColumns) == len(withdrawalFiatPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Update(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only affect one row but affected", rowsAff)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsSliceUpdateAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if len(withdrawalFiatAllColumns) == len(withdrawalFiatPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
// Remove Primary keys and unique columns from what we plan to update
|
||||
var fields []string
|
||||
if strmangle.StringSliceMatch(withdrawalFiatAllColumns, withdrawalFiatPrimaryKeyColumns) {
|
||||
fields = withdrawalFiatAllColumns
|
||||
} else {
|
||||
fields = strmangle.SetComplement(
|
||||
withdrawalFiatAllColumns,
|
||||
withdrawalFiatPrimaryKeyColumns,
|
||||
)
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
typ := reflect.TypeOf(o).Elem()
|
||||
n := typ.NumField()
|
||||
|
||||
updateMap := M{}
|
||||
for _, col := range fields {
|
||||
for i := 0; i < n; i++ {
|
||||
f := typ.Field(i)
|
||||
if f.Tag.Get("boil") == col {
|
||||
updateMap[col] = value.Field(i).Interface()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
slice := WithdrawalFiatSlice{o}
|
||||
if rowsAff, err := slice.UpdateAll(ctx, tx, updateMap); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("wanted one record updated but got", rowsAff)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsUpsert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if len(withdrawalFiatAllColumns) == len(withdrawalFiatPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
// Attempt the INSERT side of an UPSERT
|
||||
o := WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, &o, withdrawalFiatDBTypes, true); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Upsert(ctx, tx, false, nil, boil.Infer(), boil.Infer()); err != nil {
|
||||
t.Errorf("Unable to upsert WithdrawalFiat: %s", err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
// Attempt the UPDATE side of an UPSERT
|
||||
if err = randomize.Struct(seed, &o, withdrawalFiatDBTypes, false, withdrawalFiatPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
if err = o.Upsert(ctx, tx, true, nil, boil.Infer(), boil.Infer()); err != nil {
|
||||
t.Errorf("Unable to upsert WithdrawalFiat: %s", err)
|
||||
}
|
||||
|
||||
count, err = WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
1406
database/models/postgres/withdrawal_history.go
Normal file
1406
database/models/postgres/withdrawal_history.go
Normal file
File diff suppressed because it is too large
Load Diff
1388
database/models/postgres/withdrawal_history_test.go
Normal file
1388
database/models/postgres/withdrawal_history_test.go
Normal file
File diff suppressed because it is too large
Load Diff
@@ -15,66 +15,99 @@ func TestParent(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEvents)
|
||||
t.Run("Scripts", testScripts)
|
||||
t.Run("ScriptExecutions", testScriptExecutions)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptos)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiats)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistories)
|
||||
}
|
||||
|
||||
func TestDelete(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsDelete)
|
||||
t.Run("Scripts", testScriptsDelete)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsDelete)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosDelete)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsDelete)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesDelete)
|
||||
}
|
||||
|
||||
func TestQueryDeleteAll(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsQueryDeleteAll)
|
||||
t.Run("Scripts", testScriptsQueryDeleteAll)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsQueryDeleteAll)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosQueryDeleteAll)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsQueryDeleteAll)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesQueryDeleteAll)
|
||||
}
|
||||
|
||||
func TestSliceDeleteAll(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsSliceDeleteAll)
|
||||
t.Run("Scripts", testScriptsSliceDeleteAll)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsSliceDeleteAll)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosSliceDeleteAll)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsSliceDeleteAll)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesSliceDeleteAll)
|
||||
}
|
||||
|
||||
func TestExists(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsExists)
|
||||
t.Run("Scripts", testScriptsExists)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsExists)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosExists)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsExists)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesExists)
|
||||
}
|
||||
|
||||
func TestFind(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsFind)
|
||||
t.Run("Scripts", testScriptsFind)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsFind)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosFind)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsFind)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesFind)
|
||||
}
|
||||
|
||||
func TestBind(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsBind)
|
||||
t.Run("Scripts", testScriptsBind)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsBind)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosBind)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsBind)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesBind)
|
||||
}
|
||||
|
||||
func TestOne(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsOne)
|
||||
t.Run("Scripts", testScriptsOne)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsOne)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosOne)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsOne)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesOne)
|
||||
}
|
||||
|
||||
func TestAll(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsAll)
|
||||
t.Run("Scripts", testScriptsAll)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsAll)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosAll)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsAll)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesAll)
|
||||
}
|
||||
|
||||
func TestCount(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsCount)
|
||||
t.Run("Scripts", testScriptsCount)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsCount)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosCount)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsCount)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesCount)
|
||||
}
|
||||
|
||||
func TestHooks(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsHooks)
|
||||
t.Run("Scripts", testScriptsHooks)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsHooks)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosHooks)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsHooks)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesHooks)
|
||||
}
|
||||
|
||||
func TestInsert(t *testing.T) {
|
||||
@@ -84,12 +117,20 @@ func TestInsert(t *testing.T) {
|
||||
t.Run("Scripts", testScriptsInsertWhitelist)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsInsert)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsInsertWhitelist)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosInsert)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosInsertWhitelist)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsInsert)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsInsertWhitelist)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesInsert)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesInsertWhitelist)
|
||||
}
|
||||
|
||||
// TestToOne tests cannot be run in parallel
|
||||
// or deadlocks can occur.
|
||||
func TestToOne(t *testing.T) {
|
||||
t.Run("ScriptExecutionToScriptUsingScript", testScriptExecutionToOneScriptUsingScript)
|
||||
t.Run("WithdrawalCryptoToWithdrawalHistoryUsingWithdrawalHistory", testWithdrawalCryptoToOneWithdrawalHistoryUsingWithdrawalHistory)
|
||||
t.Run("WithdrawalFiatToWithdrawalHistoryUsingWithdrawalHistory", testWithdrawalFiatToOneWithdrawalHistoryUsingWithdrawalHistory)
|
||||
}
|
||||
|
||||
// TestOneToOne tests cannot be run in parallel
|
||||
@@ -100,12 +141,16 @@ func TestOneToOne(t *testing.T) {}
|
||||
// or deadlocks can occur.
|
||||
func TestToMany(t *testing.T) {
|
||||
t.Run("ScriptToScriptExecutions", testScriptToManyScriptExecutions)
|
||||
t.Run("WithdrawalHistoryToWithdrawalCryptos", testWithdrawalHistoryToManyWithdrawalCryptos)
|
||||
t.Run("WithdrawalHistoryToWithdrawalFiats", testWithdrawalHistoryToManyWithdrawalFiats)
|
||||
}
|
||||
|
||||
// TestToOneSet tests cannot be run in parallel
|
||||
// or deadlocks can occur.
|
||||
func TestToOneSet(t *testing.T) {
|
||||
t.Run("ScriptExecutionToScriptUsingScriptExecutions", testScriptExecutionToOneSetOpScriptUsingScript)
|
||||
t.Run("WithdrawalCryptoToWithdrawalHistoryUsingWithdrawalCryptos", testWithdrawalCryptoToOneSetOpWithdrawalHistoryUsingWithdrawalHistory)
|
||||
t.Run("WithdrawalFiatToWithdrawalHistoryUsingWithdrawalFiats", testWithdrawalFiatToOneSetOpWithdrawalHistoryUsingWithdrawalHistory)
|
||||
}
|
||||
|
||||
// TestToOneRemove tests cannot be run in parallel
|
||||
@@ -124,6 +169,8 @@ func TestOneToOneRemove(t *testing.T) {}
|
||||
// or deadlocks can occur.
|
||||
func TestToManyAdd(t *testing.T) {
|
||||
t.Run("ScriptToScriptExecutions", testScriptToManyAddOpScriptExecutions)
|
||||
t.Run("WithdrawalHistoryToWithdrawalCryptos", testWithdrawalHistoryToManyAddOpWithdrawalCryptos)
|
||||
t.Run("WithdrawalHistoryToWithdrawalFiats", testWithdrawalHistoryToManyAddOpWithdrawalFiats)
|
||||
}
|
||||
|
||||
// TestToManySet tests cannot be run in parallel
|
||||
@@ -138,28 +185,43 @@ func TestReload(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsReload)
|
||||
t.Run("Scripts", testScriptsReload)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsReload)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosReload)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsReload)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesReload)
|
||||
}
|
||||
|
||||
func TestReloadAll(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsReloadAll)
|
||||
t.Run("Scripts", testScriptsReloadAll)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsReloadAll)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosReloadAll)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsReloadAll)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesReloadAll)
|
||||
}
|
||||
|
||||
func TestSelect(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsSelect)
|
||||
t.Run("Scripts", testScriptsSelect)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsSelect)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosSelect)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsSelect)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesSelect)
|
||||
}
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsUpdate)
|
||||
t.Run("Scripts", testScriptsUpdate)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsUpdate)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosUpdate)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsUpdate)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesUpdate)
|
||||
}
|
||||
|
||||
func TestSliceUpdateAll(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsSliceUpdateAll)
|
||||
t.Run("Scripts", testScriptsSliceUpdateAll)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsSliceUpdateAll)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosSliceUpdateAll)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsSliceUpdateAll)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesSliceUpdateAll)
|
||||
}
|
||||
|
||||
@@ -4,11 +4,17 @@
|
||||
package sqlite3
|
||||
|
||||
var TableNames = struct {
|
||||
AuditEvent string
|
||||
Script string
|
||||
ScriptExecution string
|
||||
AuditEvent string
|
||||
Script string
|
||||
ScriptExecution string
|
||||
WithdrawalCrypto string
|
||||
WithdrawalFiat string
|
||||
WithdrawalHistory string
|
||||
}{
|
||||
AuditEvent: "audit_event",
|
||||
Script: "script",
|
||||
ScriptExecution: "script_execution",
|
||||
AuditEvent: "audit_event",
|
||||
Script: "script",
|
||||
ScriptExecution: "script_execution",
|
||||
WithdrawalCrypto: "withdrawal_crypto",
|
||||
WithdrawalFiat: "withdrawal_fiat",
|
||||
WithdrawalHistory: "withdrawal_history",
|
||||
}
|
||||
|
||||
996
database/models/sqlite3/withdrawal_crypto.go
Normal file
996
database/models/sqlite3/withdrawal_crypto.go
Normal file
@@ -0,0 +1,996 @@
|
||||
// Code generated by SQLBoiler 3.5.0-gct (https://github.com/thrasher-corp/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package sqlite3
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/thrasher-corp/sqlboiler/boil"
|
||||
"github.com/thrasher-corp/sqlboiler/queries"
|
||||
"github.com/thrasher-corp/sqlboiler/queries/qm"
|
||||
"github.com/thrasher-corp/sqlboiler/queries/qmhelper"
|
||||
"github.com/thrasher-corp/sqlboiler/strmangle"
|
||||
"github.com/volatiletech/null"
|
||||
)
|
||||
|
||||
// WithdrawalCrypto is an object representing the database table.
|
||||
type WithdrawalCrypto struct {
|
||||
ID int64 `boil:"id" json:"id" toml:"id" yaml:"id"`
|
||||
Address string `boil:"address" json:"address" toml:"address" yaml:"address"`
|
||||
AddressTag null.String `boil:"address_tag" json:"address_tag,omitempty" toml:"address_tag" yaml:"address_tag,omitempty"`
|
||||
Fee float64 `boil:"fee" json:"fee" toml:"fee" yaml:"fee"`
|
||||
WithdrawalHistoryID string `boil:"withdrawal_history_id" json:"withdrawal_history_id" toml:"withdrawal_history_id" yaml:"withdrawal_history_id"`
|
||||
|
||||
R *withdrawalCryptoR `boil:"-" json:"-" toml:"-" yaml:"-"`
|
||||
L withdrawalCryptoL `boil:"-" json:"-" toml:"-" yaml:"-"`
|
||||
}
|
||||
|
||||
var WithdrawalCryptoColumns = struct {
|
||||
ID string
|
||||
Address string
|
||||
AddressTag string
|
||||
Fee string
|
||||
WithdrawalHistoryID string
|
||||
}{
|
||||
ID: "id",
|
||||
Address: "address",
|
||||
AddressTag: "address_tag",
|
||||
Fee: "fee",
|
||||
WithdrawalHistoryID: "withdrawal_history_id",
|
||||
}
|
||||
|
||||
// Generated where
|
||||
|
||||
type whereHelpernull_String struct{ field string }
|
||||
|
||||
func (w whereHelpernull_String) EQ(x null.String) qm.QueryMod {
|
||||
return qmhelper.WhereNullEQ(w.field, false, x)
|
||||
}
|
||||
func (w whereHelpernull_String) NEQ(x null.String) qm.QueryMod {
|
||||
return qmhelper.WhereNullEQ(w.field, true, x)
|
||||
}
|
||||
func (w whereHelpernull_String) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) }
|
||||
func (w whereHelpernull_String) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) }
|
||||
func (w whereHelpernull_String) LT(x null.String) qm.QueryMod {
|
||||
return qmhelper.Where(w.field, qmhelper.LT, x)
|
||||
}
|
||||
func (w whereHelpernull_String) LTE(x null.String) qm.QueryMod {
|
||||
return qmhelper.Where(w.field, qmhelper.LTE, x)
|
||||
}
|
||||
func (w whereHelpernull_String) GT(x null.String) qm.QueryMod {
|
||||
return qmhelper.Where(w.field, qmhelper.GT, x)
|
||||
}
|
||||
func (w whereHelpernull_String) GTE(x null.String) qm.QueryMod {
|
||||
return qmhelper.Where(w.field, qmhelper.GTE, x)
|
||||
}
|
||||
|
||||
type whereHelperfloat64 struct{ field string }
|
||||
|
||||
func (w whereHelperfloat64) EQ(x float64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) }
|
||||
func (w whereHelperfloat64) NEQ(x float64) qm.QueryMod {
|
||||
return qmhelper.Where(w.field, qmhelper.NEQ, x)
|
||||
}
|
||||
func (w whereHelperfloat64) LT(x float64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) }
|
||||
func (w whereHelperfloat64) LTE(x float64) qm.QueryMod {
|
||||
return qmhelper.Where(w.field, qmhelper.LTE, x)
|
||||
}
|
||||
func (w whereHelperfloat64) GT(x float64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) }
|
||||
func (w whereHelperfloat64) GTE(x float64) qm.QueryMod {
|
||||
return qmhelper.Where(w.field, qmhelper.GTE, x)
|
||||
}
|
||||
|
||||
var WithdrawalCryptoWhere = struct {
|
||||
ID whereHelperint64
|
||||
Address whereHelperstring
|
||||
AddressTag whereHelpernull_String
|
||||
Fee whereHelperfloat64
|
||||
WithdrawalHistoryID whereHelperstring
|
||||
}{
|
||||
ID: whereHelperint64{field: "\"withdrawal_crypto\".\"id\""},
|
||||
Address: whereHelperstring{field: "\"withdrawal_crypto\".\"address\""},
|
||||
AddressTag: whereHelpernull_String{field: "\"withdrawal_crypto\".\"address_tag\""},
|
||||
Fee: whereHelperfloat64{field: "\"withdrawal_crypto\".\"fee\""},
|
||||
WithdrawalHistoryID: whereHelperstring{field: "\"withdrawal_crypto\".\"withdrawal_history_id\""},
|
||||
}
|
||||
|
||||
// WithdrawalCryptoRels is where relationship names are stored.
|
||||
var WithdrawalCryptoRels = struct {
|
||||
WithdrawalHistory string
|
||||
}{
|
||||
WithdrawalHistory: "WithdrawalHistory",
|
||||
}
|
||||
|
||||
// withdrawalCryptoR is where relationships are stored.
|
||||
type withdrawalCryptoR struct {
|
||||
WithdrawalHistory *WithdrawalHistory
|
||||
}
|
||||
|
||||
// NewStruct creates a new relationship struct
|
||||
func (*withdrawalCryptoR) NewStruct() *withdrawalCryptoR {
|
||||
return &withdrawalCryptoR{}
|
||||
}
|
||||
|
||||
// withdrawalCryptoL is where Load methods for each relationship are stored.
|
||||
type withdrawalCryptoL struct{}
|
||||
|
||||
var (
|
||||
withdrawalCryptoAllColumns = []string{"id", "address", "address_tag", "fee", "withdrawal_history_id"}
|
||||
withdrawalCryptoColumnsWithoutDefault = []string{"address", "address_tag", "fee", "withdrawal_history_id"}
|
||||
withdrawalCryptoColumnsWithDefault = []string{"id"}
|
||||
withdrawalCryptoPrimaryKeyColumns = []string{"id"}
|
||||
)
|
||||
|
||||
type (
|
||||
// WithdrawalCryptoSlice is an alias for a slice of pointers to WithdrawalCrypto.
|
||||
// This should generally be used opposed to []WithdrawalCrypto.
|
||||
WithdrawalCryptoSlice []*WithdrawalCrypto
|
||||
// WithdrawalCryptoHook is the signature for custom WithdrawalCrypto hook methods
|
||||
WithdrawalCryptoHook func(context.Context, boil.ContextExecutor, *WithdrawalCrypto) error
|
||||
|
||||
withdrawalCryptoQuery struct {
|
||||
*queries.Query
|
||||
}
|
||||
)
|
||||
|
||||
// Cache for insert, update and upsert
|
||||
var (
|
||||
withdrawalCryptoType = reflect.TypeOf(&WithdrawalCrypto{})
|
||||
withdrawalCryptoMapping = queries.MakeStructMapping(withdrawalCryptoType)
|
||||
withdrawalCryptoPrimaryKeyMapping, _ = queries.BindMapping(withdrawalCryptoType, withdrawalCryptoMapping, withdrawalCryptoPrimaryKeyColumns)
|
||||
withdrawalCryptoInsertCacheMut sync.RWMutex
|
||||
withdrawalCryptoInsertCache = make(map[string]insertCache)
|
||||
withdrawalCryptoUpdateCacheMut sync.RWMutex
|
||||
withdrawalCryptoUpdateCache = make(map[string]updateCache)
|
||||
withdrawalCryptoUpsertCacheMut sync.RWMutex
|
||||
withdrawalCryptoUpsertCache = make(map[string]insertCache)
|
||||
)
|
||||
|
||||
var (
|
||||
// Force time package dependency for automated UpdatedAt/CreatedAt.
|
||||
_ = time.Second
|
||||
// Force qmhelper dependency for where clause generation (which doesn't
|
||||
// always happen)
|
||||
_ = qmhelper.Where
|
||||
)
|
||||
|
||||
var withdrawalCryptoBeforeInsertHooks []WithdrawalCryptoHook
|
||||
var withdrawalCryptoBeforeUpdateHooks []WithdrawalCryptoHook
|
||||
var withdrawalCryptoBeforeDeleteHooks []WithdrawalCryptoHook
|
||||
var withdrawalCryptoBeforeUpsertHooks []WithdrawalCryptoHook
|
||||
|
||||
var withdrawalCryptoAfterInsertHooks []WithdrawalCryptoHook
|
||||
var withdrawalCryptoAfterSelectHooks []WithdrawalCryptoHook
|
||||
var withdrawalCryptoAfterUpdateHooks []WithdrawalCryptoHook
|
||||
var withdrawalCryptoAfterDeleteHooks []WithdrawalCryptoHook
|
||||
var withdrawalCryptoAfterUpsertHooks []WithdrawalCryptoHook
|
||||
|
||||
// doBeforeInsertHooks executes all "before insert" hooks.
|
||||
func (o *WithdrawalCrypto) doBeforeInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalCryptoBeforeInsertHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doBeforeUpdateHooks executes all "before Update" hooks.
|
||||
func (o *WithdrawalCrypto) doBeforeUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalCryptoBeforeUpdateHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doBeforeDeleteHooks executes all "before Delete" hooks.
|
||||
func (o *WithdrawalCrypto) doBeforeDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalCryptoBeforeDeleteHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doBeforeUpsertHooks executes all "before Upsert" hooks.
|
||||
func (o *WithdrawalCrypto) doBeforeUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalCryptoBeforeUpsertHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doAfterInsertHooks executes all "after Insert" hooks.
|
||||
func (o *WithdrawalCrypto) doAfterInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalCryptoAfterInsertHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doAfterSelectHooks executes all "after Select" hooks.
|
||||
func (o *WithdrawalCrypto) doAfterSelectHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalCryptoAfterSelectHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doAfterUpdateHooks executes all "after Update" hooks.
|
||||
func (o *WithdrawalCrypto) doAfterUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalCryptoAfterUpdateHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doAfterDeleteHooks executes all "after Delete" hooks.
|
||||
func (o *WithdrawalCrypto) doAfterDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalCryptoAfterDeleteHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doAfterUpsertHooks executes all "after Upsert" hooks.
|
||||
func (o *WithdrawalCrypto) doAfterUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalCryptoAfterUpsertHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddWithdrawalCryptoHook registers your hook function for all future operations.
|
||||
func AddWithdrawalCryptoHook(hookPoint boil.HookPoint, withdrawalCryptoHook WithdrawalCryptoHook) {
|
||||
switch hookPoint {
|
||||
case boil.BeforeInsertHook:
|
||||
withdrawalCryptoBeforeInsertHooks = append(withdrawalCryptoBeforeInsertHooks, withdrawalCryptoHook)
|
||||
case boil.BeforeUpdateHook:
|
||||
withdrawalCryptoBeforeUpdateHooks = append(withdrawalCryptoBeforeUpdateHooks, withdrawalCryptoHook)
|
||||
case boil.BeforeDeleteHook:
|
||||
withdrawalCryptoBeforeDeleteHooks = append(withdrawalCryptoBeforeDeleteHooks, withdrawalCryptoHook)
|
||||
case boil.BeforeUpsertHook:
|
||||
withdrawalCryptoBeforeUpsertHooks = append(withdrawalCryptoBeforeUpsertHooks, withdrawalCryptoHook)
|
||||
case boil.AfterInsertHook:
|
||||
withdrawalCryptoAfterInsertHooks = append(withdrawalCryptoAfterInsertHooks, withdrawalCryptoHook)
|
||||
case boil.AfterSelectHook:
|
||||
withdrawalCryptoAfterSelectHooks = append(withdrawalCryptoAfterSelectHooks, withdrawalCryptoHook)
|
||||
case boil.AfterUpdateHook:
|
||||
withdrawalCryptoAfterUpdateHooks = append(withdrawalCryptoAfterUpdateHooks, withdrawalCryptoHook)
|
||||
case boil.AfterDeleteHook:
|
||||
withdrawalCryptoAfterDeleteHooks = append(withdrawalCryptoAfterDeleteHooks, withdrawalCryptoHook)
|
||||
case boil.AfterUpsertHook:
|
||||
withdrawalCryptoAfterUpsertHooks = append(withdrawalCryptoAfterUpsertHooks, withdrawalCryptoHook)
|
||||
}
|
||||
}
|
||||
|
||||
// One returns a single withdrawalCrypto record from the query.
|
||||
func (q withdrawalCryptoQuery) One(ctx context.Context, exec boil.ContextExecutor) (*WithdrawalCrypto, error) {
|
||||
o := &WithdrawalCrypto{}
|
||||
|
||||
queries.SetLimit(q.Query, 1)
|
||||
|
||||
err := q.Bind(ctx, exec, o)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == sql.ErrNoRows {
|
||||
return nil, sql.ErrNoRows
|
||||
}
|
||||
return nil, errors.Wrap(err, "sqlite3: failed to execute a one query for withdrawal_crypto")
|
||||
}
|
||||
|
||||
if err := o.doAfterSelectHooks(ctx, exec); err != nil {
|
||||
return o, err
|
||||
}
|
||||
|
||||
return o, nil
|
||||
}
|
||||
|
||||
// All returns all WithdrawalCrypto records from the query.
|
||||
func (q withdrawalCryptoQuery) All(ctx context.Context, exec boil.ContextExecutor) (WithdrawalCryptoSlice, error) {
|
||||
var o []*WithdrawalCrypto
|
||||
|
||||
err := q.Bind(ctx, exec, &o)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "sqlite3: failed to assign all query results to WithdrawalCrypto slice")
|
||||
}
|
||||
|
||||
if len(withdrawalCryptoAfterSelectHooks) != 0 {
|
||||
for _, obj := range o {
|
||||
if err := obj.doAfterSelectHooks(ctx, exec); err != nil {
|
||||
return o, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return o, nil
|
||||
}
|
||||
|
||||
// Count returns the count of all WithdrawalCrypto records in the query.
|
||||
func (q withdrawalCryptoQuery) Count(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
var count int64
|
||||
|
||||
queries.SetSelect(q.Query, nil)
|
||||
queries.SetCount(q.Query)
|
||||
|
||||
err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: failed to count withdrawal_crypto rows")
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// Exists checks if the row exists in the table.
|
||||
func (q withdrawalCryptoQuery) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
|
||||
var count int64
|
||||
|
||||
queries.SetSelect(q.Query, nil)
|
||||
queries.SetCount(q.Query)
|
||||
queries.SetLimit(q.Query, 1)
|
||||
|
||||
err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "sqlite3: failed to check if withdrawal_crypto exists")
|
||||
}
|
||||
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
// WithdrawalHistory pointed to by the foreign key.
|
||||
func (o *WithdrawalCrypto) WithdrawalHistory(mods ...qm.QueryMod) withdrawalHistoryQuery {
|
||||
queryMods := []qm.QueryMod{
|
||||
qm.Where("\"id\" = ?", o.WithdrawalHistoryID),
|
||||
}
|
||||
|
||||
queryMods = append(queryMods, mods...)
|
||||
|
||||
query := WithdrawalHistories(queryMods...)
|
||||
queries.SetFrom(query.Query, "\"withdrawal_history\"")
|
||||
|
||||
return query
|
||||
}
|
||||
|
||||
// LoadWithdrawalHistory allows an eager lookup of values, cached into the
|
||||
// loaded structs of the objects. This is for an N-1 relationship.
|
||||
func (withdrawalCryptoL) LoadWithdrawalHistory(ctx context.Context, e boil.ContextExecutor, singular bool, maybeWithdrawalCrypto interface{}, mods queries.Applicator) error {
|
||||
var slice []*WithdrawalCrypto
|
||||
var object *WithdrawalCrypto
|
||||
|
||||
if singular {
|
||||
object = maybeWithdrawalCrypto.(*WithdrawalCrypto)
|
||||
} else {
|
||||
slice = *maybeWithdrawalCrypto.(*[]*WithdrawalCrypto)
|
||||
}
|
||||
|
||||
args := make([]interface{}, 0, 1)
|
||||
if singular {
|
||||
if object.R == nil {
|
||||
object.R = &withdrawalCryptoR{}
|
||||
}
|
||||
args = append(args, object.WithdrawalHistoryID)
|
||||
|
||||
} else {
|
||||
Outer:
|
||||
for _, obj := range slice {
|
||||
if obj.R == nil {
|
||||
obj.R = &withdrawalCryptoR{}
|
||||
}
|
||||
|
||||
for _, a := range args {
|
||||
if a == obj.WithdrawalHistoryID {
|
||||
continue Outer
|
||||
}
|
||||
}
|
||||
|
||||
args = append(args, obj.WithdrawalHistoryID)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if len(args) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
query := NewQuery(qm.From(`withdrawal_history`), qm.WhereIn(`withdrawal_history.id in ?`, args...))
|
||||
if mods != nil {
|
||||
mods.Apply(query)
|
||||
}
|
||||
|
||||
results, err := query.QueryContext(ctx, e)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to eager load WithdrawalHistory")
|
||||
}
|
||||
|
||||
var resultSlice []*WithdrawalHistory
|
||||
if err = queries.Bind(results, &resultSlice); err != nil {
|
||||
return errors.Wrap(err, "failed to bind eager loaded slice WithdrawalHistory")
|
||||
}
|
||||
|
||||
if err = results.Close(); err != nil {
|
||||
return errors.Wrap(err, "failed to close results of eager load for withdrawal_history")
|
||||
}
|
||||
if err = results.Err(); err != nil {
|
||||
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for withdrawal_history")
|
||||
}
|
||||
|
||||
if len(withdrawalCryptoAfterSelectHooks) != 0 {
|
||||
for _, obj := range resultSlice {
|
||||
if err := obj.doAfterSelectHooks(ctx, e); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(resultSlice) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if singular {
|
||||
foreign := resultSlice[0]
|
||||
object.R.WithdrawalHistory = foreign
|
||||
if foreign.R == nil {
|
||||
foreign.R = &withdrawalHistoryR{}
|
||||
}
|
||||
foreign.R.WithdrawalCryptos = append(foreign.R.WithdrawalCryptos, object)
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, local := range slice {
|
||||
for _, foreign := range resultSlice {
|
||||
if local.WithdrawalHistoryID == foreign.ID {
|
||||
local.R.WithdrawalHistory = foreign
|
||||
if foreign.R == nil {
|
||||
foreign.R = &withdrawalHistoryR{}
|
||||
}
|
||||
foreign.R.WithdrawalCryptos = append(foreign.R.WithdrawalCryptos, local)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetWithdrawalHistory of the withdrawalCrypto to the related item.
|
||||
// Sets o.R.WithdrawalHistory to related.
|
||||
// Adds o to related.R.WithdrawalCryptos.
|
||||
func (o *WithdrawalCrypto) SetWithdrawalHistory(ctx context.Context, exec boil.ContextExecutor, insert bool, related *WithdrawalHistory) error {
|
||||
var err error
|
||||
if insert {
|
||||
if err = related.Insert(ctx, exec, boil.Infer()); err != nil {
|
||||
return errors.Wrap(err, "failed to insert into foreign table")
|
||||
}
|
||||
}
|
||||
|
||||
updateQuery := fmt.Sprintf(
|
||||
"UPDATE \"withdrawal_crypto\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 0, []string{"withdrawal_history_id"}),
|
||||
strmangle.WhereClause("\"", "\"", 0, withdrawalCryptoPrimaryKeyColumns),
|
||||
)
|
||||
values := []interface{}{related.ID, o.ID}
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, updateQuery)
|
||||
fmt.Fprintln(boil.DebugWriter, values)
|
||||
}
|
||||
|
||||
if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil {
|
||||
return errors.Wrap(err, "failed to update local table")
|
||||
}
|
||||
|
||||
o.WithdrawalHistoryID = related.ID
|
||||
if o.R == nil {
|
||||
o.R = &withdrawalCryptoR{
|
||||
WithdrawalHistory: related,
|
||||
}
|
||||
} else {
|
||||
o.R.WithdrawalHistory = related
|
||||
}
|
||||
|
||||
if related.R == nil {
|
||||
related.R = &withdrawalHistoryR{
|
||||
WithdrawalCryptos: WithdrawalCryptoSlice{o},
|
||||
}
|
||||
} else {
|
||||
related.R.WithdrawalCryptos = append(related.R.WithdrawalCryptos, o)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// WithdrawalCryptos retrieves all the records using an executor.
|
||||
func WithdrawalCryptos(mods ...qm.QueryMod) withdrawalCryptoQuery {
|
||||
mods = append(mods, qm.From("\"withdrawal_crypto\""))
|
||||
return withdrawalCryptoQuery{NewQuery(mods...)}
|
||||
}
|
||||
|
||||
// FindWithdrawalCrypto retrieves a single record by ID with an executor.
|
||||
// If selectCols is empty Find will return all columns.
|
||||
func FindWithdrawalCrypto(ctx context.Context, exec boil.ContextExecutor, iD int64, selectCols ...string) (*WithdrawalCrypto, error) {
|
||||
withdrawalCryptoObj := &WithdrawalCrypto{}
|
||||
|
||||
sel := "*"
|
||||
if len(selectCols) > 0 {
|
||||
sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
|
||||
}
|
||||
query := fmt.Sprintf(
|
||||
"select %s from \"withdrawal_crypto\" where \"id\"=?", sel,
|
||||
)
|
||||
|
||||
q := queries.Raw(query, iD)
|
||||
|
||||
err := q.Bind(ctx, exec, withdrawalCryptoObj)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == sql.ErrNoRows {
|
||||
return nil, sql.ErrNoRows
|
||||
}
|
||||
return nil, errors.Wrap(err, "sqlite3: unable to select from withdrawal_crypto")
|
||||
}
|
||||
|
||||
return withdrawalCryptoObj, nil
|
||||
}
|
||||
|
||||
// Insert a single record using an executor.
|
||||
// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.
|
||||
func (o *WithdrawalCrypto) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
|
||||
if o == nil {
|
||||
return errors.New("sqlite3: no withdrawal_crypto provided for insertion")
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
if err := o.doBeforeInsertHooks(ctx, exec); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
nzDefaults := queries.NonZeroDefaultSet(withdrawalCryptoColumnsWithDefault, o)
|
||||
|
||||
key := makeCacheKey(columns, nzDefaults)
|
||||
withdrawalCryptoInsertCacheMut.RLock()
|
||||
cache, cached := withdrawalCryptoInsertCache[key]
|
||||
withdrawalCryptoInsertCacheMut.RUnlock()
|
||||
|
||||
if !cached {
|
||||
wl, returnColumns := columns.InsertColumnSet(
|
||||
withdrawalCryptoAllColumns,
|
||||
withdrawalCryptoColumnsWithDefault,
|
||||
withdrawalCryptoColumnsWithoutDefault,
|
||||
nzDefaults,
|
||||
)
|
||||
|
||||
cache.valueMapping, err = queries.BindMapping(withdrawalCryptoType, withdrawalCryptoMapping, wl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cache.retMapping, err = queries.BindMapping(withdrawalCryptoType, withdrawalCryptoMapping, returnColumns)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(wl) != 0 {
|
||||
cache.query = fmt.Sprintf("INSERT INTO \"withdrawal_crypto\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
|
||||
} else {
|
||||
cache.query = "INSERT INTO \"withdrawal_crypto\" () VALUES ()%s%s"
|
||||
}
|
||||
|
||||
var queryOutput, queryReturning string
|
||||
|
||||
if len(cache.retMapping) != 0 {
|
||||
cache.retQuery = fmt.Sprintf("SELECT \"%s\" FROM \"withdrawal_crypto\" WHERE %s", strings.Join(returnColumns, "\",\""), strmangle.WhereClause("\"", "\"", 0, withdrawalCryptoPrimaryKeyColumns))
|
||||
}
|
||||
|
||||
cache.query = fmt.Sprintf(cache.query, queryOutput, queryReturning)
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
vals := queries.ValuesFromMapping(value, cache.valueMapping)
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, cache.query)
|
||||
fmt.Fprintln(boil.DebugWriter, vals)
|
||||
}
|
||||
|
||||
result, err := exec.ExecContext(ctx, cache.query, vals...)
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "sqlite3: unable to insert into withdrawal_crypto")
|
||||
}
|
||||
|
||||
var lastID int64
|
||||
var identifierCols []interface{}
|
||||
|
||||
if len(cache.retMapping) == 0 {
|
||||
goto CacheNoHooks
|
||||
}
|
||||
|
||||
lastID, err = result.LastInsertId()
|
||||
if err != nil {
|
||||
return ErrSyncFail
|
||||
}
|
||||
|
||||
o.ID = int64(lastID)
|
||||
if lastID != 0 && len(cache.retMapping) == 1 && cache.retMapping[0] == withdrawalCryptoMapping["ID"] {
|
||||
goto CacheNoHooks
|
||||
}
|
||||
|
||||
identifierCols = []interface{}{
|
||||
o.ID,
|
||||
}
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, cache.retQuery)
|
||||
fmt.Fprintln(boil.DebugWriter, identifierCols...)
|
||||
}
|
||||
|
||||
err = exec.QueryRowContext(ctx, cache.retQuery, identifierCols...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "sqlite3: unable to populate default values for withdrawal_crypto")
|
||||
}
|
||||
|
||||
CacheNoHooks:
|
||||
if !cached {
|
||||
withdrawalCryptoInsertCacheMut.Lock()
|
||||
withdrawalCryptoInsertCache[key] = cache
|
||||
withdrawalCryptoInsertCacheMut.Unlock()
|
||||
}
|
||||
|
||||
return o.doAfterInsertHooks(ctx, exec)
|
||||
}
|
||||
|
||||
// Update uses an executor to update the WithdrawalCrypto.
|
||||
// See boil.Columns.UpdateColumnSet documentation to understand column list inference for updates.
|
||||
// Update does not automatically update the record in case of default values. Use .Reload() to refresh the records.
|
||||
func (o *WithdrawalCrypto) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error) {
|
||||
var err error
|
||||
if err = o.doBeforeUpdateHooks(ctx, exec); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
key := makeCacheKey(columns, nil)
|
||||
withdrawalCryptoUpdateCacheMut.RLock()
|
||||
cache, cached := withdrawalCryptoUpdateCache[key]
|
||||
withdrawalCryptoUpdateCacheMut.RUnlock()
|
||||
|
||||
if !cached {
|
||||
wl := columns.UpdateColumnSet(
|
||||
withdrawalCryptoAllColumns,
|
||||
withdrawalCryptoPrimaryKeyColumns,
|
||||
)
|
||||
|
||||
if len(wl) == 0 {
|
||||
return 0, errors.New("sqlite3: unable to update withdrawal_crypto, could not build whitelist")
|
||||
}
|
||||
|
||||
cache.query = fmt.Sprintf("UPDATE \"withdrawal_crypto\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 0, wl),
|
||||
strmangle.WhereClause("\"", "\"", 0, withdrawalCryptoPrimaryKeyColumns),
|
||||
)
|
||||
cache.valueMapping, err = queries.BindMapping(withdrawalCryptoType, withdrawalCryptoMapping, append(wl, withdrawalCryptoPrimaryKeyColumns...))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping)
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, cache.query)
|
||||
fmt.Fprintln(boil.DebugWriter, values)
|
||||
}
|
||||
|
||||
var result sql.Result
|
||||
result, err = exec.ExecContext(ctx, cache.query, values...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to update withdrawal_crypto row")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: failed to get rows affected by update for withdrawal_crypto")
|
||||
}
|
||||
|
||||
if !cached {
|
||||
withdrawalCryptoUpdateCacheMut.Lock()
|
||||
withdrawalCryptoUpdateCache[key] = cache
|
||||
withdrawalCryptoUpdateCacheMut.Unlock()
|
||||
}
|
||||
|
||||
return rowsAff, o.doAfterUpdateHooks(ctx, exec)
|
||||
}
|
||||
|
||||
// UpdateAll updates all rows with the specified column values.
|
||||
func (q withdrawalCryptoQuery) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
|
||||
queries.SetUpdate(q.Query, cols)
|
||||
|
||||
result, err := q.Query.ExecContext(ctx, exec)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to update all for withdrawal_crypto")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to retrieve rows affected for withdrawal_crypto")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// UpdateAll updates all rows with the specified column values, using an executor.
|
||||
func (o WithdrawalCryptoSlice) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
|
||||
ln := int64(len(o))
|
||||
if ln == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
if len(cols) == 0 {
|
||||
return 0, errors.New("sqlite3: update all requires at least one column argument")
|
||||
}
|
||||
|
||||
colNames := make([]string, len(cols))
|
||||
args := make([]interface{}, len(cols))
|
||||
|
||||
i := 0
|
||||
for name, value := range cols {
|
||||
colNames[i] = name
|
||||
args[i] = value
|
||||
i++
|
||||
}
|
||||
|
||||
// Append all of the primary key values for each column
|
||||
for _, obj := range o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), withdrawalCryptoPrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := fmt.Sprintf("UPDATE \"withdrawal_crypto\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 0, colNames),
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, withdrawalCryptoPrimaryKeyColumns, len(o)))
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, sql)
|
||||
fmt.Fprintln(boil.DebugWriter, args...)
|
||||
}
|
||||
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to update all in withdrawalCrypto slice")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to retrieve rows affected all in update all withdrawalCrypto")
|
||||
}
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// Delete deletes a single WithdrawalCrypto record with an executor.
|
||||
// Delete will match against the primary key column to find the record to delete.
|
||||
func (o *WithdrawalCrypto) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if o == nil {
|
||||
return 0, errors.New("sqlite3: no WithdrawalCrypto provided for delete")
|
||||
}
|
||||
|
||||
if err := o.doBeforeDeleteHooks(ctx, exec); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), withdrawalCryptoPrimaryKeyMapping)
|
||||
sql := "DELETE FROM \"withdrawal_crypto\" WHERE \"id\"=?"
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, sql)
|
||||
fmt.Fprintln(boil.DebugWriter, args...)
|
||||
}
|
||||
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to delete from withdrawal_crypto")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: failed to get rows affected by delete for withdrawal_crypto")
|
||||
}
|
||||
|
||||
if err := o.doAfterDeleteHooks(ctx, exec); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// DeleteAll deletes all matching rows.
|
||||
func (q withdrawalCryptoQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if q.Query == nil {
|
||||
return 0, errors.New("sqlite3: no withdrawalCryptoQuery provided for delete all")
|
||||
}
|
||||
|
||||
queries.SetDelete(q.Query)
|
||||
|
||||
result, err := q.Query.ExecContext(ctx, exec)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to delete all from withdrawal_crypto")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: failed to get rows affected by deleteall for withdrawal_crypto")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// DeleteAll deletes all rows in the slice, using an executor.
|
||||
func (o WithdrawalCryptoSlice) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if len(o) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
if len(withdrawalCryptoBeforeDeleteHooks) != 0 {
|
||||
for _, obj := range o {
|
||||
if err := obj.doBeforeDeleteHooks(ctx, exec); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var args []interface{}
|
||||
for _, obj := range o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), withdrawalCryptoPrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := "DELETE FROM \"withdrawal_crypto\" WHERE " +
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, withdrawalCryptoPrimaryKeyColumns, len(o))
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, sql)
|
||||
fmt.Fprintln(boil.DebugWriter, args)
|
||||
}
|
||||
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to delete all from withdrawalCrypto slice")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: failed to get rows affected by deleteall for withdrawal_crypto")
|
||||
}
|
||||
|
||||
if len(withdrawalCryptoAfterDeleteHooks) != 0 {
|
||||
for _, obj := range o {
|
||||
if err := obj.doAfterDeleteHooks(ctx, exec); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// Reload refetches the object from the database
|
||||
// using the primary keys with an executor.
|
||||
func (o *WithdrawalCrypto) Reload(ctx context.Context, exec boil.ContextExecutor) error {
|
||||
ret, err := FindWithdrawalCrypto(ctx, exec, o.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*o = *ret
|
||||
return nil
|
||||
}
|
||||
|
||||
// ReloadAll refetches every row with matching primary key column values
|
||||
// and overwrites the original object slice with the newly updated slice.
|
||||
func (o *WithdrawalCryptoSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error {
|
||||
if o == nil || len(*o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
slice := WithdrawalCryptoSlice{}
|
||||
var args []interface{}
|
||||
for _, obj := range *o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), withdrawalCryptoPrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := "SELECT \"withdrawal_crypto\".* FROM \"withdrawal_crypto\" WHERE " +
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, withdrawalCryptoPrimaryKeyColumns, len(*o))
|
||||
|
||||
q := queries.Raw(sql, args...)
|
||||
|
||||
err := q.Bind(ctx, exec, &slice)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "sqlite3: unable to reload all in WithdrawalCryptoSlice")
|
||||
}
|
||||
|
||||
*o = slice
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// WithdrawalCryptoExists checks if the WithdrawalCrypto row exists.
|
||||
func WithdrawalCryptoExists(ctx context.Context, exec boil.ContextExecutor, iD int64) (bool, error) {
|
||||
var exists bool
|
||||
sql := "select exists(select 1 from \"withdrawal_crypto\" where \"id\"=? limit 1)"
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, sql)
|
||||
fmt.Fprintln(boil.DebugWriter, iD)
|
||||
}
|
||||
|
||||
row := exec.QueryRowContext(ctx, sql, iD)
|
||||
|
||||
err := row.Scan(&exists)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "sqlite3: unable to check if withdrawal_crypto exists")
|
||||
}
|
||||
|
||||
return exists, nil
|
||||
}
|
||||
793
database/models/sqlite3/withdrawal_crypto_test.go
Normal file
793
database/models/sqlite3/withdrawal_crypto_test.go
Normal file
@@ -0,0 +1,793 @@
|
||||
// Code generated by SQLBoiler 3.5.0-gct (https://github.com/thrasher-corp/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package sqlite3
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-corp/sqlboiler/boil"
|
||||
"github.com/thrasher-corp/sqlboiler/queries"
|
||||
"github.com/thrasher-corp/sqlboiler/randomize"
|
||||
"github.com/thrasher-corp/sqlboiler/strmangle"
|
||||
)
|
||||
|
||||
var (
|
||||
// Relationships sometimes use the reflection helper queries.Equal/queries.Assign
|
||||
// so force a package dependency in case they don't.
|
||||
_ = queries.Equal
|
||||
)
|
||||
|
||||
func testWithdrawalCryptos(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
query := WithdrawalCryptos()
|
||||
|
||||
if query.Query == nil {
|
||||
t.Error("expected a query, got nothing")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosDelete(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Delete(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosQueryDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := WithdrawalCryptos().DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosSliceDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := WithdrawalCryptoSlice{o}
|
||||
|
||||
if rowsAff, err := slice.DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosExists(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
e, err := WithdrawalCryptoExists(ctx, tx, o.ID)
|
||||
if err != nil {
|
||||
t.Errorf("Unable to check if WithdrawalCrypto exists: %s", err)
|
||||
}
|
||||
if !e {
|
||||
t.Errorf("Expected WithdrawalCryptoExists to return true, but got false.")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosFind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
withdrawalCryptoFound, err := FindWithdrawalCrypto(ctx, tx, o.ID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if withdrawalCryptoFound == nil {
|
||||
t.Error("want a record, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosBind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = WithdrawalCryptos().Bind(ctx, tx, o); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosOne(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if x, err := WithdrawalCryptos().One(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if x == nil {
|
||||
t.Error("expected to get a non nil record")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
withdrawalCryptoOne := &WithdrawalCrypto{}
|
||||
withdrawalCryptoTwo := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, withdrawalCryptoOne, withdrawalCryptoDBTypes, false, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, withdrawalCryptoTwo, withdrawalCryptoDBTypes, false, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = withdrawalCryptoOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = withdrawalCryptoTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := WithdrawalCryptos().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 2 {
|
||||
t.Error("want 2 records, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosCount(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
seed := randomize.NewSeed()
|
||||
withdrawalCryptoOne := &WithdrawalCrypto{}
|
||||
withdrawalCryptoTwo := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, withdrawalCryptoOne, withdrawalCryptoDBTypes, false, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, withdrawalCryptoTwo, withdrawalCryptoDBTypes, false, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = withdrawalCryptoOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = withdrawalCryptoTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 2 {
|
||||
t.Error("want 2 records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func withdrawalCryptoBeforeInsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoAfterInsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoAfterSelectHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoBeforeUpdateHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoAfterUpdateHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoBeforeDeleteHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoAfterDeleteHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoBeforeUpsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoAfterUpsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosHooks(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
empty := &WithdrawalCrypto{}
|
||||
o := &WithdrawalCrypto{}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, false); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto object: %s", err)
|
||||
}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.BeforeInsertHook, withdrawalCryptoBeforeInsertHook)
|
||||
if err = o.doBeforeInsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeInsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeInsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoBeforeInsertHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.AfterInsertHook, withdrawalCryptoAfterInsertHook)
|
||||
if err = o.doAfterInsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterInsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterInsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoAfterInsertHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.AfterSelectHook, withdrawalCryptoAfterSelectHook)
|
||||
if err = o.doAfterSelectHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterSelectHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterSelectHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoAfterSelectHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.BeforeUpdateHook, withdrawalCryptoBeforeUpdateHook)
|
||||
if err = o.doBeforeUpdateHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeUpdateHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeUpdateHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoBeforeUpdateHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.AfterUpdateHook, withdrawalCryptoAfterUpdateHook)
|
||||
if err = o.doAfterUpdateHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterUpdateHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterUpdateHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoAfterUpdateHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.BeforeDeleteHook, withdrawalCryptoBeforeDeleteHook)
|
||||
if err = o.doBeforeDeleteHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeDeleteHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeDeleteHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoBeforeDeleteHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.AfterDeleteHook, withdrawalCryptoAfterDeleteHook)
|
||||
if err = o.doAfterDeleteHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterDeleteHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterDeleteHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoAfterDeleteHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.BeforeUpsertHook, withdrawalCryptoBeforeUpsertHook)
|
||||
if err = o.doBeforeUpsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeUpsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeUpsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoBeforeUpsertHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.AfterUpsertHook, withdrawalCryptoAfterUpsertHook)
|
||||
if err = o.doAfterUpsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterUpsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterUpsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoAfterUpsertHooks = []WithdrawalCryptoHook{}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosInsert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosInsertWhitelist(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Whitelist(withdrawalCryptoColumnsWithoutDefault...)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptoToOneWithdrawalHistoryUsingWithdrawalHistory(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var local WithdrawalCrypto
|
||||
var foreign WithdrawalHistory
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err := randomize.Struct(seed, &local, withdrawalCryptoDBTypes, false, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
if err := randomize.Struct(seed, &foreign, withdrawalHistoryDBTypes, false, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
if err := foreign.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
local.WithdrawalHistoryID = foreign.ID
|
||||
if err := local.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
check, err := local.WithdrawalHistory().One(ctx, tx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if check.ID != foreign.ID {
|
||||
t.Errorf("want: %v, got %v", foreign.ID, check.ID)
|
||||
}
|
||||
|
||||
slice := WithdrawalCryptoSlice{&local}
|
||||
if err = local.L.LoadWithdrawalHistory(ctx, tx, false, (*[]*WithdrawalCrypto)(&slice), nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.WithdrawalHistory == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
|
||||
local.R.WithdrawalHistory = nil
|
||||
if err = local.L.LoadWithdrawalHistory(ctx, tx, true, &local, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.WithdrawalHistory == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptoToOneSetOpWithdrawalHistoryUsingWithdrawalHistory(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var a WithdrawalCrypto
|
||||
var b, c WithdrawalHistory
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, &a, withdrawalCryptoDBTypes, false, strmangle.SetComplement(withdrawalCryptoPrimaryKeyColumns, withdrawalCryptoColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &b, withdrawalHistoryDBTypes, false, strmangle.SetComplement(withdrawalHistoryPrimaryKeyColumns, withdrawalHistoryColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &c, withdrawalHistoryDBTypes, false, strmangle.SetComplement(withdrawalHistoryPrimaryKeyColumns, withdrawalHistoryColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for i, x := range []*WithdrawalHistory{&b, &c} {
|
||||
err = a.SetWithdrawalHistory(ctx, tx, i != 0, x)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if a.R.WithdrawalHistory != x {
|
||||
t.Error("relationship struct not set to correct value")
|
||||
}
|
||||
|
||||
if x.R.WithdrawalCryptos[0] != &a {
|
||||
t.Error("failed to append to foreign relationship struct")
|
||||
}
|
||||
if a.WithdrawalHistoryID != x.ID {
|
||||
t.Error("foreign key was wrong value", a.WithdrawalHistoryID)
|
||||
}
|
||||
|
||||
zero := reflect.Zero(reflect.TypeOf(a.WithdrawalHistoryID))
|
||||
reflect.Indirect(reflect.ValueOf(&a.WithdrawalHistoryID)).Set(zero)
|
||||
|
||||
if err = a.Reload(ctx, tx); err != nil {
|
||||
t.Fatal("failed to reload", err)
|
||||
}
|
||||
|
||||
if a.WithdrawalHistoryID != x.ID {
|
||||
t.Error("foreign key was wrong value", a.WithdrawalHistoryID, x.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosReload(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = o.Reload(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosReloadAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := WithdrawalCryptoSlice{o}
|
||||
|
||||
if err = slice.ReloadAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosSelect(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := WithdrawalCryptos().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 1 {
|
||||
t.Error("want one record, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
withdrawalCryptoDBTypes = map[string]string{`ID`: `INTEGER`, `Address`: `TEXT`, `AddressTag`: `TEXT`, `Fee`: `REAL`, `WithdrawalHistoryID`: `TEXT`}
|
||||
_ = bytes.MinRead
|
||||
)
|
||||
|
||||
func testWithdrawalCryptosUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if 0 == len(withdrawalCryptoPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with no primary key columns")
|
||||
}
|
||||
if len(withdrawalCryptoAllColumns) == len(withdrawalCryptoPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Update(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only affect one row but affected", rowsAff)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosSliceUpdateAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if len(withdrawalCryptoAllColumns) == len(withdrawalCryptoPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
// Remove Primary keys and unique columns from what we plan to update
|
||||
var fields []string
|
||||
if strmangle.StringSliceMatch(withdrawalCryptoAllColumns, withdrawalCryptoPrimaryKeyColumns) {
|
||||
fields = withdrawalCryptoAllColumns
|
||||
} else {
|
||||
fields = strmangle.SetComplement(
|
||||
withdrawalCryptoAllColumns,
|
||||
withdrawalCryptoPrimaryKeyColumns,
|
||||
)
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
typ := reflect.TypeOf(o).Elem()
|
||||
n := typ.NumField()
|
||||
|
||||
updateMap := M{}
|
||||
for _, col := range fields {
|
||||
for i := 0; i < n; i++ {
|
||||
f := typ.Field(i)
|
||||
if f.Tag.Get("boil") == col {
|
||||
updateMap[col] = value.Field(i).Interface()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
slice := WithdrawalCryptoSlice{o}
|
||||
if rowsAff, err := slice.UpdateAll(ctx, tx, updateMap); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("wanted one record updated but got", rowsAff)
|
||||
}
|
||||
}
|
||||
982
database/models/sqlite3/withdrawal_fiat.go
Normal file
982
database/models/sqlite3/withdrawal_fiat.go
Normal file
@@ -0,0 +1,982 @@
|
||||
// Code generated by SQLBoiler 3.5.0-gct (https://github.com/thrasher-corp/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package sqlite3
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/thrasher-corp/sqlboiler/boil"
|
||||
"github.com/thrasher-corp/sqlboiler/queries"
|
||||
"github.com/thrasher-corp/sqlboiler/queries/qm"
|
||||
"github.com/thrasher-corp/sqlboiler/queries/qmhelper"
|
||||
"github.com/thrasher-corp/sqlboiler/strmangle"
|
||||
)
|
||||
|
||||
// WithdrawalFiat is an object representing the database table.
|
||||
type WithdrawalFiat struct {
|
||||
ID int64 `boil:"id" json:"id" toml:"id" yaml:"id"`
|
||||
BankName string `boil:"bank_name" json:"bank_name" toml:"bank_name" yaml:"bank_name"`
|
||||
BankAddress string `boil:"bank_address" json:"bank_address" toml:"bank_address" yaml:"bank_address"`
|
||||
BankAccountName string `boil:"bank_account_name" json:"bank_account_name" toml:"bank_account_name" yaml:"bank_account_name"`
|
||||
BankAccountNumber string `boil:"bank_account_number" json:"bank_account_number" toml:"bank_account_number" yaml:"bank_account_number"`
|
||||
BSB string `boil:"bsb" json:"bsb" toml:"bsb" yaml:"bsb"`
|
||||
SwiftCode string `boil:"swift_code" json:"swift_code" toml:"swift_code" yaml:"swift_code"`
|
||||
Iban string `boil:"iban" json:"iban" toml:"iban" yaml:"iban"`
|
||||
BankCode float64 `boil:"bank_code" json:"bank_code" toml:"bank_code" yaml:"bank_code"`
|
||||
WithdrawalHistoryID string `boil:"withdrawal_history_id" json:"withdrawal_history_id" toml:"withdrawal_history_id" yaml:"withdrawal_history_id"`
|
||||
|
||||
R *withdrawalFiatR `boil:"-" json:"-" toml:"-" yaml:"-"`
|
||||
L withdrawalFiatL `boil:"-" json:"-" toml:"-" yaml:"-"`
|
||||
}
|
||||
|
||||
var WithdrawalFiatColumns = struct {
|
||||
ID string
|
||||
BankName string
|
||||
BankAddress string
|
||||
BankAccountName string
|
||||
BankAccountNumber string
|
||||
BSB string
|
||||
SwiftCode string
|
||||
Iban string
|
||||
BankCode string
|
||||
WithdrawalHistoryID string
|
||||
}{
|
||||
ID: "id",
|
||||
BankName: "bank_name",
|
||||
BankAddress: "bank_address",
|
||||
BankAccountName: "bank_account_name",
|
||||
BankAccountNumber: "bank_account_number",
|
||||
BSB: "bsb",
|
||||
SwiftCode: "swift_code",
|
||||
Iban: "iban",
|
||||
BankCode: "bank_code",
|
||||
WithdrawalHistoryID: "withdrawal_history_id",
|
||||
}
|
||||
|
||||
// Generated where
|
||||
|
||||
var WithdrawalFiatWhere = struct {
|
||||
ID whereHelperint64
|
||||
BankName whereHelperstring
|
||||
BankAddress whereHelperstring
|
||||
BankAccountName whereHelperstring
|
||||
BankAccountNumber whereHelperstring
|
||||
BSB whereHelperstring
|
||||
SwiftCode whereHelperstring
|
||||
Iban whereHelperstring
|
||||
BankCode whereHelperfloat64
|
||||
WithdrawalHistoryID whereHelperstring
|
||||
}{
|
||||
ID: whereHelperint64{field: "\"withdrawal_fiat\".\"id\""},
|
||||
BankName: whereHelperstring{field: "\"withdrawal_fiat\".\"bank_name\""},
|
||||
BankAddress: whereHelperstring{field: "\"withdrawal_fiat\".\"bank_address\""},
|
||||
BankAccountName: whereHelperstring{field: "\"withdrawal_fiat\".\"bank_account_name\""},
|
||||
BankAccountNumber: whereHelperstring{field: "\"withdrawal_fiat\".\"bank_account_number\""},
|
||||
BSB: whereHelperstring{field: "\"withdrawal_fiat\".\"bsb\""},
|
||||
SwiftCode: whereHelperstring{field: "\"withdrawal_fiat\".\"swift_code\""},
|
||||
Iban: whereHelperstring{field: "\"withdrawal_fiat\".\"iban\""},
|
||||
BankCode: whereHelperfloat64{field: "\"withdrawal_fiat\".\"bank_code\""},
|
||||
WithdrawalHistoryID: whereHelperstring{field: "\"withdrawal_fiat\".\"withdrawal_history_id\""},
|
||||
}
|
||||
|
||||
// WithdrawalFiatRels is where relationship names are stored.
|
||||
var WithdrawalFiatRels = struct {
|
||||
WithdrawalHistory string
|
||||
}{
|
||||
WithdrawalHistory: "WithdrawalHistory",
|
||||
}
|
||||
|
||||
// withdrawalFiatR is where relationships are stored.
|
||||
type withdrawalFiatR struct {
|
||||
WithdrawalHistory *WithdrawalHistory
|
||||
}
|
||||
|
||||
// NewStruct creates a new relationship struct
|
||||
func (*withdrawalFiatR) NewStruct() *withdrawalFiatR {
|
||||
return &withdrawalFiatR{}
|
||||
}
|
||||
|
||||
// withdrawalFiatL is where Load methods for each relationship are stored.
|
||||
type withdrawalFiatL struct{}
|
||||
|
||||
var (
|
||||
withdrawalFiatAllColumns = []string{"id", "bank_name", "bank_address", "bank_account_name", "bank_account_number", "bsb", "swift_code", "iban", "bank_code", "withdrawal_history_id"}
|
||||
withdrawalFiatColumnsWithoutDefault = []string{"bank_name", "bank_address", "bank_account_name", "bank_account_number", "bsb", "swift_code", "iban", "bank_code", "withdrawal_history_id"}
|
||||
withdrawalFiatColumnsWithDefault = []string{"id"}
|
||||
withdrawalFiatPrimaryKeyColumns = []string{"id"}
|
||||
)
|
||||
|
||||
type (
|
||||
// WithdrawalFiatSlice is an alias for a slice of pointers to WithdrawalFiat.
|
||||
// This should generally be used opposed to []WithdrawalFiat.
|
||||
WithdrawalFiatSlice []*WithdrawalFiat
|
||||
// WithdrawalFiatHook is the signature for custom WithdrawalFiat hook methods
|
||||
WithdrawalFiatHook func(context.Context, boil.ContextExecutor, *WithdrawalFiat) error
|
||||
|
||||
withdrawalFiatQuery struct {
|
||||
*queries.Query
|
||||
}
|
||||
)
|
||||
|
||||
// Cache for insert, update and upsert
|
||||
var (
|
||||
withdrawalFiatType = reflect.TypeOf(&WithdrawalFiat{})
|
||||
withdrawalFiatMapping = queries.MakeStructMapping(withdrawalFiatType)
|
||||
withdrawalFiatPrimaryKeyMapping, _ = queries.BindMapping(withdrawalFiatType, withdrawalFiatMapping, withdrawalFiatPrimaryKeyColumns)
|
||||
withdrawalFiatInsertCacheMut sync.RWMutex
|
||||
withdrawalFiatInsertCache = make(map[string]insertCache)
|
||||
withdrawalFiatUpdateCacheMut sync.RWMutex
|
||||
withdrawalFiatUpdateCache = make(map[string]updateCache)
|
||||
withdrawalFiatUpsertCacheMut sync.RWMutex
|
||||
withdrawalFiatUpsertCache = make(map[string]insertCache)
|
||||
)
|
||||
|
||||
var (
|
||||
// Force time package dependency for automated UpdatedAt/CreatedAt.
|
||||
_ = time.Second
|
||||
// Force qmhelper dependency for where clause generation (which doesn't
|
||||
// always happen)
|
||||
_ = qmhelper.Where
|
||||
)
|
||||
|
||||
var withdrawalFiatBeforeInsertHooks []WithdrawalFiatHook
|
||||
var withdrawalFiatBeforeUpdateHooks []WithdrawalFiatHook
|
||||
var withdrawalFiatBeforeDeleteHooks []WithdrawalFiatHook
|
||||
var withdrawalFiatBeforeUpsertHooks []WithdrawalFiatHook
|
||||
|
||||
var withdrawalFiatAfterInsertHooks []WithdrawalFiatHook
|
||||
var withdrawalFiatAfterSelectHooks []WithdrawalFiatHook
|
||||
var withdrawalFiatAfterUpdateHooks []WithdrawalFiatHook
|
||||
var withdrawalFiatAfterDeleteHooks []WithdrawalFiatHook
|
||||
var withdrawalFiatAfterUpsertHooks []WithdrawalFiatHook
|
||||
|
||||
// doBeforeInsertHooks executes all "before insert" hooks.
|
||||
func (o *WithdrawalFiat) doBeforeInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalFiatBeforeInsertHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doBeforeUpdateHooks executes all "before Update" hooks.
|
||||
func (o *WithdrawalFiat) doBeforeUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalFiatBeforeUpdateHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doBeforeDeleteHooks executes all "before Delete" hooks.
|
||||
func (o *WithdrawalFiat) doBeforeDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalFiatBeforeDeleteHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doBeforeUpsertHooks executes all "before Upsert" hooks.
|
||||
func (o *WithdrawalFiat) doBeforeUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalFiatBeforeUpsertHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doAfterInsertHooks executes all "after Insert" hooks.
|
||||
func (o *WithdrawalFiat) doAfterInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalFiatAfterInsertHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doAfterSelectHooks executes all "after Select" hooks.
|
||||
func (o *WithdrawalFiat) doAfterSelectHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalFiatAfterSelectHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doAfterUpdateHooks executes all "after Update" hooks.
|
||||
func (o *WithdrawalFiat) doAfterUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalFiatAfterUpdateHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doAfterDeleteHooks executes all "after Delete" hooks.
|
||||
func (o *WithdrawalFiat) doAfterDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalFiatAfterDeleteHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doAfterUpsertHooks executes all "after Upsert" hooks.
|
||||
func (o *WithdrawalFiat) doAfterUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalFiatAfterUpsertHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddWithdrawalFiatHook registers your hook function for all future operations.
|
||||
func AddWithdrawalFiatHook(hookPoint boil.HookPoint, withdrawalFiatHook WithdrawalFiatHook) {
|
||||
switch hookPoint {
|
||||
case boil.BeforeInsertHook:
|
||||
withdrawalFiatBeforeInsertHooks = append(withdrawalFiatBeforeInsertHooks, withdrawalFiatHook)
|
||||
case boil.BeforeUpdateHook:
|
||||
withdrawalFiatBeforeUpdateHooks = append(withdrawalFiatBeforeUpdateHooks, withdrawalFiatHook)
|
||||
case boil.BeforeDeleteHook:
|
||||
withdrawalFiatBeforeDeleteHooks = append(withdrawalFiatBeforeDeleteHooks, withdrawalFiatHook)
|
||||
case boil.BeforeUpsertHook:
|
||||
withdrawalFiatBeforeUpsertHooks = append(withdrawalFiatBeforeUpsertHooks, withdrawalFiatHook)
|
||||
case boil.AfterInsertHook:
|
||||
withdrawalFiatAfterInsertHooks = append(withdrawalFiatAfterInsertHooks, withdrawalFiatHook)
|
||||
case boil.AfterSelectHook:
|
||||
withdrawalFiatAfterSelectHooks = append(withdrawalFiatAfterSelectHooks, withdrawalFiatHook)
|
||||
case boil.AfterUpdateHook:
|
||||
withdrawalFiatAfterUpdateHooks = append(withdrawalFiatAfterUpdateHooks, withdrawalFiatHook)
|
||||
case boil.AfterDeleteHook:
|
||||
withdrawalFiatAfterDeleteHooks = append(withdrawalFiatAfterDeleteHooks, withdrawalFiatHook)
|
||||
case boil.AfterUpsertHook:
|
||||
withdrawalFiatAfterUpsertHooks = append(withdrawalFiatAfterUpsertHooks, withdrawalFiatHook)
|
||||
}
|
||||
}
|
||||
|
||||
// One returns a single withdrawalFiat record from the query.
|
||||
func (q withdrawalFiatQuery) One(ctx context.Context, exec boil.ContextExecutor) (*WithdrawalFiat, error) {
|
||||
o := &WithdrawalFiat{}
|
||||
|
||||
queries.SetLimit(q.Query, 1)
|
||||
|
||||
err := q.Bind(ctx, exec, o)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == sql.ErrNoRows {
|
||||
return nil, sql.ErrNoRows
|
||||
}
|
||||
return nil, errors.Wrap(err, "sqlite3: failed to execute a one query for withdrawal_fiat")
|
||||
}
|
||||
|
||||
if err := o.doAfterSelectHooks(ctx, exec); err != nil {
|
||||
return o, err
|
||||
}
|
||||
|
||||
return o, nil
|
||||
}
|
||||
|
||||
// All returns all WithdrawalFiat records from the query.
|
||||
func (q withdrawalFiatQuery) All(ctx context.Context, exec boil.ContextExecutor) (WithdrawalFiatSlice, error) {
|
||||
var o []*WithdrawalFiat
|
||||
|
||||
err := q.Bind(ctx, exec, &o)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "sqlite3: failed to assign all query results to WithdrawalFiat slice")
|
||||
}
|
||||
|
||||
if len(withdrawalFiatAfterSelectHooks) != 0 {
|
||||
for _, obj := range o {
|
||||
if err := obj.doAfterSelectHooks(ctx, exec); err != nil {
|
||||
return o, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return o, nil
|
||||
}
|
||||
|
||||
// Count returns the count of all WithdrawalFiat records in the query.
|
||||
func (q withdrawalFiatQuery) Count(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
var count int64
|
||||
|
||||
queries.SetSelect(q.Query, nil)
|
||||
queries.SetCount(q.Query)
|
||||
|
||||
err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: failed to count withdrawal_fiat rows")
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// Exists checks if the row exists in the table.
|
||||
func (q withdrawalFiatQuery) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
|
||||
var count int64
|
||||
|
||||
queries.SetSelect(q.Query, nil)
|
||||
queries.SetCount(q.Query)
|
||||
queries.SetLimit(q.Query, 1)
|
||||
|
||||
err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "sqlite3: failed to check if withdrawal_fiat exists")
|
||||
}
|
||||
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
// WithdrawalHistory pointed to by the foreign key.
|
||||
func (o *WithdrawalFiat) WithdrawalHistory(mods ...qm.QueryMod) withdrawalHistoryQuery {
|
||||
queryMods := []qm.QueryMod{
|
||||
qm.Where("\"id\" = ?", o.WithdrawalHistoryID),
|
||||
}
|
||||
|
||||
queryMods = append(queryMods, mods...)
|
||||
|
||||
query := WithdrawalHistories(queryMods...)
|
||||
queries.SetFrom(query.Query, "\"withdrawal_history\"")
|
||||
|
||||
return query
|
||||
}
|
||||
|
||||
// LoadWithdrawalHistory allows an eager lookup of values, cached into the
|
||||
// loaded structs of the objects. This is for an N-1 relationship.
|
||||
func (withdrawalFiatL) LoadWithdrawalHistory(ctx context.Context, e boil.ContextExecutor, singular bool, maybeWithdrawalFiat interface{}, mods queries.Applicator) error {
|
||||
var slice []*WithdrawalFiat
|
||||
var object *WithdrawalFiat
|
||||
|
||||
if singular {
|
||||
object = maybeWithdrawalFiat.(*WithdrawalFiat)
|
||||
} else {
|
||||
slice = *maybeWithdrawalFiat.(*[]*WithdrawalFiat)
|
||||
}
|
||||
|
||||
args := make([]interface{}, 0, 1)
|
||||
if singular {
|
||||
if object.R == nil {
|
||||
object.R = &withdrawalFiatR{}
|
||||
}
|
||||
args = append(args, object.WithdrawalHistoryID)
|
||||
|
||||
} else {
|
||||
Outer:
|
||||
for _, obj := range slice {
|
||||
if obj.R == nil {
|
||||
obj.R = &withdrawalFiatR{}
|
||||
}
|
||||
|
||||
for _, a := range args {
|
||||
if a == obj.WithdrawalHistoryID {
|
||||
continue Outer
|
||||
}
|
||||
}
|
||||
|
||||
args = append(args, obj.WithdrawalHistoryID)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if len(args) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
query := NewQuery(qm.From(`withdrawal_history`), qm.WhereIn(`withdrawal_history.id in ?`, args...))
|
||||
if mods != nil {
|
||||
mods.Apply(query)
|
||||
}
|
||||
|
||||
results, err := query.QueryContext(ctx, e)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to eager load WithdrawalHistory")
|
||||
}
|
||||
|
||||
var resultSlice []*WithdrawalHistory
|
||||
if err = queries.Bind(results, &resultSlice); err != nil {
|
||||
return errors.Wrap(err, "failed to bind eager loaded slice WithdrawalHistory")
|
||||
}
|
||||
|
||||
if err = results.Close(); err != nil {
|
||||
return errors.Wrap(err, "failed to close results of eager load for withdrawal_history")
|
||||
}
|
||||
if err = results.Err(); err != nil {
|
||||
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for withdrawal_history")
|
||||
}
|
||||
|
||||
if len(withdrawalFiatAfterSelectHooks) != 0 {
|
||||
for _, obj := range resultSlice {
|
||||
if err := obj.doAfterSelectHooks(ctx, e); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(resultSlice) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if singular {
|
||||
foreign := resultSlice[0]
|
||||
object.R.WithdrawalHistory = foreign
|
||||
if foreign.R == nil {
|
||||
foreign.R = &withdrawalHistoryR{}
|
||||
}
|
||||
foreign.R.WithdrawalFiats = append(foreign.R.WithdrawalFiats, object)
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, local := range slice {
|
||||
for _, foreign := range resultSlice {
|
||||
if local.WithdrawalHistoryID == foreign.ID {
|
||||
local.R.WithdrawalHistory = foreign
|
||||
if foreign.R == nil {
|
||||
foreign.R = &withdrawalHistoryR{}
|
||||
}
|
||||
foreign.R.WithdrawalFiats = append(foreign.R.WithdrawalFiats, local)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetWithdrawalHistory of the withdrawalFiat to the related item.
|
||||
// Sets o.R.WithdrawalHistory to related.
|
||||
// Adds o to related.R.WithdrawalFiats.
|
||||
func (o *WithdrawalFiat) SetWithdrawalHistory(ctx context.Context, exec boil.ContextExecutor, insert bool, related *WithdrawalHistory) error {
|
||||
var err error
|
||||
if insert {
|
||||
if err = related.Insert(ctx, exec, boil.Infer()); err != nil {
|
||||
return errors.Wrap(err, "failed to insert into foreign table")
|
||||
}
|
||||
}
|
||||
|
||||
updateQuery := fmt.Sprintf(
|
||||
"UPDATE \"withdrawal_fiat\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 0, []string{"withdrawal_history_id"}),
|
||||
strmangle.WhereClause("\"", "\"", 0, withdrawalFiatPrimaryKeyColumns),
|
||||
)
|
||||
values := []interface{}{related.ID, o.ID}
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, updateQuery)
|
||||
fmt.Fprintln(boil.DebugWriter, values)
|
||||
}
|
||||
|
||||
if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil {
|
||||
return errors.Wrap(err, "failed to update local table")
|
||||
}
|
||||
|
||||
o.WithdrawalHistoryID = related.ID
|
||||
if o.R == nil {
|
||||
o.R = &withdrawalFiatR{
|
||||
WithdrawalHistory: related,
|
||||
}
|
||||
} else {
|
||||
o.R.WithdrawalHistory = related
|
||||
}
|
||||
|
||||
if related.R == nil {
|
||||
related.R = &withdrawalHistoryR{
|
||||
WithdrawalFiats: WithdrawalFiatSlice{o},
|
||||
}
|
||||
} else {
|
||||
related.R.WithdrawalFiats = append(related.R.WithdrawalFiats, o)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// WithdrawalFiats retrieves all the records using an executor.
|
||||
func WithdrawalFiats(mods ...qm.QueryMod) withdrawalFiatQuery {
|
||||
mods = append(mods, qm.From("\"withdrawal_fiat\""))
|
||||
return withdrawalFiatQuery{NewQuery(mods...)}
|
||||
}
|
||||
|
||||
// FindWithdrawalFiat retrieves a single record by ID with an executor.
|
||||
// If selectCols is empty Find will return all columns.
|
||||
func FindWithdrawalFiat(ctx context.Context, exec boil.ContextExecutor, iD int64, selectCols ...string) (*WithdrawalFiat, error) {
|
||||
withdrawalFiatObj := &WithdrawalFiat{}
|
||||
|
||||
sel := "*"
|
||||
if len(selectCols) > 0 {
|
||||
sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
|
||||
}
|
||||
query := fmt.Sprintf(
|
||||
"select %s from \"withdrawal_fiat\" where \"id\"=?", sel,
|
||||
)
|
||||
|
||||
q := queries.Raw(query, iD)
|
||||
|
||||
err := q.Bind(ctx, exec, withdrawalFiatObj)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == sql.ErrNoRows {
|
||||
return nil, sql.ErrNoRows
|
||||
}
|
||||
return nil, errors.Wrap(err, "sqlite3: unable to select from withdrawal_fiat")
|
||||
}
|
||||
|
||||
return withdrawalFiatObj, nil
|
||||
}
|
||||
|
||||
// Insert a single record using an executor.
|
||||
// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.
|
||||
func (o *WithdrawalFiat) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
|
||||
if o == nil {
|
||||
return errors.New("sqlite3: no withdrawal_fiat provided for insertion")
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
if err := o.doBeforeInsertHooks(ctx, exec); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
nzDefaults := queries.NonZeroDefaultSet(withdrawalFiatColumnsWithDefault, o)
|
||||
|
||||
key := makeCacheKey(columns, nzDefaults)
|
||||
withdrawalFiatInsertCacheMut.RLock()
|
||||
cache, cached := withdrawalFiatInsertCache[key]
|
||||
withdrawalFiatInsertCacheMut.RUnlock()
|
||||
|
||||
if !cached {
|
||||
wl, returnColumns := columns.InsertColumnSet(
|
||||
withdrawalFiatAllColumns,
|
||||
withdrawalFiatColumnsWithDefault,
|
||||
withdrawalFiatColumnsWithoutDefault,
|
||||
nzDefaults,
|
||||
)
|
||||
|
||||
cache.valueMapping, err = queries.BindMapping(withdrawalFiatType, withdrawalFiatMapping, wl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cache.retMapping, err = queries.BindMapping(withdrawalFiatType, withdrawalFiatMapping, returnColumns)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(wl) != 0 {
|
||||
cache.query = fmt.Sprintf("INSERT INTO \"withdrawal_fiat\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
|
||||
} else {
|
||||
cache.query = "INSERT INTO \"withdrawal_fiat\" () VALUES ()%s%s"
|
||||
}
|
||||
|
||||
var queryOutput, queryReturning string
|
||||
|
||||
if len(cache.retMapping) != 0 {
|
||||
cache.retQuery = fmt.Sprintf("SELECT \"%s\" FROM \"withdrawal_fiat\" WHERE %s", strings.Join(returnColumns, "\",\""), strmangle.WhereClause("\"", "\"", 0, withdrawalFiatPrimaryKeyColumns))
|
||||
}
|
||||
|
||||
cache.query = fmt.Sprintf(cache.query, queryOutput, queryReturning)
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
vals := queries.ValuesFromMapping(value, cache.valueMapping)
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, cache.query)
|
||||
fmt.Fprintln(boil.DebugWriter, vals)
|
||||
}
|
||||
|
||||
result, err := exec.ExecContext(ctx, cache.query, vals...)
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "sqlite3: unable to insert into withdrawal_fiat")
|
||||
}
|
||||
|
||||
var lastID int64
|
||||
var identifierCols []interface{}
|
||||
|
||||
if len(cache.retMapping) == 0 {
|
||||
goto CacheNoHooks
|
||||
}
|
||||
|
||||
lastID, err = result.LastInsertId()
|
||||
if err != nil {
|
||||
return ErrSyncFail
|
||||
}
|
||||
|
||||
o.ID = int64(lastID)
|
||||
if lastID != 0 && len(cache.retMapping) == 1 && cache.retMapping[0] == withdrawalFiatMapping["ID"] {
|
||||
goto CacheNoHooks
|
||||
}
|
||||
|
||||
identifierCols = []interface{}{
|
||||
o.ID,
|
||||
}
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, cache.retQuery)
|
||||
fmt.Fprintln(boil.DebugWriter, identifierCols...)
|
||||
}
|
||||
|
||||
err = exec.QueryRowContext(ctx, cache.retQuery, identifierCols...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "sqlite3: unable to populate default values for withdrawal_fiat")
|
||||
}
|
||||
|
||||
CacheNoHooks:
|
||||
if !cached {
|
||||
withdrawalFiatInsertCacheMut.Lock()
|
||||
withdrawalFiatInsertCache[key] = cache
|
||||
withdrawalFiatInsertCacheMut.Unlock()
|
||||
}
|
||||
|
||||
return o.doAfterInsertHooks(ctx, exec)
|
||||
}
|
||||
|
||||
// Update uses an executor to update the WithdrawalFiat.
|
||||
// See boil.Columns.UpdateColumnSet documentation to understand column list inference for updates.
|
||||
// Update does not automatically update the record in case of default values. Use .Reload() to refresh the records.
|
||||
func (o *WithdrawalFiat) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error) {
|
||||
var err error
|
||||
if err = o.doBeforeUpdateHooks(ctx, exec); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
key := makeCacheKey(columns, nil)
|
||||
withdrawalFiatUpdateCacheMut.RLock()
|
||||
cache, cached := withdrawalFiatUpdateCache[key]
|
||||
withdrawalFiatUpdateCacheMut.RUnlock()
|
||||
|
||||
if !cached {
|
||||
wl := columns.UpdateColumnSet(
|
||||
withdrawalFiatAllColumns,
|
||||
withdrawalFiatPrimaryKeyColumns,
|
||||
)
|
||||
|
||||
if len(wl) == 0 {
|
||||
return 0, errors.New("sqlite3: unable to update withdrawal_fiat, could not build whitelist")
|
||||
}
|
||||
|
||||
cache.query = fmt.Sprintf("UPDATE \"withdrawal_fiat\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 0, wl),
|
||||
strmangle.WhereClause("\"", "\"", 0, withdrawalFiatPrimaryKeyColumns),
|
||||
)
|
||||
cache.valueMapping, err = queries.BindMapping(withdrawalFiatType, withdrawalFiatMapping, append(wl, withdrawalFiatPrimaryKeyColumns...))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping)
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, cache.query)
|
||||
fmt.Fprintln(boil.DebugWriter, values)
|
||||
}
|
||||
|
||||
var result sql.Result
|
||||
result, err = exec.ExecContext(ctx, cache.query, values...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to update withdrawal_fiat row")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: failed to get rows affected by update for withdrawal_fiat")
|
||||
}
|
||||
|
||||
if !cached {
|
||||
withdrawalFiatUpdateCacheMut.Lock()
|
||||
withdrawalFiatUpdateCache[key] = cache
|
||||
withdrawalFiatUpdateCacheMut.Unlock()
|
||||
}
|
||||
|
||||
return rowsAff, o.doAfterUpdateHooks(ctx, exec)
|
||||
}
|
||||
|
||||
// UpdateAll updates all rows with the specified column values.
|
||||
func (q withdrawalFiatQuery) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
|
||||
queries.SetUpdate(q.Query, cols)
|
||||
|
||||
result, err := q.Query.ExecContext(ctx, exec)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to update all for withdrawal_fiat")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to retrieve rows affected for withdrawal_fiat")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// UpdateAll updates all rows with the specified column values, using an executor.
|
||||
func (o WithdrawalFiatSlice) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
|
||||
ln := int64(len(o))
|
||||
if ln == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
if len(cols) == 0 {
|
||||
return 0, errors.New("sqlite3: update all requires at least one column argument")
|
||||
}
|
||||
|
||||
colNames := make([]string, len(cols))
|
||||
args := make([]interface{}, len(cols))
|
||||
|
||||
i := 0
|
||||
for name, value := range cols {
|
||||
colNames[i] = name
|
||||
args[i] = value
|
||||
i++
|
||||
}
|
||||
|
||||
// Append all of the primary key values for each column
|
||||
for _, obj := range o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), withdrawalFiatPrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := fmt.Sprintf("UPDATE \"withdrawal_fiat\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 0, colNames),
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, withdrawalFiatPrimaryKeyColumns, len(o)))
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, sql)
|
||||
fmt.Fprintln(boil.DebugWriter, args...)
|
||||
}
|
||||
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to update all in withdrawalFiat slice")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to retrieve rows affected all in update all withdrawalFiat")
|
||||
}
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// Delete deletes a single WithdrawalFiat record with an executor.
|
||||
// Delete will match against the primary key column to find the record to delete.
|
||||
func (o *WithdrawalFiat) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if o == nil {
|
||||
return 0, errors.New("sqlite3: no WithdrawalFiat provided for delete")
|
||||
}
|
||||
|
||||
if err := o.doBeforeDeleteHooks(ctx, exec); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), withdrawalFiatPrimaryKeyMapping)
|
||||
sql := "DELETE FROM \"withdrawal_fiat\" WHERE \"id\"=?"
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, sql)
|
||||
fmt.Fprintln(boil.DebugWriter, args...)
|
||||
}
|
||||
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to delete from withdrawal_fiat")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: failed to get rows affected by delete for withdrawal_fiat")
|
||||
}
|
||||
|
||||
if err := o.doAfterDeleteHooks(ctx, exec); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// DeleteAll deletes all matching rows.
|
||||
func (q withdrawalFiatQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if q.Query == nil {
|
||||
return 0, errors.New("sqlite3: no withdrawalFiatQuery provided for delete all")
|
||||
}
|
||||
|
||||
queries.SetDelete(q.Query)
|
||||
|
||||
result, err := q.Query.ExecContext(ctx, exec)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to delete all from withdrawal_fiat")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: failed to get rows affected by deleteall for withdrawal_fiat")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// DeleteAll deletes all rows in the slice, using an executor.
|
||||
func (o WithdrawalFiatSlice) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if len(o) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
if len(withdrawalFiatBeforeDeleteHooks) != 0 {
|
||||
for _, obj := range o {
|
||||
if err := obj.doBeforeDeleteHooks(ctx, exec); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var args []interface{}
|
||||
for _, obj := range o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), withdrawalFiatPrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := "DELETE FROM \"withdrawal_fiat\" WHERE " +
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, withdrawalFiatPrimaryKeyColumns, len(o))
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, sql)
|
||||
fmt.Fprintln(boil.DebugWriter, args)
|
||||
}
|
||||
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to delete all from withdrawalFiat slice")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: failed to get rows affected by deleteall for withdrawal_fiat")
|
||||
}
|
||||
|
||||
if len(withdrawalFiatAfterDeleteHooks) != 0 {
|
||||
for _, obj := range o {
|
||||
if err := obj.doAfterDeleteHooks(ctx, exec); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// Reload refetches the object from the database
|
||||
// using the primary keys with an executor.
|
||||
func (o *WithdrawalFiat) Reload(ctx context.Context, exec boil.ContextExecutor) error {
|
||||
ret, err := FindWithdrawalFiat(ctx, exec, o.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*o = *ret
|
||||
return nil
|
||||
}
|
||||
|
||||
// ReloadAll refetches every row with matching primary key column values
|
||||
// and overwrites the original object slice with the newly updated slice.
|
||||
func (o *WithdrawalFiatSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error {
|
||||
if o == nil || len(*o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
slice := WithdrawalFiatSlice{}
|
||||
var args []interface{}
|
||||
for _, obj := range *o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), withdrawalFiatPrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := "SELECT \"withdrawal_fiat\".* FROM \"withdrawal_fiat\" WHERE " +
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, withdrawalFiatPrimaryKeyColumns, len(*o))
|
||||
|
||||
q := queries.Raw(sql, args...)
|
||||
|
||||
err := q.Bind(ctx, exec, &slice)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "sqlite3: unable to reload all in WithdrawalFiatSlice")
|
||||
}
|
||||
|
||||
*o = slice
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// WithdrawalFiatExists checks if the WithdrawalFiat row exists.
|
||||
func WithdrawalFiatExists(ctx context.Context, exec boil.ContextExecutor, iD int64) (bool, error) {
|
||||
var exists bool
|
||||
sql := "select exists(select 1 from \"withdrawal_fiat\" where \"id\"=? limit 1)"
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, sql)
|
||||
fmt.Fprintln(boil.DebugWriter, iD)
|
||||
}
|
||||
|
||||
row := exec.QueryRowContext(ctx, sql, iD)
|
||||
|
||||
err := row.Scan(&exists)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "sqlite3: unable to check if withdrawal_fiat exists")
|
||||
}
|
||||
|
||||
return exists, nil
|
||||
}
|
||||
793
database/models/sqlite3/withdrawal_fiat_test.go
Normal file
793
database/models/sqlite3/withdrawal_fiat_test.go
Normal file
@@ -0,0 +1,793 @@
|
||||
// Code generated by SQLBoiler 3.5.0-gct (https://github.com/thrasher-corp/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package sqlite3
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-corp/sqlboiler/boil"
|
||||
"github.com/thrasher-corp/sqlboiler/queries"
|
||||
"github.com/thrasher-corp/sqlboiler/randomize"
|
||||
"github.com/thrasher-corp/sqlboiler/strmangle"
|
||||
)
|
||||
|
||||
var (
|
||||
// Relationships sometimes use the reflection helper queries.Equal/queries.Assign
|
||||
// so force a package dependency in case they don't.
|
||||
_ = queries.Equal
|
||||
)
|
||||
|
||||
func testWithdrawalFiats(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
query := WithdrawalFiats()
|
||||
|
||||
if query.Query == nil {
|
||||
t.Error("expected a query, got nothing")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsDelete(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Delete(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsQueryDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := WithdrawalFiats().DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsSliceDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := WithdrawalFiatSlice{o}
|
||||
|
||||
if rowsAff, err := slice.DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsExists(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
e, err := WithdrawalFiatExists(ctx, tx, o.ID)
|
||||
if err != nil {
|
||||
t.Errorf("Unable to check if WithdrawalFiat exists: %s", err)
|
||||
}
|
||||
if !e {
|
||||
t.Errorf("Expected WithdrawalFiatExists to return true, but got false.")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsFind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
withdrawalFiatFound, err := FindWithdrawalFiat(ctx, tx, o.ID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if withdrawalFiatFound == nil {
|
||||
t.Error("want a record, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsBind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = WithdrawalFiats().Bind(ctx, tx, o); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsOne(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if x, err := WithdrawalFiats().One(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if x == nil {
|
||||
t.Error("expected to get a non nil record")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
withdrawalFiatOne := &WithdrawalFiat{}
|
||||
withdrawalFiatTwo := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, withdrawalFiatOne, withdrawalFiatDBTypes, false, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, withdrawalFiatTwo, withdrawalFiatDBTypes, false, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = withdrawalFiatOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = withdrawalFiatTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := WithdrawalFiats().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 2 {
|
||||
t.Error("want 2 records, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsCount(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
seed := randomize.NewSeed()
|
||||
withdrawalFiatOne := &WithdrawalFiat{}
|
||||
withdrawalFiatTwo := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, withdrawalFiatOne, withdrawalFiatDBTypes, false, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, withdrawalFiatTwo, withdrawalFiatDBTypes, false, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = withdrawalFiatOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = withdrawalFiatTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 2 {
|
||||
t.Error("want 2 records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func withdrawalFiatBeforeInsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatAfterInsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatAfterSelectHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatBeforeUpdateHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatAfterUpdateHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatBeforeDeleteHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatAfterDeleteHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatBeforeUpsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatAfterUpsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsHooks(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
empty := &WithdrawalFiat{}
|
||||
o := &WithdrawalFiat{}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, false); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat object: %s", err)
|
||||
}
|
||||
|
||||
AddWithdrawalFiatHook(boil.BeforeInsertHook, withdrawalFiatBeforeInsertHook)
|
||||
if err = o.doBeforeInsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeInsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeInsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatBeforeInsertHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.AfterInsertHook, withdrawalFiatAfterInsertHook)
|
||||
if err = o.doAfterInsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterInsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterInsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatAfterInsertHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.AfterSelectHook, withdrawalFiatAfterSelectHook)
|
||||
if err = o.doAfterSelectHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterSelectHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterSelectHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatAfterSelectHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.BeforeUpdateHook, withdrawalFiatBeforeUpdateHook)
|
||||
if err = o.doBeforeUpdateHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeUpdateHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeUpdateHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatBeforeUpdateHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.AfterUpdateHook, withdrawalFiatAfterUpdateHook)
|
||||
if err = o.doAfterUpdateHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterUpdateHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterUpdateHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatAfterUpdateHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.BeforeDeleteHook, withdrawalFiatBeforeDeleteHook)
|
||||
if err = o.doBeforeDeleteHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeDeleteHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeDeleteHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatBeforeDeleteHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.AfterDeleteHook, withdrawalFiatAfterDeleteHook)
|
||||
if err = o.doAfterDeleteHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterDeleteHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterDeleteHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatAfterDeleteHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.BeforeUpsertHook, withdrawalFiatBeforeUpsertHook)
|
||||
if err = o.doBeforeUpsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeUpsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeUpsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatBeforeUpsertHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.AfterUpsertHook, withdrawalFiatAfterUpsertHook)
|
||||
if err = o.doAfterUpsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterUpsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterUpsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatAfterUpsertHooks = []WithdrawalFiatHook{}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsInsert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsInsertWhitelist(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Whitelist(withdrawalFiatColumnsWithoutDefault...)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatToOneWithdrawalHistoryUsingWithdrawalHistory(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var local WithdrawalFiat
|
||||
var foreign WithdrawalHistory
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err := randomize.Struct(seed, &local, withdrawalFiatDBTypes, false, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
if err := randomize.Struct(seed, &foreign, withdrawalHistoryDBTypes, false, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
if err := foreign.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
local.WithdrawalHistoryID = foreign.ID
|
||||
if err := local.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
check, err := local.WithdrawalHistory().One(ctx, tx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if check.ID != foreign.ID {
|
||||
t.Errorf("want: %v, got %v", foreign.ID, check.ID)
|
||||
}
|
||||
|
||||
slice := WithdrawalFiatSlice{&local}
|
||||
if err = local.L.LoadWithdrawalHistory(ctx, tx, false, (*[]*WithdrawalFiat)(&slice), nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.WithdrawalHistory == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
|
||||
local.R.WithdrawalHistory = nil
|
||||
if err = local.L.LoadWithdrawalHistory(ctx, tx, true, &local, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.WithdrawalHistory == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatToOneSetOpWithdrawalHistoryUsingWithdrawalHistory(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var a WithdrawalFiat
|
||||
var b, c WithdrawalHistory
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, &a, withdrawalFiatDBTypes, false, strmangle.SetComplement(withdrawalFiatPrimaryKeyColumns, withdrawalFiatColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &b, withdrawalHistoryDBTypes, false, strmangle.SetComplement(withdrawalHistoryPrimaryKeyColumns, withdrawalHistoryColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &c, withdrawalHistoryDBTypes, false, strmangle.SetComplement(withdrawalHistoryPrimaryKeyColumns, withdrawalHistoryColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for i, x := range []*WithdrawalHistory{&b, &c} {
|
||||
err = a.SetWithdrawalHistory(ctx, tx, i != 0, x)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if a.R.WithdrawalHistory != x {
|
||||
t.Error("relationship struct not set to correct value")
|
||||
}
|
||||
|
||||
if x.R.WithdrawalFiats[0] != &a {
|
||||
t.Error("failed to append to foreign relationship struct")
|
||||
}
|
||||
if a.WithdrawalHistoryID != x.ID {
|
||||
t.Error("foreign key was wrong value", a.WithdrawalHistoryID)
|
||||
}
|
||||
|
||||
zero := reflect.Zero(reflect.TypeOf(a.WithdrawalHistoryID))
|
||||
reflect.Indirect(reflect.ValueOf(&a.WithdrawalHistoryID)).Set(zero)
|
||||
|
||||
if err = a.Reload(ctx, tx); err != nil {
|
||||
t.Fatal("failed to reload", err)
|
||||
}
|
||||
|
||||
if a.WithdrawalHistoryID != x.ID {
|
||||
t.Error("foreign key was wrong value", a.WithdrawalHistoryID, x.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsReload(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = o.Reload(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsReloadAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := WithdrawalFiatSlice{o}
|
||||
|
||||
if err = slice.ReloadAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsSelect(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := WithdrawalFiats().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 1 {
|
||||
t.Error("want one record, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
withdrawalFiatDBTypes = map[string]string{`ID`: `INTEGER`, `BankName`: `TEXT`, `BankAddress`: `TEXT`, `BankAccountName`: `TEXT`, `BankAccountNumber`: `TEXT`, `BSB`: `TEXT`, `SwiftCode`: `TEXT`, `Iban`: `TEXT`, `BankCode`: `REAL`, `WithdrawalHistoryID`: `TEXT`}
|
||||
_ = bytes.MinRead
|
||||
)
|
||||
|
||||
func testWithdrawalFiatsUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if 0 == len(withdrawalFiatPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with no primary key columns")
|
||||
}
|
||||
if len(withdrawalFiatAllColumns) == len(withdrawalFiatPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Update(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only affect one row but affected", rowsAff)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsSliceUpdateAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if len(withdrawalFiatAllColumns) == len(withdrawalFiatPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
// Remove Primary keys and unique columns from what we plan to update
|
||||
var fields []string
|
||||
if strmangle.StringSliceMatch(withdrawalFiatAllColumns, withdrawalFiatPrimaryKeyColumns) {
|
||||
fields = withdrawalFiatAllColumns
|
||||
} else {
|
||||
fields = strmangle.SetComplement(
|
||||
withdrawalFiatAllColumns,
|
||||
withdrawalFiatPrimaryKeyColumns,
|
||||
)
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
typ := reflect.TypeOf(o).Elem()
|
||||
n := typ.NumField()
|
||||
|
||||
updateMap := M{}
|
||||
for _, col := range fields {
|
||||
for i := 0; i < n; i++ {
|
||||
f := typ.Field(i)
|
||||
if f.Tag.Get("boil") == col {
|
||||
updateMap[col] = value.Field(i).Interface()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
slice := WithdrawalFiatSlice{o}
|
||||
if rowsAff, err := slice.UpdateAll(ctx, tx, updateMap); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("wanted one record updated but got", rowsAff)
|
||||
}
|
||||
}
|
||||
1151
database/models/sqlite3/withdrawal_history.go
Normal file
1151
database/models/sqlite3/withdrawal_history.go
Normal file
File diff suppressed because it is too large
Load Diff
991
database/models/sqlite3/withdrawal_history_test.go
Normal file
991
database/models/sqlite3/withdrawal_history_test.go
Normal file
@@ -0,0 +1,991 @@
|
||||
// Code generated by SQLBoiler 3.5.0-gct (https://github.com/thrasher-corp/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package sqlite3
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-corp/sqlboiler/boil"
|
||||
"github.com/thrasher-corp/sqlboiler/queries"
|
||||
"github.com/thrasher-corp/sqlboiler/randomize"
|
||||
"github.com/thrasher-corp/sqlboiler/strmangle"
|
||||
)
|
||||
|
||||
var (
|
||||
// Relationships sometimes use the reflection helper queries.Equal/queries.Assign
|
||||
// so force a package dependency in case they don't.
|
||||
_ = queries.Equal
|
||||
)
|
||||
|
||||
func testWithdrawalHistories(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
query := WithdrawalHistories()
|
||||
|
||||
if query.Query == nil {
|
||||
t.Error("expected a query, got nothing")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesDelete(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Delete(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := WithdrawalHistories().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesQueryDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := WithdrawalHistories().DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := WithdrawalHistories().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesSliceDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := WithdrawalHistorySlice{o}
|
||||
|
||||
if rowsAff, err := slice.DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := WithdrawalHistories().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesExists(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
e, err := WithdrawalHistoryExists(ctx, tx, o.ID)
|
||||
if err != nil {
|
||||
t.Errorf("Unable to check if WithdrawalHistory exists: %s", err)
|
||||
}
|
||||
if !e {
|
||||
t.Errorf("Expected WithdrawalHistoryExists to return true, but got false.")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesFind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
withdrawalHistoryFound, err := FindWithdrawalHistory(ctx, tx, o.ID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if withdrawalHistoryFound == nil {
|
||||
t.Error("want a record, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesBind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = WithdrawalHistories().Bind(ctx, tx, o); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesOne(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if x, err := WithdrawalHistories().One(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if x == nil {
|
||||
t.Error("expected to get a non nil record")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
withdrawalHistoryOne := &WithdrawalHistory{}
|
||||
withdrawalHistoryTwo := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, withdrawalHistoryOne, withdrawalHistoryDBTypes, false, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, withdrawalHistoryTwo, withdrawalHistoryDBTypes, false, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = withdrawalHistoryOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = withdrawalHistoryTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := WithdrawalHistories().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 2 {
|
||||
t.Error("want 2 records, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesCount(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
seed := randomize.NewSeed()
|
||||
withdrawalHistoryOne := &WithdrawalHistory{}
|
||||
withdrawalHistoryTwo := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, withdrawalHistoryOne, withdrawalHistoryDBTypes, false, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, withdrawalHistoryTwo, withdrawalHistoryDBTypes, false, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = withdrawalHistoryOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = withdrawalHistoryTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalHistories().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 2 {
|
||||
t.Error("want 2 records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func withdrawalHistoryBeforeInsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalHistory) error {
|
||||
*o = WithdrawalHistory{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalHistoryAfterInsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalHistory) error {
|
||||
*o = WithdrawalHistory{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalHistoryAfterSelectHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalHistory) error {
|
||||
*o = WithdrawalHistory{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalHistoryBeforeUpdateHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalHistory) error {
|
||||
*o = WithdrawalHistory{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalHistoryAfterUpdateHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalHistory) error {
|
||||
*o = WithdrawalHistory{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalHistoryBeforeDeleteHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalHistory) error {
|
||||
*o = WithdrawalHistory{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalHistoryAfterDeleteHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalHistory) error {
|
||||
*o = WithdrawalHistory{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalHistoryBeforeUpsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalHistory) error {
|
||||
*o = WithdrawalHistory{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalHistoryAfterUpsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalHistory) error {
|
||||
*o = WithdrawalHistory{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesHooks(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
empty := &WithdrawalHistory{}
|
||||
o := &WithdrawalHistory{}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, false); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory object: %s", err)
|
||||
}
|
||||
|
||||
AddWithdrawalHistoryHook(boil.BeforeInsertHook, withdrawalHistoryBeforeInsertHook)
|
||||
if err = o.doBeforeInsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeInsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeInsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalHistoryBeforeInsertHooks = []WithdrawalHistoryHook{}
|
||||
|
||||
AddWithdrawalHistoryHook(boil.AfterInsertHook, withdrawalHistoryAfterInsertHook)
|
||||
if err = o.doAfterInsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterInsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterInsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalHistoryAfterInsertHooks = []WithdrawalHistoryHook{}
|
||||
|
||||
AddWithdrawalHistoryHook(boil.AfterSelectHook, withdrawalHistoryAfterSelectHook)
|
||||
if err = o.doAfterSelectHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterSelectHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterSelectHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalHistoryAfterSelectHooks = []WithdrawalHistoryHook{}
|
||||
|
||||
AddWithdrawalHistoryHook(boil.BeforeUpdateHook, withdrawalHistoryBeforeUpdateHook)
|
||||
if err = o.doBeforeUpdateHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeUpdateHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeUpdateHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalHistoryBeforeUpdateHooks = []WithdrawalHistoryHook{}
|
||||
|
||||
AddWithdrawalHistoryHook(boil.AfterUpdateHook, withdrawalHistoryAfterUpdateHook)
|
||||
if err = o.doAfterUpdateHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterUpdateHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterUpdateHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalHistoryAfterUpdateHooks = []WithdrawalHistoryHook{}
|
||||
|
||||
AddWithdrawalHistoryHook(boil.BeforeDeleteHook, withdrawalHistoryBeforeDeleteHook)
|
||||
if err = o.doBeforeDeleteHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeDeleteHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeDeleteHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalHistoryBeforeDeleteHooks = []WithdrawalHistoryHook{}
|
||||
|
||||
AddWithdrawalHistoryHook(boil.AfterDeleteHook, withdrawalHistoryAfterDeleteHook)
|
||||
if err = o.doAfterDeleteHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterDeleteHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterDeleteHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalHistoryAfterDeleteHooks = []WithdrawalHistoryHook{}
|
||||
|
||||
AddWithdrawalHistoryHook(boil.BeforeUpsertHook, withdrawalHistoryBeforeUpsertHook)
|
||||
if err = o.doBeforeUpsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeUpsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeUpsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalHistoryBeforeUpsertHooks = []WithdrawalHistoryHook{}
|
||||
|
||||
AddWithdrawalHistoryHook(boil.AfterUpsertHook, withdrawalHistoryAfterUpsertHook)
|
||||
if err = o.doAfterUpsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterUpsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterUpsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalHistoryAfterUpsertHooks = []WithdrawalHistoryHook{}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesInsert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalHistories().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesInsertWhitelist(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Whitelist(withdrawalHistoryColumnsWithoutDefault...)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalHistories().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoryToManyWithdrawalCryptos(t *testing.T) {
|
||||
var err error
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var a WithdrawalHistory
|
||||
var b, c WithdrawalCrypto
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, &a, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, &b, withdrawalCryptoDBTypes, false, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &c, withdrawalCryptoDBTypes, false, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
b.WithdrawalHistoryID = a.ID
|
||||
c.WithdrawalHistoryID = a.ID
|
||||
|
||||
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = c.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
check, err := a.WithdrawalCryptos().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
bFound, cFound := false, false
|
||||
for _, v := range check {
|
||||
if v.WithdrawalHistoryID == b.WithdrawalHistoryID {
|
||||
bFound = true
|
||||
}
|
||||
if v.WithdrawalHistoryID == c.WithdrawalHistoryID {
|
||||
cFound = true
|
||||
}
|
||||
}
|
||||
|
||||
if !bFound {
|
||||
t.Error("expected to find b")
|
||||
}
|
||||
if !cFound {
|
||||
t.Error("expected to find c")
|
||||
}
|
||||
|
||||
slice := WithdrawalHistorySlice{&a}
|
||||
if err = a.L.LoadWithdrawalCryptos(ctx, tx, false, (*[]*WithdrawalHistory)(&slice), nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := len(a.R.WithdrawalCryptos); got != 2 {
|
||||
t.Error("number of eager loaded records wrong, got:", got)
|
||||
}
|
||||
|
||||
a.R.WithdrawalCryptos = nil
|
||||
if err = a.L.LoadWithdrawalCryptos(ctx, tx, true, &a, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := len(a.R.WithdrawalCryptos); got != 2 {
|
||||
t.Error("number of eager loaded records wrong, got:", got)
|
||||
}
|
||||
|
||||
if t.Failed() {
|
||||
t.Logf("%#v", check)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoryToManyWithdrawalFiats(t *testing.T) {
|
||||
var err error
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var a WithdrawalHistory
|
||||
var b, c WithdrawalFiat
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, &a, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, &b, withdrawalFiatDBTypes, false, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &c, withdrawalFiatDBTypes, false, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
b.WithdrawalHistoryID = a.ID
|
||||
c.WithdrawalHistoryID = a.ID
|
||||
|
||||
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = c.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
check, err := a.WithdrawalFiats().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
bFound, cFound := false, false
|
||||
for _, v := range check {
|
||||
if v.WithdrawalHistoryID == b.WithdrawalHistoryID {
|
||||
bFound = true
|
||||
}
|
||||
if v.WithdrawalHistoryID == c.WithdrawalHistoryID {
|
||||
cFound = true
|
||||
}
|
||||
}
|
||||
|
||||
if !bFound {
|
||||
t.Error("expected to find b")
|
||||
}
|
||||
if !cFound {
|
||||
t.Error("expected to find c")
|
||||
}
|
||||
|
||||
slice := WithdrawalHistorySlice{&a}
|
||||
if err = a.L.LoadWithdrawalFiats(ctx, tx, false, (*[]*WithdrawalHistory)(&slice), nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := len(a.R.WithdrawalFiats); got != 2 {
|
||||
t.Error("number of eager loaded records wrong, got:", got)
|
||||
}
|
||||
|
||||
a.R.WithdrawalFiats = nil
|
||||
if err = a.L.LoadWithdrawalFiats(ctx, tx, true, &a, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := len(a.R.WithdrawalFiats); got != 2 {
|
||||
t.Error("number of eager loaded records wrong, got:", got)
|
||||
}
|
||||
|
||||
if t.Failed() {
|
||||
t.Logf("%#v", check)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoryToManyAddOpWithdrawalCryptos(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var a WithdrawalHistory
|
||||
var b, c, d, e WithdrawalCrypto
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, &a, withdrawalHistoryDBTypes, false, strmangle.SetComplement(withdrawalHistoryPrimaryKeyColumns, withdrawalHistoryColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
foreigners := []*WithdrawalCrypto{&b, &c, &d, &e}
|
||||
for _, x := range foreigners {
|
||||
if err = randomize.Struct(seed, x, withdrawalCryptoDBTypes, false, strmangle.SetComplement(withdrawalCryptoPrimaryKeyColumns, withdrawalCryptoColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = c.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
foreignersSplitByInsertion := [][]*WithdrawalCrypto{
|
||||
{&b, &c},
|
||||
{&d, &e},
|
||||
}
|
||||
|
||||
for i, x := range foreignersSplitByInsertion {
|
||||
err = a.AddWithdrawalCryptos(ctx, tx, i != 0, x...)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
first := x[0]
|
||||
second := x[1]
|
||||
|
||||
if a.ID != first.WithdrawalHistoryID {
|
||||
t.Error("foreign key was wrong value", a.ID, first.WithdrawalHistoryID)
|
||||
}
|
||||
if a.ID != second.WithdrawalHistoryID {
|
||||
t.Error("foreign key was wrong value", a.ID, second.WithdrawalHistoryID)
|
||||
}
|
||||
|
||||
if first.R.WithdrawalHistory != &a {
|
||||
t.Error("relationship was not added properly to the foreign slice")
|
||||
}
|
||||
if second.R.WithdrawalHistory != &a {
|
||||
t.Error("relationship was not added properly to the foreign slice")
|
||||
}
|
||||
|
||||
if a.R.WithdrawalCryptos[i*2] != first {
|
||||
t.Error("relationship struct slice not set to correct value")
|
||||
}
|
||||
if a.R.WithdrawalCryptos[i*2+1] != second {
|
||||
t.Error("relationship struct slice not set to correct value")
|
||||
}
|
||||
|
||||
count, err := a.WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if want := int64((i + 1) * 2); count != want {
|
||||
t.Error("want", want, "got", count)
|
||||
}
|
||||
}
|
||||
}
|
||||
func testWithdrawalHistoryToManyAddOpWithdrawalFiats(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var a WithdrawalHistory
|
||||
var b, c, d, e WithdrawalFiat
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, &a, withdrawalHistoryDBTypes, false, strmangle.SetComplement(withdrawalHistoryPrimaryKeyColumns, withdrawalHistoryColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
foreigners := []*WithdrawalFiat{&b, &c, &d, &e}
|
||||
for _, x := range foreigners {
|
||||
if err = randomize.Struct(seed, x, withdrawalFiatDBTypes, false, strmangle.SetComplement(withdrawalFiatPrimaryKeyColumns, withdrawalFiatColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = c.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
foreignersSplitByInsertion := [][]*WithdrawalFiat{
|
||||
{&b, &c},
|
||||
{&d, &e},
|
||||
}
|
||||
|
||||
for i, x := range foreignersSplitByInsertion {
|
||||
err = a.AddWithdrawalFiats(ctx, tx, i != 0, x...)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
first := x[0]
|
||||
second := x[1]
|
||||
|
||||
if a.ID != first.WithdrawalHistoryID {
|
||||
t.Error("foreign key was wrong value", a.ID, first.WithdrawalHistoryID)
|
||||
}
|
||||
if a.ID != second.WithdrawalHistoryID {
|
||||
t.Error("foreign key was wrong value", a.ID, second.WithdrawalHistoryID)
|
||||
}
|
||||
|
||||
if first.R.WithdrawalHistory != &a {
|
||||
t.Error("relationship was not added properly to the foreign slice")
|
||||
}
|
||||
if second.R.WithdrawalHistory != &a {
|
||||
t.Error("relationship was not added properly to the foreign slice")
|
||||
}
|
||||
|
||||
if a.R.WithdrawalFiats[i*2] != first {
|
||||
t.Error("relationship struct slice not set to correct value")
|
||||
}
|
||||
if a.R.WithdrawalFiats[i*2+1] != second {
|
||||
t.Error("relationship struct slice not set to correct value")
|
||||
}
|
||||
|
||||
count, err := a.WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if want := int64((i + 1) * 2); count != want {
|
||||
t.Error("want", want, "got", count)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesReload(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = o.Reload(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesReloadAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := WithdrawalHistorySlice{o}
|
||||
|
||||
if err = slice.ReloadAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesSelect(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := WithdrawalHistories().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 1 {
|
||||
t.Error("want one record, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
withdrawalHistoryDBTypes = map[string]string{`ID`: `TEXT`, `Exchange`: `TEXT`, `ExchangeID`: `TEXT`, `Status`: `TEXT`, `Currency`: `TEXT`, `Amount`: `REAL`, `Description`: `TEXT`, `WithdrawType`: `INTEGER`, `CreatedAt`: `TIMESTAMP`, `UpdatedAt`: `TIMESTAMP`}
|
||||
_ = bytes.MinRead
|
||||
)
|
||||
|
||||
func testWithdrawalHistoriesUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if 0 == len(withdrawalHistoryPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with no primary key columns")
|
||||
}
|
||||
if len(withdrawalHistoryAllColumns) == len(withdrawalHistoryPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalHistories().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Update(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only affect one row but affected", rowsAff)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesSliceUpdateAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if len(withdrawalHistoryAllColumns) == len(withdrawalHistoryPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalHistories().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
// Remove Primary keys and unique columns from what we plan to update
|
||||
var fields []string
|
||||
if strmangle.StringSliceMatch(withdrawalHistoryAllColumns, withdrawalHistoryPrimaryKeyColumns) {
|
||||
fields = withdrawalHistoryAllColumns
|
||||
} else {
|
||||
fields = strmangle.SetComplement(
|
||||
withdrawalHistoryAllColumns,
|
||||
withdrawalHistoryPrimaryKeyColumns,
|
||||
)
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
typ := reflect.TypeOf(o).Elem()
|
||||
n := typ.NumField()
|
||||
|
||||
updateMap := M{}
|
||||
for _, col := range fields {
|
||||
for i := 0; i < n; i++ {
|
||||
f := typ.Field(i)
|
||||
if f.Tag.Get("boil") == col {
|
||||
updateMap[col] = value.Field(i).Interface()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
slice := WithdrawalHistorySlice{o}
|
||||
if rowsAff, err := slice.UpdateAll(ctx, tx, updateMap); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("wanted one record updated but got", rowsAff)
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package audit
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/database"
|
||||
@@ -71,7 +70,7 @@ func Event(id, msgtype, message string) {
|
||||
// GetEvent () returns list of order events matching query
|
||||
func GetEvent(startTime, endTime time.Time, order string, limit int) (interface{}, error) {
|
||||
if database.DB.SQL == nil {
|
||||
return nil, errors.New("database is nil")
|
||||
return nil, database.ErrDatabaseSupportDisabled
|
||||
}
|
||||
|
||||
query := qm.Where("created_at BETWEEN ? AND ?", startTime, endTime)
|
||||
|
||||
@@ -50,7 +50,6 @@ func TestScript(t *testing.T) {
|
||||
Driver: database.DBSQLite3,
|
||||
ConnectionDetails: drivers.ConnectionDetails{Database: "./testdb"},
|
||||
},
|
||||
|
||||
writeScript,
|
||||
testhelpers.CloseDatabase,
|
||||
nil,
|
||||
|
||||
389
database/repository/withdraw/withdraw.go
Normal file
389
database/repository/withdraw/withdraw.go
Normal file
@@ -0,0 +1,389 @@
|
||||
package withdraw
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/database"
|
||||
modelPSQL "github.com/thrasher-corp/gocryptotrader/database/models/postgres"
|
||||
modelSQLite "github.com/thrasher-corp/gocryptotrader/database/models/sqlite3"
|
||||
"github.com/thrasher-corp/gocryptotrader/database/repository"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/banking"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
"github.com/thrasher-corp/sqlboiler/boil"
|
||||
"github.com/thrasher-corp/sqlboiler/queries/qm"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNoResults = errors.New("no results found")
|
||||
)
|
||||
|
||||
// Event stores Withdrawal Response details in database
|
||||
func Event(res *withdraw.Response) {
|
||||
if database.DB.SQL == nil {
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = boil.SkipTimestamps(ctx)
|
||||
|
||||
tx, err := database.DB.SQL.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Event transaction being failed: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if repository.GetSQLDialect() == database.DBSQLite3 {
|
||||
err = addSQLiteEvent(ctx, tx, res)
|
||||
} else {
|
||||
err = addPSQLEvent(ctx, tx, res)
|
||||
}
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Event insert failed: %v", err)
|
||||
err = tx.Rollback()
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Event Transaction rollback failed: %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Event Transaction commit failed: %v", err)
|
||||
err = tx.Rollback()
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Event Transaction rollback failed: %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func addPSQLEvent(ctx context.Context, tx *sql.Tx, res *withdraw.Response) (err error) {
|
||||
var tempEvent = modelPSQL.WithdrawalHistory{
|
||||
Exchange: res.Exchange.Name,
|
||||
ExchangeID: res.Exchange.ID,
|
||||
Status: res.Exchange.Status,
|
||||
Currency: res.RequestDetails.Currency.String(),
|
||||
Amount: res.RequestDetails.Amount,
|
||||
WithdrawType: int(res.RequestDetails.Type),
|
||||
}
|
||||
|
||||
if res.RequestDetails.Description != "" {
|
||||
tempEvent.Description.SetValid(res.RequestDetails.Description)
|
||||
}
|
||||
|
||||
err = tempEvent.Insert(ctx, tx, boil.Infer())
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Event Insert failed: %v", err)
|
||||
err = tx.Rollback()
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Rollback failed: %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if res.RequestDetails.Type == withdraw.Fiat {
|
||||
fiatEvent := &modelPSQL.WithdrawalFiat{
|
||||
BankName: res.RequestDetails.Fiat.Bank.BankName,
|
||||
BankAddress: res.RequestDetails.Fiat.Bank.BankAddress,
|
||||
BankAccountName: res.RequestDetails.Fiat.Bank.AccountName,
|
||||
BankAccountNumber: res.RequestDetails.Fiat.Bank.AccountNumber,
|
||||
BSB: res.RequestDetails.Fiat.Bank.BSBNumber,
|
||||
SwiftCode: res.RequestDetails.Fiat.Bank.SWIFTCode,
|
||||
Iban: res.RequestDetails.Fiat.Bank.IBAN,
|
||||
}
|
||||
err = tempEvent.SetWithdrawalFiatWithdrawalFiats(ctx, tx, true, fiatEvent)
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Event Insert failed: %v", err)
|
||||
err = tx.Rollback()
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Rollback failed: %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if res.RequestDetails.Type == withdraw.Crypto {
|
||||
cryptoEvent := &modelPSQL.WithdrawalCrypto{
|
||||
Address: res.RequestDetails.Crypto.Address,
|
||||
Fee: res.RequestDetails.Crypto.FeeAmount,
|
||||
}
|
||||
if res.RequestDetails.Crypto.AddressTag != "" {
|
||||
cryptoEvent.AddressTag.SetValid(res.RequestDetails.Crypto.AddressTag)
|
||||
}
|
||||
err = tempEvent.AddWithdrawalCryptoWithdrawalCryptos(ctx, tx, true, cryptoEvent)
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Event Insert failed: %v", err)
|
||||
err = tx.Rollback()
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Rollback failed: %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
realID, _ := uuid.FromString(tempEvent.ID)
|
||||
res.ID = realID
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func addSQLiteEvent(ctx context.Context, tx *sql.Tx, res *withdraw.Response) (err error) {
|
||||
newUUID, errUUID := uuid.NewV4()
|
||||
if errUUID != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Failed to generate UUID: %v", errUUID)
|
||||
err = tx.Rollback()
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Rollback failed: %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
var tempEvent = modelSQLite.WithdrawalHistory{
|
||||
ID: newUUID.String(),
|
||||
Exchange: res.Exchange.Name,
|
||||
ExchangeID: res.Exchange.ID,
|
||||
Status: res.Exchange.Status,
|
||||
Currency: res.RequestDetails.Currency.String(),
|
||||
Amount: res.RequestDetails.Amount,
|
||||
WithdrawType: int64(res.RequestDetails.Type),
|
||||
}
|
||||
|
||||
if res.RequestDetails.Description != "" {
|
||||
tempEvent.Description.SetValid(res.RequestDetails.Description)
|
||||
}
|
||||
|
||||
err = tempEvent.Insert(ctx, tx, boil.Infer())
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Event Insert failed: %v", err)
|
||||
err = tx.Rollback()
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Rollback failed: %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if res.RequestDetails.Type == withdraw.Fiat {
|
||||
fiatEvent := &modelSQLite.WithdrawalFiat{
|
||||
BankName: res.RequestDetails.Fiat.Bank.BankName,
|
||||
BankAddress: res.RequestDetails.Fiat.Bank.BankAddress,
|
||||
BankAccountName: res.RequestDetails.Fiat.Bank.AccountName,
|
||||
BankAccountNumber: res.RequestDetails.Fiat.Bank.AccountNumber,
|
||||
BSB: res.RequestDetails.Fiat.Bank.BSBNumber,
|
||||
SwiftCode: res.RequestDetails.Fiat.Bank.SWIFTCode,
|
||||
Iban: res.RequestDetails.Fiat.Bank.IBAN,
|
||||
}
|
||||
|
||||
err = tempEvent.AddWithdrawalFiats(ctx, tx, true, fiatEvent)
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Event Insert failed: %v", err)
|
||||
err = tx.Rollback()
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Rollback failed: %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if res.RequestDetails.Type == withdraw.Crypto {
|
||||
cryptoEvent := &modelSQLite.WithdrawalCrypto{
|
||||
Address: res.RequestDetails.Crypto.Address,
|
||||
Fee: res.RequestDetails.Crypto.FeeAmount,
|
||||
}
|
||||
|
||||
if res.RequestDetails.Crypto.AddressTag != "" {
|
||||
cryptoEvent.AddressTag.SetValid(res.RequestDetails.Crypto.AddressTag)
|
||||
}
|
||||
|
||||
err = tempEvent.AddWithdrawalCryptos(ctx, tx, true, cryptoEvent)
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Event Insert failed: %v", err)
|
||||
err = tx.Rollback()
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Rollback failed: %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
res.ID = newUUID
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetEventByUUID return requested withdraw information by ID
|
||||
func GetEventByUUID(id string) (*withdraw.Response, error) {
|
||||
resp, err := getByColumns(generateWhereQuery([]string{"id"}, []string{id}, 1))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp[0], nil
|
||||
}
|
||||
|
||||
// GetEventsByExchange returns all withdrawal requests by exchange
|
||||
func GetEventsByExchange(exchange string, limit int) ([]*withdraw.Response, error) {
|
||||
return getByColumns(generateWhereQuery([]string{"exchange"}, []string{exchange}, limit))
|
||||
}
|
||||
|
||||
// GetEventByExchangeID return requested withdraw information by Exchange ID
|
||||
func GetEventByExchangeID(exchange, id string) (*withdraw.Response, error) {
|
||||
resp, err := getByColumns(generateWhereQuery([]string{"exchange", "exchange_id"}, []string{exchange, id}, 1))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp[0], err
|
||||
}
|
||||
|
||||
// GetEventsByDate returns requested withdraw information by date range
|
||||
func GetEventsByDate(exchange string, start, end time.Time, limit int) ([]*withdraw.Response, error) {
|
||||
betweenQuery := generateWhereBetweenQuery("created_at", start, end, limit)
|
||||
if exchange == "" {
|
||||
return getByColumns(betweenQuery)
|
||||
}
|
||||
return getByColumns(append(generateWhereQuery([]string{"exchange"}, []string{exchange}, 0), betweenQuery...))
|
||||
}
|
||||
|
||||
func generateWhereQuery(columns, id []string, limit int) []qm.QueryMod {
|
||||
var queries []qm.QueryMod
|
||||
if limit > 0 {
|
||||
queries = append(queries, qm.Limit(limit))
|
||||
}
|
||||
for x := range columns {
|
||||
queries = append(queries, qm.Where(columns[x]+"= ?", id[x]))
|
||||
}
|
||||
return queries
|
||||
}
|
||||
|
||||
func generateWhereBetweenQuery(column string, start, end interface{}, limit int) []qm.QueryMod {
|
||||
return []qm.QueryMod{
|
||||
qm.Limit(limit),
|
||||
qm.Where(column+" BETWEEN ? AND ?", start, end),
|
||||
}
|
||||
}
|
||||
|
||||
func getByColumns(q []qm.QueryMod) ([]*withdraw.Response, error) {
|
||||
if database.DB.SQL == nil {
|
||||
return nil, database.ErrDatabaseSupportDisabled
|
||||
}
|
||||
|
||||
var resp []*withdraw.Response
|
||||
var ctx = context.Background()
|
||||
if repository.GetSQLDialect() == database.DBSQLite3 {
|
||||
v, err := modelSQLite.WithdrawalHistories(q...).All(ctx, database.DB.SQL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for x := range v {
|
||||
var tempResp = &withdraw.Response{}
|
||||
newUUID, _ := uuid.FromString(v[x].ID)
|
||||
tempResp.ID = newUUID
|
||||
tempResp.Exchange = new(withdraw.ExchangeResponse)
|
||||
tempResp.Exchange.ID = v[x].ExchangeID
|
||||
tempResp.Exchange.Name = v[x].Exchange
|
||||
tempResp.Exchange.Status = v[x].Status
|
||||
tempResp.RequestDetails = new(withdraw.Request)
|
||||
tempResp.RequestDetails = &withdraw.Request{
|
||||
Currency: currency.NewCode(v[x].Currency),
|
||||
Description: v[x].Description.String,
|
||||
Amount: v[x].Amount,
|
||||
Type: withdraw.RequestType(v[x].WithdrawType),
|
||||
}
|
||||
|
||||
createdAtTime, err := time.Parse(time.RFC3339, v[x].CreatedAt)
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "record: %v has an incorrect time format ( %v ) - defaulting to empty time: %v", tempResp.ID, v[x].CreatedAt, err)
|
||||
tempResp.CreatedAt = time.Time{}
|
||||
} else {
|
||||
tempResp.CreatedAt = createdAtTime
|
||||
}
|
||||
|
||||
updatedAtTime, err := time.Parse(time.RFC3339, v[x].UpdatedAt)
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "record: %v has an incorrect time format ( %v ) - defaulting to empty time: %v", tempResp.ID, v[x].UpdatedAt, err)
|
||||
tempResp.UpdatedAt = time.Time{}
|
||||
} else {
|
||||
tempResp.UpdatedAt = updatedAtTime
|
||||
}
|
||||
|
||||
if withdraw.RequestType(v[x].WithdrawType) == withdraw.Crypto {
|
||||
x, err := v[x].WithdrawalCryptos().One(ctx, database.DB.SQL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tempResp.RequestDetails.Crypto = new(withdraw.CryptoRequest)
|
||||
tempResp.RequestDetails.Crypto.Address = x.Address
|
||||
tempResp.RequestDetails.Crypto.AddressTag = x.AddressTag.String
|
||||
tempResp.RequestDetails.Crypto.FeeAmount = x.Fee
|
||||
} else {
|
||||
x, err := v[x].WithdrawalFiats().One(ctx, database.DB.SQL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tempResp.RequestDetails.Fiat = new(withdraw.FiatRequest)
|
||||
tempResp.RequestDetails.Fiat.Bank = new(banking.Account)
|
||||
tempResp.RequestDetails.Fiat.Bank.AccountName = x.BankAccountName
|
||||
tempResp.RequestDetails.Fiat.Bank.AccountNumber = x.BankAccountNumber
|
||||
tempResp.RequestDetails.Fiat.Bank.IBAN = x.Iban
|
||||
tempResp.RequestDetails.Fiat.Bank.SWIFTCode = x.SwiftCode
|
||||
tempResp.RequestDetails.Fiat.Bank.BSBNumber = x.BSB
|
||||
}
|
||||
resp = append(resp, tempResp)
|
||||
}
|
||||
} else {
|
||||
v, err := modelPSQL.WithdrawalHistories(q...).All(ctx, database.DB.SQL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for x := range v {
|
||||
var tempResp = &withdraw.Response{}
|
||||
newUUID, _ := uuid.FromString(v[x].ID)
|
||||
tempResp.ID = newUUID
|
||||
tempResp.Exchange = new(withdraw.ExchangeResponse)
|
||||
tempResp.Exchange.ID = v[x].ExchangeID
|
||||
tempResp.Exchange.Name = v[x].Exchange
|
||||
tempResp.Exchange.Status = v[x].Status
|
||||
tempResp.RequestDetails = new(withdraw.Request)
|
||||
tempResp.RequestDetails = &withdraw.Request{
|
||||
Currency: currency.NewCode(v[x].Currency),
|
||||
Description: v[x].Description.String,
|
||||
Amount: v[x].Amount,
|
||||
Type: withdraw.RequestType(v[x].WithdrawType),
|
||||
}
|
||||
tempResp.CreatedAt = v[x].CreatedAt
|
||||
tempResp.UpdatedAt = v[x].UpdatedAt
|
||||
|
||||
if withdraw.RequestType(v[x].WithdrawType) == withdraw.Crypto {
|
||||
tempResp.RequestDetails.Crypto = new(withdraw.CryptoRequest)
|
||||
x, err := v[x].WithdrawalCryptoWithdrawalCryptos().One(ctx, database.DB.SQL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tempResp.RequestDetails.Crypto.Address = x.Address
|
||||
tempResp.RequestDetails.Crypto.AddressTag = x.AddressTag.String
|
||||
tempResp.RequestDetails.Crypto.FeeAmount = x.Fee
|
||||
} else if withdraw.RequestType(v[x].WithdrawType) == withdraw.Fiat {
|
||||
tempResp.RequestDetails.Fiat = new(withdraw.FiatRequest)
|
||||
x, err := v[x].WithdrawalFiatWithdrawalFiats().One(ctx, database.DB.SQL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tempResp.RequestDetails.Fiat.Bank = new(banking.Account)
|
||||
tempResp.RequestDetails.Fiat.Bank.AccountName = x.BankAccountName
|
||||
tempResp.RequestDetails.Fiat.Bank.AccountNumber = x.BankAccountNumber
|
||||
tempResp.RequestDetails.Fiat.Bank.IBAN = x.Iban
|
||||
tempResp.RequestDetails.Fiat.Bank.SWIFTCode = x.SwiftCode
|
||||
tempResp.RequestDetails.Fiat.Bank.BSBNumber = x.BSB
|
||||
}
|
||||
resp = append(resp, tempResp)
|
||||
}
|
||||
}
|
||||
if len(resp) == 0 {
|
||||
return nil, ErrNoResults
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
171
database/repository/withdraw/withdraw_test.go
Normal file
171
database/repository/withdraw/withdraw_test.go
Normal file
@@ -0,0 +1,171 @@
|
||||
package withdraw
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/database"
|
||||
"github.com/thrasher-corp/gocryptotrader/database/drivers"
|
||||
"github.com/thrasher-corp/gocryptotrader/database/repository"
|
||||
"github.com/thrasher-corp/gocryptotrader/database/testhelpers"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/banking"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
"github.com/thrasher-corp/goose"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
var err error
|
||||
testhelpers.PostgresTestDatabase = testhelpers.GetConnectionDetails()
|
||||
testhelpers.TempDir, err = ioutil.TempDir("", "gct-temp")
|
||||
if err != nil {
|
||||
fmt.Printf("failed to create temp file: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
t := m.Run()
|
||||
|
||||
err = os.RemoveAll(testhelpers.TempDir)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to remove temp db file: %v", err)
|
||||
}
|
||||
|
||||
os.Exit(t)
|
||||
}
|
||||
|
||||
func TestWithdraw(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
config *database.Config
|
||||
runner func(t *testing.T)
|
||||
closer func(dbConn *database.Db) error
|
||||
output interface{}
|
||||
}{
|
||||
{
|
||||
"SQLite-Write",
|
||||
&database.Config{
|
||||
Driver: database.DBSQLite3,
|
||||
ConnectionDetails: drivers.ConnectionDetails{Database: "./testdb"},
|
||||
},
|
||||
withdrawHelper,
|
||||
testhelpers.CloseDatabase,
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"Postgres-Write",
|
||||
testhelpers.PostgresTestDatabase,
|
||||
withdrawHelper,
|
||||
nil,
|
||||
nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tests := range testCases {
|
||||
test := tests
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
if !testhelpers.CheckValidConfig(&test.config.ConnectionDetails) {
|
||||
t.Skip("database not configured skipping test")
|
||||
}
|
||||
|
||||
dbConn, err := testhelpers.ConnectToDatabase(test.config)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
path := filepath.Join("..", "..", "migrations")
|
||||
err = goose.Run("up", dbConn.SQL, repository.GetSQLDialect(), path, "")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to run migrations %v", err)
|
||||
}
|
||||
|
||||
if test.runner != nil {
|
||||
test.runner(t)
|
||||
}
|
||||
|
||||
if test.closer != nil {
|
||||
err = test.closer(dbConn)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func withdrawHelper(t *testing.T) {
|
||||
t.Helper()
|
||||
var wg sync.WaitGroup
|
||||
for x := 0; x < 20; x++ {
|
||||
wg.Add(1)
|
||||
go func(x int) {
|
||||
defer wg.Done()
|
||||
test := fmt.Sprintf("test-%v", x)
|
||||
resp := &withdraw.Response{
|
||||
Exchange: &withdraw.ExchangeResponse{
|
||||
Name: test,
|
||||
ID: test,
|
||||
Status: test,
|
||||
},
|
||||
RequestDetails: &withdraw.Request{
|
||||
Exchange: test,
|
||||
Description: test,
|
||||
Amount: 1.0,
|
||||
},
|
||||
}
|
||||
rnd := rand.Intn(2)
|
||||
if rnd == 0 {
|
||||
resp.RequestDetails.Currency = currency.AUD
|
||||
resp.RequestDetails.Type = 1
|
||||
resp.RequestDetails.Fiat = new(withdraw.FiatRequest)
|
||||
resp.RequestDetails.Fiat.Bank = new(banking.Account)
|
||||
} else {
|
||||
resp.RequestDetails.Currency = currency.BTC
|
||||
resp.RequestDetails.Type = 0
|
||||
resp.RequestDetails.Crypto = new(withdraw.CryptoRequest)
|
||||
resp.RequestDetails.Crypto.Address = test
|
||||
resp.RequestDetails.Crypto.FeeAmount = 0
|
||||
resp.RequestDetails.Crypto.AddressTag = test
|
||||
}
|
||||
Event(resp)
|
||||
}(x)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
_, err := GetEventByUUID(withdraw.DryRunID.String())
|
||||
if err != nil {
|
||||
if !errors.Is(err, ErrNoResults) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
v, err := GetEventsByExchange("test-1", 10)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = GetEventByExchangeID("test-1", "test-1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if len(v) > 0 {
|
||||
_, err = GetEventByUUID(v[0].ID.String())
|
||||
if err != nil {
|
||||
if !errors.Is(err, ErrNoResults) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_, err = GetEventsByDate("test-1", time.Now().UTC().Add(-time.Minute), time.Now().UTC(), 5)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user