mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-18 15:10:03 +00:00
(Feature) OHLCV data storage and retrieval (#522)
* WIP * end of day WIP started migration of trade history * added kline support to hitbtc huobi lbank * added exchangehistory to all supported exchanges started work on coinbase 300 candles/request method * end of day WIP * removed unused ta and misc changes to flag ready for review * yobit cleanup * revert coinbase changES * general code clean up and added zb support * poloniex support added * renamed method to FormatExchangeKlineInterval other misc fixes * linter fixes * linter fixes * removed verbose * fixed poloniex test coverage * revert poloniex mock data * regenerated poloniex mock data * a very verbose clean up * binance mock clean up * removed unneeded t.Log() * setting verbose to true to debug CI issue * first pass changes addressed * common.ErrNotYetImplemented implemented :D * comments added * WIP-addressed exchange requests and reverted previous GetExchangeHistory changes * WIP-addressed exchange requests and reverted previous GetExchangeHistory changes * increased test coverage added kraken support * OKGroup support completed started work on address GetExchangeHistory feedback and migrating to own PR under https://github.com/xtda/gocryptotrader/tree/exchange_history * convert zb ratelimits * gofmt run on okcoin * increased delay on rate limit * gofmt package * fixed panic with coinbene and bithumb if conversion fails * very broken end of day WIP * added support for GetHistoricCandlesEx to coinbase and binance * gofmt package * coinbase, btcmarkets, zb ex wrapper function added * added all exchange support for ex regenerated mock data * update bithumb to return wrapper method * gofmt package * end of day started work on changes * models created for exchange/asset/currency/currencypair, new seed system created * reworked test coverage added okgroup support general fixes/change requests addressed * Added OneMonth * limit checks on supportedexchanges * reverted getexchangehistory * started work on currency seeding and insertion * reworked binance tesT * added workaround for kraken panic * :D extremely broken WIP * renamed command to extended removed interval check on non-implemented commands * added wrapperconfig back * increased test coverage for FormatExchangeKlineInterval * WIP * increased test coverage for FormatExchangeKlineInterval bitfinex/gateio/huobi * linter fixes * zb kraken lbank coinbene btcmarkets support added * removed verbose * OK group support for other asset types added * swapped margin to use spot endpoint * index support added test coverage added for asset types * added asset type to okcoin test * gofmt * add asset to extended method * removed verbose * Very broken WIP models need to be regenerated * add support for coinbene swap increase test coverage * removed verbose * small clean up of okgroup wrapper functions * verbose to troubleshoot CI issues * removed verbose * added error check reverted coinbasechanges * attempting to fix broken model generation * readme updated * :D i broke so much * model regeneration fixed & complete * candle model filled out * removed unused start/finish started work on decoupling api requests from kline package * restructured coinbene, bithumb methods, added bitstamp support * kraken time fix * BTCMarkets restructure * typo fix * removed test for futures due to contact changing * removed test for futures due to contact changing * added start/end date to extended method over range * WIP * added sync option to candles * converted to assettranslator * removed verbose * removed verbose * removed invalid char * reverted incorrectly removed return * added import * further template updates * macos hates my keyboard :D * misc canges * started work on creating kline from databases eed * x -> i * removed verbose * updated fixCasing to allocate var before checks * sqlite3 supported work started * removed time conversion * further work on tets * sort all outgoing kline candles * fixCasing fix * after/before checks added * added parallel to test * logic check on BTCmarkets * removed unused param, used correct iterator * converted HitBTC to use time.Time * test update * add iszero false check to candle times * Seed exchange & OHCLV data for test usage * updated resultlimit to 5000 * new line added * added comment to exported const * move date forward * use configured ratelimit * fixed pair for test * panic fixed WIP on fixCasing * fixCasing rework, started work on readme docs * enable rate limiter for wrapper issues tool * docs updated * removed unused vars from tests * removed err from return and formatted currency * updated Yobit supported status * Updated HitBTC to use onehour candles due to test exeuction times * added further details to gctcli output * added link to docs * added link to tempalte * disable FTX websocket in config_example * fix poloneix * regenerated poloniex mock data * removed recording flag * format on package * moved exchange var outside of method scope * reworked seeding into package * verbose output improved * removed verbose from candles * Added comments to exported functions * removed verbose output * Reworking of tests * end of day commit * added SQLite migration for asset, test updates for exchange, added support for withdrawal for new exchange_name_id relation * regenerated database models * WIP * test rework, sqlite migration updates for withdrawal * Reworked error returns to stop duplications, format all output to UTC, changed gctscript OHLCV output to be unix timestmap, started work on seeding tool * gofmt * dbseed command for seeding exchanges added, removed seed from dbmigrate, LoadCSV method added for exchange * go mod tidy * added import candle from csv command to dbseed * Removed reset & duplicate migrate command from helper, renamed struct to Item/Candle over Candle/Tick, added test coverage to dbseed, improved withdraw tests * remove broken tests due to ORM generation of Fk, removed go unneeded goroutine for inserting records * removed t.Cleanup usage because appveyor * added test coverage to StoreInDatabase() * removed unneeded data from config for test * added new line * Added down migration support to candle/asset removal, return original error and display rollback error * removed unneeded err assignment, break out of loop on error * add err check to method for test * first pass changes * WIP * Updated migrations for both sqlite3 & postgres to create exchanges if any withdrawal_history records are found, removed migrate command * removed argusage as usage information is provided by flags * added inserted records return count and test coverage * new line added * Database: comment config details out to disable local postgresl testing by default * added asset support * Database: added error return when no exchanges are found, title exchange name across queries * Fixed test data * Database: removed migration bool from ConnectToDatabase(), removed empty line, insert asset on test * Database: verbose linter :D * Database/OHLCV: removed go module from dbseed command and reverted back to main module, converted interval to int64 to match other parts of code base, provided migrations to update database, poloniex fix to skip first candle * dbseed: add completed message to output * Database: added migration to add asset to uniq index for candle table * Database: database -> exchange * Database: add asset to upsert conflict * Poloneix: fix for invalid interval * regenerated poloniex mock data * Database: added down migration for candle interval update * OHCLV/Database: WIP * OHLCV/Datastore: added new ValidateKline() method to check that asset, pair, interval are enabled/supported by exchange and updated tests * revert configtest changes * OHCLV/Kline: pointer assignment to ErrorKline & format pairs on check * goimports * migration updates * Database/Candle: updated tests * revert configtest changes * ZB: updaed defaults to use uppercase pairs * ZB: updaed defaults to use uppercase pairs * revert pair formatting * Switch over to .Cotains() method from pairManagement * Added comment & ftx back 😆 * OHLCV/Datastore: (Candles): added not null to asset, (WithdrawalHistory): added not null to exchange_name_id), reworked KlineError return * set verbose to false * updated btc markets test * Updated readme * removed ability to have blank exchange name as indexing requires it * remove old usedb and empty exchange check, return error on no data instead * Updated kline test to match date range * Renamed candles.exchange_id column to candles.xchange_name_id to match withdrawal table, return err on unwrap, zb fix revert * regenerated sqlite3 models * force UTC for sqlite.... because sqlite * OHLCV/Datastore: upper case pairs on insert for consistency, remove unneeded rollback call on commit failure as it has no effect, move rollback outside of insertsqlite/insertpsql methods * add error check for no candles * nil length/cap is 0 in golang :D * OHLCV/Datastore: updated wording on examples, removed duplicate testfile * OHLCV/Datastore: updated README with links to dbseed * dbtool -> dbseed
This commit is contained in:
@@ -13,6 +13,8 @@ import "testing"
|
||||
// Separating the tests thusly grants avoidance of Postgres deadlocks.
|
||||
func TestParent(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEvents)
|
||||
t.Run("Candles", testCandles)
|
||||
t.Run("Exchanges", testExchanges)
|
||||
t.Run("Scripts", testScripts)
|
||||
t.Run("ScriptExecutions", testScriptExecutions)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptos)
|
||||
@@ -22,6 +24,8 @@ func TestParent(t *testing.T) {
|
||||
|
||||
func TestDelete(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsDelete)
|
||||
t.Run("Candles", testCandlesDelete)
|
||||
t.Run("Exchanges", testExchangesDelete)
|
||||
t.Run("Scripts", testScriptsDelete)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsDelete)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosDelete)
|
||||
@@ -31,6 +35,8 @@ func TestDelete(t *testing.T) {
|
||||
|
||||
func TestQueryDeleteAll(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsQueryDeleteAll)
|
||||
t.Run("Candles", testCandlesQueryDeleteAll)
|
||||
t.Run("Exchanges", testExchangesQueryDeleteAll)
|
||||
t.Run("Scripts", testScriptsQueryDeleteAll)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsQueryDeleteAll)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosQueryDeleteAll)
|
||||
@@ -40,6 +46,8 @@ func TestQueryDeleteAll(t *testing.T) {
|
||||
|
||||
func TestSliceDeleteAll(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsSliceDeleteAll)
|
||||
t.Run("Candles", testCandlesSliceDeleteAll)
|
||||
t.Run("Exchanges", testExchangesSliceDeleteAll)
|
||||
t.Run("Scripts", testScriptsSliceDeleteAll)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsSliceDeleteAll)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosSliceDeleteAll)
|
||||
@@ -49,6 +57,8 @@ func TestSliceDeleteAll(t *testing.T) {
|
||||
|
||||
func TestExists(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsExists)
|
||||
t.Run("Candles", testCandlesExists)
|
||||
t.Run("Exchanges", testExchangesExists)
|
||||
t.Run("Scripts", testScriptsExists)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsExists)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosExists)
|
||||
@@ -58,6 +68,8 @@ func TestExists(t *testing.T) {
|
||||
|
||||
func TestFind(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsFind)
|
||||
t.Run("Candles", testCandlesFind)
|
||||
t.Run("Exchanges", testExchangesFind)
|
||||
t.Run("Scripts", testScriptsFind)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsFind)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosFind)
|
||||
@@ -67,6 +79,8 @@ func TestFind(t *testing.T) {
|
||||
|
||||
func TestBind(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsBind)
|
||||
t.Run("Candles", testCandlesBind)
|
||||
t.Run("Exchanges", testExchangesBind)
|
||||
t.Run("Scripts", testScriptsBind)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsBind)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosBind)
|
||||
@@ -76,6 +90,8 @@ func TestBind(t *testing.T) {
|
||||
|
||||
func TestOne(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsOne)
|
||||
t.Run("Candles", testCandlesOne)
|
||||
t.Run("Exchanges", testExchangesOne)
|
||||
t.Run("Scripts", testScriptsOne)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsOne)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosOne)
|
||||
@@ -85,6 +101,8 @@ func TestOne(t *testing.T) {
|
||||
|
||||
func TestAll(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsAll)
|
||||
t.Run("Candles", testCandlesAll)
|
||||
t.Run("Exchanges", testExchangesAll)
|
||||
t.Run("Scripts", testScriptsAll)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsAll)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosAll)
|
||||
@@ -94,6 +112,8 @@ func TestAll(t *testing.T) {
|
||||
|
||||
func TestCount(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsCount)
|
||||
t.Run("Candles", testCandlesCount)
|
||||
t.Run("Exchanges", testExchangesCount)
|
||||
t.Run("Scripts", testScriptsCount)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsCount)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosCount)
|
||||
@@ -103,6 +123,8 @@ func TestCount(t *testing.T) {
|
||||
|
||||
func TestHooks(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsHooks)
|
||||
t.Run("Candles", testCandlesHooks)
|
||||
t.Run("Exchanges", testExchangesHooks)
|
||||
t.Run("Scripts", testScriptsHooks)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsHooks)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosHooks)
|
||||
@@ -113,6 +135,10 @@ func TestHooks(t *testing.T) {
|
||||
func TestInsert(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsInsert)
|
||||
t.Run("AuditEvents", testAuditEventsInsertWhitelist)
|
||||
t.Run("Candles", testCandlesInsert)
|
||||
t.Run("Candles", testCandlesInsertWhitelist)
|
||||
t.Run("Exchanges", testExchangesInsert)
|
||||
t.Run("Exchanges", testExchangesInsertWhitelist)
|
||||
t.Run("Scripts", testScriptsInsert)
|
||||
t.Run("Scripts", testScriptsInsertWhitelist)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsInsert)
|
||||
@@ -128,18 +154,23 @@ func TestInsert(t *testing.T) {
|
||||
// TestToOne tests cannot be run in parallel
|
||||
// or deadlocks can occur.
|
||||
func TestToOne(t *testing.T) {
|
||||
t.Run("CandleToExchangeUsingExchangeName", testCandleToOneExchangeUsingExchangeName)
|
||||
t.Run("ScriptExecutionToScriptUsingScript", testScriptExecutionToOneScriptUsingScript)
|
||||
t.Run("WithdrawalCryptoToWithdrawalHistoryUsingWithdrawalHistory", testWithdrawalCryptoToOneWithdrawalHistoryUsingWithdrawalHistory)
|
||||
t.Run("WithdrawalFiatToWithdrawalHistoryUsingWithdrawalHistory", testWithdrawalFiatToOneWithdrawalHistoryUsingWithdrawalHistory)
|
||||
t.Run("WithdrawalHistoryToExchangeUsingExchangeName", testWithdrawalHistoryToOneExchangeUsingExchangeName)
|
||||
}
|
||||
|
||||
// TestOneToOne tests cannot be run in parallel
|
||||
// or deadlocks can occur.
|
||||
func TestOneToOne(t *testing.T) {}
|
||||
func TestOneToOne(t *testing.T) {
|
||||
t.Run("ExchangeToCandleUsingExchangeNameCandle", testExchangeOneToOneCandleUsingExchangeNameCandle)
|
||||
}
|
||||
|
||||
// TestToMany tests cannot be run in parallel
|
||||
// or deadlocks can occur.
|
||||
func TestToMany(t *testing.T) {
|
||||
t.Run("ExchangeToExchangeNameWithdrawalHistories", testExchangeToManyExchangeNameWithdrawalHistories)
|
||||
t.Run("ScriptToScriptExecutions", testScriptToManyScriptExecutions)
|
||||
t.Run("WithdrawalHistoryToWithdrawalCryptos", testWithdrawalHistoryToManyWithdrawalCryptos)
|
||||
t.Run("WithdrawalHistoryToWithdrawalFiats", testWithdrawalHistoryToManyWithdrawalFiats)
|
||||
@@ -148,9 +179,11 @@ func TestToMany(t *testing.T) {
|
||||
// TestToOneSet tests cannot be run in parallel
|
||||
// or deadlocks can occur.
|
||||
func TestToOneSet(t *testing.T) {
|
||||
t.Run("CandleToExchangeUsingExchangeNameCandle", testCandleToOneSetOpExchangeUsingExchangeName)
|
||||
t.Run("ScriptExecutionToScriptUsingScriptExecutions", testScriptExecutionToOneSetOpScriptUsingScript)
|
||||
t.Run("WithdrawalCryptoToWithdrawalHistoryUsingWithdrawalCryptos", testWithdrawalCryptoToOneSetOpWithdrawalHistoryUsingWithdrawalHistory)
|
||||
t.Run("WithdrawalFiatToWithdrawalHistoryUsingWithdrawalFiats", testWithdrawalFiatToOneSetOpWithdrawalHistoryUsingWithdrawalHistory)
|
||||
t.Run("WithdrawalHistoryToExchangeUsingExchangeNameWithdrawalHistories", testWithdrawalHistoryToOneSetOpExchangeUsingExchangeName)
|
||||
}
|
||||
|
||||
// TestToOneRemove tests cannot be run in parallel
|
||||
@@ -159,7 +192,9 @@ func TestToOneRemove(t *testing.T) {}
|
||||
|
||||
// TestOneToOneSet tests cannot be run in parallel
|
||||
// or deadlocks can occur.
|
||||
func TestOneToOneSet(t *testing.T) {}
|
||||
func TestOneToOneSet(t *testing.T) {
|
||||
t.Run("ExchangeToCandleUsingExchangeNameCandle", testExchangeOneToOneSetOpCandleUsingExchangeNameCandle)
|
||||
}
|
||||
|
||||
// TestOneToOneRemove tests cannot be run in parallel
|
||||
// or deadlocks can occur.
|
||||
@@ -168,6 +203,7 @@ func TestOneToOneRemove(t *testing.T) {}
|
||||
// TestToManyAdd tests cannot be run in parallel
|
||||
// or deadlocks can occur.
|
||||
func TestToManyAdd(t *testing.T) {
|
||||
t.Run("ExchangeToExchangeNameWithdrawalHistories", testExchangeToManyAddOpExchangeNameWithdrawalHistories)
|
||||
t.Run("ScriptToScriptExecutions", testScriptToManyAddOpScriptExecutions)
|
||||
t.Run("WithdrawalHistoryToWithdrawalCryptos", testWithdrawalHistoryToManyAddOpWithdrawalCryptos)
|
||||
t.Run("WithdrawalHistoryToWithdrawalFiats", testWithdrawalHistoryToManyAddOpWithdrawalFiats)
|
||||
@@ -183,6 +219,8 @@ func TestToManyRemove(t *testing.T) {}
|
||||
|
||||
func TestReload(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsReload)
|
||||
t.Run("Candles", testCandlesReload)
|
||||
t.Run("Exchanges", testExchangesReload)
|
||||
t.Run("Scripts", testScriptsReload)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsReload)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosReload)
|
||||
@@ -192,6 +230,8 @@ func TestReload(t *testing.T) {
|
||||
|
||||
func TestReloadAll(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsReloadAll)
|
||||
t.Run("Candles", testCandlesReloadAll)
|
||||
t.Run("Exchanges", testExchangesReloadAll)
|
||||
t.Run("Scripts", testScriptsReloadAll)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsReloadAll)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosReloadAll)
|
||||
@@ -201,6 +241,8 @@ func TestReloadAll(t *testing.T) {
|
||||
|
||||
func TestSelect(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsSelect)
|
||||
t.Run("Candles", testCandlesSelect)
|
||||
t.Run("Exchanges", testExchangesSelect)
|
||||
t.Run("Scripts", testScriptsSelect)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsSelect)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosSelect)
|
||||
@@ -210,6 +252,8 @@ func TestSelect(t *testing.T) {
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsUpdate)
|
||||
t.Run("Candles", testCandlesUpdate)
|
||||
t.Run("Exchanges", testExchangesUpdate)
|
||||
t.Run("Scripts", testScriptsUpdate)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsUpdate)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosUpdate)
|
||||
@@ -219,6 +263,8 @@ func TestUpdate(t *testing.T) {
|
||||
|
||||
func TestSliceUpdateAll(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsSliceUpdateAll)
|
||||
t.Run("Candles", testCandlesSliceUpdateAll)
|
||||
t.Run("Exchanges", testExchangesSliceUpdateAll)
|
||||
t.Run("Scripts", testScriptsSliceUpdateAll)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsSliceUpdateAll)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosSliceUpdateAll)
|
||||
|
||||
@@ -5,6 +5,8 @@ package sqlite3
|
||||
|
||||
var TableNames = struct {
|
||||
AuditEvent string
|
||||
Candle string
|
||||
Exchange string
|
||||
Script string
|
||||
ScriptExecution string
|
||||
WithdrawalCrypto string
|
||||
@@ -12,6 +14,8 @@ var TableNames = struct {
|
||||
WithdrawalHistory string
|
||||
}{
|
||||
AuditEvent: "audit_event",
|
||||
Candle: "candle",
|
||||
Exchange: "exchange",
|
||||
Script: "script",
|
||||
ScriptExecution: "script_execution",
|
||||
WithdrawalCrypto: "withdrawal_crypto",
|
||||
|
||||
996
database/models/sqlite3/candle.go
Normal file
996
database/models/sqlite3/candle.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"
|
||||
)
|
||||
|
||||
// Candle is an object representing the database table.
|
||||
type Candle struct {
|
||||
ID string `boil:"id" json:"id" toml:"id" yaml:"id"`
|
||||
ExchangeNameID string `boil:"exchange_name_id" json:"exchange_name_id" toml:"exchange_name_id" yaml:"exchange_name_id"`
|
||||
Base string `boil:"Base" json:"Base" toml:"Base" yaml:"Base"`
|
||||
Quote string `boil:"Quote" json:"Quote" toml:"Quote" yaml:"Quote"`
|
||||
Interval string `boil:"Interval" json:"Interval" toml:"Interval" yaml:"Interval"`
|
||||
Timestamp string `boil:"Timestamp" json:"Timestamp" toml:"Timestamp" yaml:"Timestamp"`
|
||||
Open float64 `boil:"Open" json:"Open" toml:"Open" yaml:"Open"`
|
||||
High float64 `boil:"High" json:"High" toml:"High" yaml:"High"`
|
||||
Low float64 `boil:"Low" json:"Low" toml:"Low" yaml:"Low"`
|
||||
Close float64 `boil:"Close" json:"Close" toml:"Close" yaml:"Close"`
|
||||
Volume float64 `boil:"Volume" json:"Volume" toml:"Volume" yaml:"Volume"`
|
||||
Asset string `boil:"Asset" json:"Asset" toml:"Asset" yaml:"Asset"`
|
||||
|
||||
R *candleR `boil:"-" json:"-" toml:"-" yaml:"-"`
|
||||
L candleL `boil:"-" json:"-" toml:"-" yaml:"-"`
|
||||
}
|
||||
|
||||
var CandleColumns = struct {
|
||||
ID string
|
||||
ExchangeNameID string
|
||||
Base string
|
||||
Quote string
|
||||
Interval string
|
||||
Timestamp string
|
||||
Open string
|
||||
High string
|
||||
Low string
|
||||
Close string
|
||||
Volume string
|
||||
Asset string
|
||||
}{
|
||||
ID: "id",
|
||||
ExchangeNameID: "exchange_name_id",
|
||||
Base: "Base",
|
||||
Quote: "Quote",
|
||||
Interval: "Interval",
|
||||
Timestamp: "Timestamp",
|
||||
Open: "Open",
|
||||
High: "High",
|
||||
Low: "Low",
|
||||
Close: "Close",
|
||||
Volume: "Volume",
|
||||
Asset: "Asset",
|
||||
}
|
||||
|
||||
// Generated where
|
||||
|
||||
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 CandleWhere = struct {
|
||||
ID whereHelperstring
|
||||
ExchangeNameID whereHelperstring
|
||||
Base whereHelperstring
|
||||
Quote whereHelperstring
|
||||
Interval whereHelperstring
|
||||
Timestamp whereHelperstring
|
||||
Open whereHelperfloat64
|
||||
High whereHelperfloat64
|
||||
Low whereHelperfloat64
|
||||
Close whereHelperfloat64
|
||||
Volume whereHelperfloat64
|
||||
Asset whereHelperstring
|
||||
}{
|
||||
ID: whereHelperstring{field: "\"candle\".\"id\""},
|
||||
ExchangeNameID: whereHelperstring{field: "\"candle\".\"exchange_name_id\""},
|
||||
Base: whereHelperstring{field: "\"candle\".\"Base\""},
|
||||
Quote: whereHelperstring{field: "\"candle\".\"Quote\""},
|
||||
Interval: whereHelperstring{field: "\"candle\".\"Interval\""},
|
||||
Timestamp: whereHelperstring{field: "\"candle\".\"Timestamp\""},
|
||||
Open: whereHelperfloat64{field: "\"candle\".\"Open\""},
|
||||
High: whereHelperfloat64{field: "\"candle\".\"High\""},
|
||||
Low: whereHelperfloat64{field: "\"candle\".\"Low\""},
|
||||
Close: whereHelperfloat64{field: "\"candle\".\"Close\""},
|
||||
Volume: whereHelperfloat64{field: "\"candle\".\"Volume\""},
|
||||
Asset: whereHelperstring{field: "\"candle\".\"Asset\""},
|
||||
}
|
||||
|
||||
// CandleRels is where relationship names are stored.
|
||||
var CandleRels = struct {
|
||||
ExchangeName string
|
||||
}{
|
||||
ExchangeName: "ExchangeName",
|
||||
}
|
||||
|
||||
// candleR is where relationships are stored.
|
||||
type candleR struct {
|
||||
ExchangeName *Exchange
|
||||
}
|
||||
|
||||
// NewStruct creates a new relationship struct
|
||||
func (*candleR) NewStruct() *candleR {
|
||||
return &candleR{}
|
||||
}
|
||||
|
||||
// candleL is where Load methods for each relationship are stored.
|
||||
type candleL struct{}
|
||||
|
||||
var (
|
||||
candleAllColumns = []string{"id", "exchange_name_id", "Base", "Quote", "Interval", "Timestamp", "Open", "High", "Low", "Close", "Volume", "Asset"}
|
||||
candleColumnsWithoutDefault = []string{"id", "exchange_name_id", "Base", "Quote", "Interval", "Timestamp", "Open", "High", "Low", "Close", "Volume", "Asset"}
|
||||
candleColumnsWithDefault = []string{}
|
||||
candlePrimaryKeyColumns = []string{"id"}
|
||||
)
|
||||
|
||||
type (
|
||||
// CandleSlice is an alias for a slice of pointers to Candle.
|
||||
// This should generally be used opposed to []Candle.
|
||||
CandleSlice []*Candle
|
||||
// CandleHook is the signature for custom Candle hook methods
|
||||
CandleHook func(context.Context, boil.ContextExecutor, *Candle) error
|
||||
|
||||
candleQuery struct {
|
||||
*queries.Query
|
||||
}
|
||||
)
|
||||
|
||||
// Cache for insert, update and upsert
|
||||
var (
|
||||
candleType = reflect.TypeOf(&Candle{})
|
||||
candleMapping = queries.MakeStructMapping(candleType)
|
||||
candlePrimaryKeyMapping, _ = queries.BindMapping(candleType, candleMapping, candlePrimaryKeyColumns)
|
||||
candleInsertCacheMut sync.RWMutex
|
||||
candleInsertCache = make(map[string]insertCache)
|
||||
candleUpdateCacheMut sync.RWMutex
|
||||
candleUpdateCache = make(map[string]updateCache)
|
||||
candleUpsertCacheMut sync.RWMutex
|
||||
candleUpsertCache = 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 candleBeforeInsertHooks []CandleHook
|
||||
var candleBeforeUpdateHooks []CandleHook
|
||||
var candleBeforeDeleteHooks []CandleHook
|
||||
var candleBeforeUpsertHooks []CandleHook
|
||||
|
||||
var candleAfterInsertHooks []CandleHook
|
||||
var candleAfterSelectHooks []CandleHook
|
||||
var candleAfterUpdateHooks []CandleHook
|
||||
var candleAfterDeleteHooks []CandleHook
|
||||
var candleAfterUpsertHooks []CandleHook
|
||||
|
||||
// doBeforeInsertHooks executes all "before insert" hooks.
|
||||
func (o *Candle) doBeforeInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range candleBeforeInsertHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doBeforeUpdateHooks executes all "before Update" hooks.
|
||||
func (o *Candle) doBeforeUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range candleBeforeUpdateHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doBeforeDeleteHooks executes all "before Delete" hooks.
|
||||
func (o *Candle) doBeforeDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range candleBeforeDeleteHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doBeforeUpsertHooks executes all "before Upsert" hooks.
|
||||
func (o *Candle) doBeforeUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range candleBeforeUpsertHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doAfterInsertHooks executes all "after Insert" hooks.
|
||||
func (o *Candle) doAfterInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range candleAfterInsertHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doAfterSelectHooks executes all "after Select" hooks.
|
||||
func (o *Candle) doAfterSelectHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range candleAfterSelectHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doAfterUpdateHooks executes all "after Update" hooks.
|
||||
func (o *Candle) doAfterUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range candleAfterUpdateHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doAfterDeleteHooks executes all "after Delete" hooks.
|
||||
func (o *Candle) doAfterDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range candleAfterDeleteHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doAfterUpsertHooks executes all "after Upsert" hooks.
|
||||
func (o *Candle) doAfterUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range candleAfterUpsertHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddCandleHook registers your hook function for all future operations.
|
||||
func AddCandleHook(hookPoint boil.HookPoint, candleHook CandleHook) {
|
||||
switch hookPoint {
|
||||
case boil.BeforeInsertHook:
|
||||
candleBeforeInsertHooks = append(candleBeforeInsertHooks, candleHook)
|
||||
case boil.BeforeUpdateHook:
|
||||
candleBeforeUpdateHooks = append(candleBeforeUpdateHooks, candleHook)
|
||||
case boil.BeforeDeleteHook:
|
||||
candleBeforeDeleteHooks = append(candleBeforeDeleteHooks, candleHook)
|
||||
case boil.BeforeUpsertHook:
|
||||
candleBeforeUpsertHooks = append(candleBeforeUpsertHooks, candleHook)
|
||||
case boil.AfterInsertHook:
|
||||
candleAfterInsertHooks = append(candleAfterInsertHooks, candleHook)
|
||||
case boil.AfterSelectHook:
|
||||
candleAfterSelectHooks = append(candleAfterSelectHooks, candleHook)
|
||||
case boil.AfterUpdateHook:
|
||||
candleAfterUpdateHooks = append(candleAfterUpdateHooks, candleHook)
|
||||
case boil.AfterDeleteHook:
|
||||
candleAfterDeleteHooks = append(candleAfterDeleteHooks, candleHook)
|
||||
case boil.AfterUpsertHook:
|
||||
candleAfterUpsertHooks = append(candleAfterUpsertHooks, candleHook)
|
||||
}
|
||||
}
|
||||
|
||||
// One returns a single candle record from the query.
|
||||
func (q candleQuery) One(ctx context.Context, exec boil.ContextExecutor) (*Candle, error) {
|
||||
o := &Candle{}
|
||||
|
||||
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 candle")
|
||||
}
|
||||
|
||||
if err := o.doAfterSelectHooks(ctx, exec); err != nil {
|
||||
return o, err
|
||||
}
|
||||
|
||||
return o, nil
|
||||
}
|
||||
|
||||
// All returns all Candle records from the query.
|
||||
func (q candleQuery) All(ctx context.Context, exec boil.ContextExecutor) (CandleSlice, error) {
|
||||
var o []*Candle
|
||||
|
||||
err := q.Bind(ctx, exec, &o)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "sqlite3: failed to assign all query results to Candle slice")
|
||||
}
|
||||
|
||||
if len(candleAfterSelectHooks) != 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 Candle records in the query.
|
||||
func (q candleQuery) 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 candle rows")
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// Exists checks if the row exists in the table.
|
||||
func (q candleQuery) 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 candle exists")
|
||||
}
|
||||
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
// ExchangeName pointed to by the foreign key.
|
||||
func (o *Candle) ExchangeName(mods ...qm.QueryMod) exchangeQuery {
|
||||
queryMods := []qm.QueryMod{
|
||||
qm.Where("\"id\" = ?", o.ExchangeNameID),
|
||||
}
|
||||
|
||||
queryMods = append(queryMods, mods...)
|
||||
|
||||
query := Exchanges(queryMods...)
|
||||
queries.SetFrom(query.Query, "\"exchange\"")
|
||||
|
||||
return query
|
||||
}
|
||||
|
||||
// LoadExchangeName allows an eager lookup of values, cached into the
|
||||
// loaded structs of the objects. This is for an N-1 relationship.
|
||||
func (candleL) LoadExchangeName(ctx context.Context, e boil.ContextExecutor, singular bool, maybeCandle interface{}, mods queries.Applicator) error {
|
||||
var slice []*Candle
|
||||
var object *Candle
|
||||
|
||||
if singular {
|
||||
object = maybeCandle.(*Candle)
|
||||
} else {
|
||||
slice = *maybeCandle.(*[]*Candle)
|
||||
}
|
||||
|
||||
args := make([]interface{}, 0, 1)
|
||||
if singular {
|
||||
if object.R == nil {
|
||||
object.R = &candleR{}
|
||||
}
|
||||
args = append(args, object.ExchangeNameID)
|
||||
|
||||
} else {
|
||||
Outer:
|
||||
for _, obj := range slice {
|
||||
if obj.R == nil {
|
||||
obj.R = &candleR{}
|
||||
}
|
||||
|
||||
for _, a := range args {
|
||||
if a == obj.ExchangeNameID {
|
||||
continue Outer
|
||||
}
|
||||
}
|
||||
|
||||
args = append(args, obj.ExchangeNameID)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if len(args) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
query := NewQuery(qm.From(`exchange`), qm.WhereIn(`exchange.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 Exchange")
|
||||
}
|
||||
|
||||
var resultSlice []*Exchange
|
||||
if err = queries.Bind(results, &resultSlice); err != nil {
|
||||
return errors.Wrap(err, "failed to bind eager loaded slice Exchange")
|
||||
}
|
||||
|
||||
if err = results.Close(); err != nil {
|
||||
return errors.Wrap(err, "failed to close results of eager load for exchange")
|
||||
}
|
||||
if err = results.Err(); err != nil {
|
||||
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for exchange")
|
||||
}
|
||||
|
||||
if len(candleAfterSelectHooks) != 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.ExchangeName = foreign
|
||||
if foreign.R == nil {
|
||||
foreign.R = &exchangeR{}
|
||||
}
|
||||
foreign.R.ExchangeNameCandle = object
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, local := range slice {
|
||||
for _, foreign := range resultSlice {
|
||||
if local.ExchangeNameID == foreign.ID {
|
||||
local.R.ExchangeName = foreign
|
||||
if foreign.R == nil {
|
||||
foreign.R = &exchangeR{}
|
||||
}
|
||||
foreign.R.ExchangeNameCandle = local
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetExchangeName of the candle to the related item.
|
||||
// Sets o.R.ExchangeName to related.
|
||||
// Adds o to related.R.ExchangeNameCandle.
|
||||
func (o *Candle) SetExchangeName(ctx context.Context, exec boil.ContextExecutor, insert bool, related *Exchange) 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 \"candle\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 0, []string{"exchange_name_id"}),
|
||||
strmangle.WhereClause("\"", "\"", 0, candlePrimaryKeyColumns),
|
||||
)
|
||||
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.ExchangeNameID = related.ID
|
||||
if o.R == nil {
|
||||
o.R = &candleR{
|
||||
ExchangeName: related,
|
||||
}
|
||||
} else {
|
||||
o.R.ExchangeName = related
|
||||
}
|
||||
|
||||
if related.R == nil {
|
||||
related.R = &exchangeR{
|
||||
ExchangeNameCandle: o,
|
||||
}
|
||||
} else {
|
||||
related.R.ExchangeNameCandle = o
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Candles retrieves all the records using an executor.
|
||||
func Candles(mods ...qm.QueryMod) candleQuery {
|
||||
mods = append(mods, qm.From("\"candle\""))
|
||||
return candleQuery{NewQuery(mods...)}
|
||||
}
|
||||
|
||||
// FindCandle retrieves a single record by ID with an executor.
|
||||
// If selectCols is empty Find will return all columns.
|
||||
func FindCandle(ctx context.Context, exec boil.ContextExecutor, iD string, selectCols ...string) (*Candle, error) {
|
||||
candleObj := &Candle{}
|
||||
|
||||
sel := "*"
|
||||
if len(selectCols) > 0 {
|
||||
sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
|
||||
}
|
||||
query := fmt.Sprintf(
|
||||
"select %s from \"candle\" where \"id\"=?", sel,
|
||||
)
|
||||
|
||||
q := queries.Raw(query, iD)
|
||||
|
||||
err := q.Bind(ctx, exec, candleObj)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == sql.ErrNoRows {
|
||||
return nil, sql.ErrNoRows
|
||||
}
|
||||
return nil, errors.Wrap(err, "sqlite3: unable to select from candle")
|
||||
}
|
||||
|
||||
return candleObj, nil
|
||||
}
|
||||
|
||||
// Insert a single record using an executor.
|
||||
// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.
|
||||
func (o *Candle) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
|
||||
if o == nil {
|
||||
return errors.New("sqlite3: no candle provided for insertion")
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
if err := o.doBeforeInsertHooks(ctx, exec); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
nzDefaults := queries.NonZeroDefaultSet(candleColumnsWithDefault, o)
|
||||
|
||||
key := makeCacheKey(columns, nzDefaults)
|
||||
candleInsertCacheMut.RLock()
|
||||
cache, cached := candleInsertCache[key]
|
||||
candleInsertCacheMut.RUnlock()
|
||||
|
||||
if !cached {
|
||||
wl, returnColumns := columns.InsertColumnSet(
|
||||
candleAllColumns,
|
||||
candleColumnsWithDefault,
|
||||
candleColumnsWithoutDefault,
|
||||
nzDefaults,
|
||||
)
|
||||
|
||||
cache.valueMapping, err = queries.BindMapping(candleType, candleMapping, wl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cache.retMapping, err = queries.BindMapping(candleType, candleMapping, returnColumns)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(wl) != 0 {
|
||||
cache.query = fmt.Sprintf("INSERT INTO \"candle\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
|
||||
} else {
|
||||
cache.query = "INSERT INTO \"candle\" () VALUES ()%s%s"
|
||||
}
|
||||
|
||||
var queryOutput, queryReturning string
|
||||
|
||||
if len(cache.retMapping) != 0 {
|
||||
cache.retQuery = fmt.Sprintf("SELECT \"%s\" FROM \"candle\" WHERE %s", strings.Join(returnColumns, "\",\""), strmangle.WhereClause("\"", "\"", 0, candlePrimaryKeyColumns))
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
_, err = exec.ExecContext(ctx, cache.query, vals...)
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "sqlite3: unable to insert into candle")
|
||||
}
|
||||
|
||||
var identifierCols []interface{}
|
||||
|
||||
if len(cache.retMapping) == 0 {
|
||||
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 candle")
|
||||
}
|
||||
|
||||
CacheNoHooks:
|
||||
if !cached {
|
||||
candleInsertCacheMut.Lock()
|
||||
candleInsertCache[key] = cache
|
||||
candleInsertCacheMut.Unlock()
|
||||
}
|
||||
|
||||
return o.doAfterInsertHooks(ctx, exec)
|
||||
}
|
||||
|
||||
// Update uses an executor to update the Candle.
|
||||
// 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 *Candle) 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)
|
||||
candleUpdateCacheMut.RLock()
|
||||
cache, cached := candleUpdateCache[key]
|
||||
candleUpdateCacheMut.RUnlock()
|
||||
|
||||
if !cached {
|
||||
wl := columns.UpdateColumnSet(
|
||||
candleAllColumns,
|
||||
candlePrimaryKeyColumns,
|
||||
)
|
||||
|
||||
if len(wl) == 0 {
|
||||
return 0, errors.New("sqlite3: unable to update candle, could not build whitelist")
|
||||
}
|
||||
|
||||
cache.query = fmt.Sprintf("UPDATE \"candle\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 0, wl),
|
||||
strmangle.WhereClause("\"", "\"", 0, candlePrimaryKeyColumns),
|
||||
)
|
||||
cache.valueMapping, err = queries.BindMapping(candleType, candleMapping, append(wl, candlePrimaryKeyColumns...))
|
||||
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 candle row")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: failed to get rows affected by update for candle")
|
||||
}
|
||||
|
||||
if !cached {
|
||||
candleUpdateCacheMut.Lock()
|
||||
candleUpdateCache[key] = cache
|
||||
candleUpdateCacheMut.Unlock()
|
||||
}
|
||||
|
||||
return rowsAff, o.doAfterUpdateHooks(ctx, exec)
|
||||
}
|
||||
|
||||
// UpdateAll updates all rows with the specified column values.
|
||||
func (q candleQuery) 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 candle")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to retrieve rows affected for candle")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// UpdateAll updates all rows with the specified column values, using an executor.
|
||||
func (o CandleSlice) 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)), candlePrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := fmt.Sprintf("UPDATE \"candle\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 0, colNames),
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, candlePrimaryKeyColumns, 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 candle slice")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to retrieve rows affected all in update all candle")
|
||||
}
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// Delete deletes a single Candle record with an executor.
|
||||
// Delete will match against the primary key column to find the record to delete.
|
||||
func (o *Candle) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if o == nil {
|
||||
return 0, errors.New("sqlite3: no Candle provided for delete")
|
||||
}
|
||||
|
||||
if err := o.doBeforeDeleteHooks(ctx, exec); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), candlePrimaryKeyMapping)
|
||||
sql := "DELETE FROM \"candle\" 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 candle")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: failed to get rows affected by delete for candle")
|
||||
}
|
||||
|
||||
if err := o.doAfterDeleteHooks(ctx, exec); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// DeleteAll deletes all matching rows.
|
||||
func (q candleQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if q.Query == nil {
|
||||
return 0, errors.New("sqlite3: no candleQuery 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 candle")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: failed to get rows affected by deleteall for candle")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// DeleteAll deletes all rows in the slice, using an executor.
|
||||
func (o CandleSlice) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if len(o) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
if len(candleBeforeDeleteHooks) != 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)), candlePrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := "DELETE FROM \"candle\" WHERE " +
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, candlePrimaryKeyColumns, 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 candle slice")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: failed to get rows affected by deleteall for candle")
|
||||
}
|
||||
|
||||
if len(candleAfterDeleteHooks) != 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 *Candle) Reload(ctx context.Context, exec boil.ContextExecutor) error {
|
||||
ret, err := FindCandle(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 *CandleSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error {
|
||||
if o == nil || len(*o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
slice := CandleSlice{}
|
||||
var args []interface{}
|
||||
for _, obj := range *o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), candlePrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := "SELECT \"candle\".* FROM \"candle\" WHERE " +
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, candlePrimaryKeyColumns, 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 CandleSlice")
|
||||
}
|
||||
|
||||
*o = slice
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CandleExists checks if the Candle row exists.
|
||||
func CandleExists(ctx context.Context, exec boil.ContextExecutor, iD string) (bool, error) {
|
||||
var exists bool
|
||||
sql := "select exists(select 1 from \"candle\" 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 candle exists")
|
||||
}
|
||||
|
||||
return exists, nil
|
||||
}
|
||||
793
database/models/sqlite3/candle_test.go
Normal file
793
database/models/sqlite3/candle_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 testCandles(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
query := Candles()
|
||||
|
||||
if query.Query == nil {
|
||||
t.Error("expected a query, got nothing")
|
||||
}
|
||||
}
|
||||
|
||||
func testCandlesDelete(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &Candle{}
|
||||
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Candle 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 := Candles().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testCandlesQueryDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &Candle{}
|
||||
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Candle 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 := Candles().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 := Candles().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testCandlesSliceDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &Candle{}
|
||||
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Candle 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 := CandleSlice{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 := Candles().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testCandlesExists(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &Candle{}
|
||||
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Candle 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 := CandleExists(ctx, tx, o.ID)
|
||||
if err != nil {
|
||||
t.Errorf("Unable to check if Candle exists: %s", err)
|
||||
}
|
||||
if !e {
|
||||
t.Errorf("Expected CandleExists to return true, but got false.")
|
||||
}
|
||||
}
|
||||
|
||||
func testCandlesFind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &Candle{}
|
||||
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Candle 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)
|
||||
}
|
||||
|
||||
candleFound, err := FindCandle(ctx, tx, o.ID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if candleFound == nil {
|
||||
t.Error("want a record, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func testCandlesBind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &Candle{}
|
||||
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Candle 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 = Candles().Bind(ctx, tx, o); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testCandlesOne(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &Candle{}
|
||||
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Candle 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 := Candles().One(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if x == nil {
|
||||
t.Error("expected to get a non nil record")
|
||||
}
|
||||
}
|
||||
|
||||
func testCandlesAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
candleOne := &Candle{}
|
||||
candleTwo := &Candle{}
|
||||
if err = randomize.Struct(seed, candleOne, candleDBTypes, false, candleColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Candle struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, candleTwo, candleDBTypes, false, candleColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Candle struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = candleOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = candleTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := Candles().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 2 {
|
||||
t.Error("want 2 records, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
func testCandlesCount(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
seed := randomize.NewSeed()
|
||||
candleOne := &Candle{}
|
||||
candleTwo := &Candle{}
|
||||
if err = randomize.Struct(seed, candleOne, candleDBTypes, false, candleColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Candle struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, candleTwo, candleDBTypes, false, candleColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Candle struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = candleOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = candleTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := Candles().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 2 {
|
||||
t.Error("want 2 records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func candleBeforeInsertHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
|
||||
*o = Candle{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func candleAfterInsertHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
|
||||
*o = Candle{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func candleAfterSelectHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
|
||||
*o = Candle{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func candleBeforeUpdateHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
|
||||
*o = Candle{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func candleAfterUpdateHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
|
||||
*o = Candle{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func candleBeforeDeleteHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
|
||||
*o = Candle{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func candleAfterDeleteHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
|
||||
*o = Candle{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func candleBeforeUpsertHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
|
||||
*o = Candle{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func candleAfterUpsertHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
|
||||
*o = Candle{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func testCandlesHooks(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
empty := &Candle{}
|
||||
o := &Candle{}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, o, candleDBTypes, false); err != nil {
|
||||
t.Errorf("Unable to randomize Candle object: %s", err)
|
||||
}
|
||||
|
||||
AddCandleHook(boil.BeforeInsertHook, candleBeforeInsertHook)
|
||||
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)
|
||||
}
|
||||
candleBeforeInsertHooks = []CandleHook{}
|
||||
|
||||
AddCandleHook(boil.AfterInsertHook, candleAfterInsertHook)
|
||||
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)
|
||||
}
|
||||
candleAfterInsertHooks = []CandleHook{}
|
||||
|
||||
AddCandleHook(boil.AfterSelectHook, candleAfterSelectHook)
|
||||
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)
|
||||
}
|
||||
candleAfterSelectHooks = []CandleHook{}
|
||||
|
||||
AddCandleHook(boil.BeforeUpdateHook, candleBeforeUpdateHook)
|
||||
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)
|
||||
}
|
||||
candleBeforeUpdateHooks = []CandleHook{}
|
||||
|
||||
AddCandleHook(boil.AfterUpdateHook, candleAfterUpdateHook)
|
||||
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)
|
||||
}
|
||||
candleAfterUpdateHooks = []CandleHook{}
|
||||
|
||||
AddCandleHook(boil.BeforeDeleteHook, candleBeforeDeleteHook)
|
||||
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)
|
||||
}
|
||||
candleBeforeDeleteHooks = []CandleHook{}
|
||||
|
||||
AddCandleHook(boil.AfterDeleteHook, candleAfterDeleteHook)
|
||||
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)
|
||||
}
|
||||
candleAfterDeleteHooks = []CandleHook{}
|
||||
|
||||
AddCandleHook(boil.BeforeUpsertHook, candleBeforeUpsertHook)
|
||||
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)
|
||||
}
|
||||
candleBeforeUpsertHooks = []CandleHook{}
|
||||
|
||||
AddCandleHook(boil.AfterUpsertHook, candleAfterUpsertHook)
|
||||
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)
|
||||
}
|
||||
candleAfterUpsertHooks = []CandleHook{}
|
||||
}
|
||||
|
||||
func testCandlesInsert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &Candle{}
|
||||
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Candle 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 := Candles().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testCandlesInsertWhitelist(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &Candle{}
|
||||
if err = randomize.Struct(seed, o, candleDBTypes, true); err != nil {
|
||||
t.Errorf("Unable to randomize Candle struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Whitelist(candleColumnsWithoutDefault...)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := Candles().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testCandleToOneExchangeUsingExchangeName(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var local Candle
|
||||
var foreign Exchange
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err := randomize.Struct(seed, &local, candleDBTypes, false, candleColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Candle struct: %s", err)
|
||||
}
|
||||
if err := randomize.Struct(seed, &foreign, exchangeDBTypes, false, exchangeColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Exchange struct: %s", err)
|
||||
}
|
||||
|
||||
if err := foreign.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
local.ExchangeNameID = foreign.ID
|
||||
if err := local.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
check, err := local.ExchangeName().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 := CandleSlice{&local}
|
||||
if err = local.L.LoadExchangeName(ctx, tx, false, (*[]*Candle)(&slice), nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.ExchangeName == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
|
||||
local.R.ExchangeName = nil
|
||||
if err = local.L.LoadExchangeName(ctx, tx, true, &local, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.ExchangeName == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
}
|
||||
|
||||
func testCandleToOneSetOpExchangeUsingExchangeName(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var a Candle
|
||||
var b, c Exchange
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, &a, candleDBTypes, false, strmangle.SetComplement(candlePrimaryKeyColumns, candleColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &b, exchangeDBTypes, false, strmangle.SetComplement(exchangePrimaryKeyColumns, exchangeColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &c, exchangeDBTypes, false, strmangle.SetComplement(exchangePrimaryKeyColumns, exchangeColumnsWithoutDefault)...); 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 []*Exchange{&b, &c} {
|
||||
err = a.SetExchangeName(ctx, tx, i != 0, x)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if a.R.ExchangeName != x {
|
||||
t.Error("relationship struct not set to correct value")
|
||||
}
|
||||
|
||||
if x.R.ExchangeNameCandle != &a {
|
||||
t.Error("failed to append to foreign relationship struct")
|
||||
}
|
||||
if a.ExchangeNameID != x.ID {
|
||||
t.Error("foreign key was wrong value", a.ExchangeNameID)
|
||||
}
|
||||
|
||||
zero := reflect.Zero(reflect.TypeOf(a.ExchangeNameID))
|
||||
reflect.Indirect(reflect.ValueOf(&a.ExchangeNameID)).Set(zero)
|
||||
|
||||
if err = a.Reload(ctx, tx); err != nil {
|
||||
t.Fatal("failed to reload", err)
|
||||
}
|
||||
|
||||
if a.ExchangeNameID != x.ID {
|
||||
t.Error("foreign key was wrong value", a.ExchangeNameID, x.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testCandlesReload(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &Candle{}
|
||||
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Candle 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 testCandlesReloadAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &Candle{}
|
||||
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Candle 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 := CandleSlice{o}
|
||||
|
||||
if err = slice.ReloadAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testCandlesSelect(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &Candle{}
|
||||
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Candle 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 := Candles().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 1 {
|
||||
t.Error("want one record, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
candleDBTypes = map[string]string{`ID`: `TEXT`, `ExchangeNameID`: `UUID`, `Base`: `TEXT`, `Quote`: `TEXT`, `Interval`: `TEXT`, `Timestamp`: `TIMESTAMP`, `Open`: `REAL`, `High`: `REAL`, `Low`: `REAL`, `Close`: `REAL`, `Volume`: `REAL`, `Asset`: `TEXT`}
|
||||
_ = bytes.MinRead
|
||||
)
|
||||
|
||||
func testCandlesUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if 0 == len(candlePrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with no primary key columns")
|
||||
}
|
||||
if len(candleAllColumns) == len(candlePrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &Candle{}
|
||||
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Candle 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 := Candles().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, candleDBTypes, true, candlePrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize Candle 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 testCandlesSliceUpdateAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if len(candleAllColumns) == len(candlePrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &Candle{}
|
||||
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Candle 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 := Candles().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, candleDBTypes, true, candlePrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize Candle struct: %s", err)
|
||||
}
|
||||
|
||||
// Remove Primary keys and unique columns from what we plan to update
|
||||
var fields []string
|
||||
if strmangle.StringSliceMatch(candleAllColumns, candlePrimaryKeyColumns) {
|
||||
fields = candleAllColumns
|
||||
} else {
|
||||
fields = strmangle.SetComplement(
|
||||
candleAllColumns,
|
||||
candlePrimaryKeyColumns,
|
||||
)
|
||||
}
|
||||
|
||||
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 := CandleSlice{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)
|
||||
}
|
||||
}
|
||||
1104
database/models/sqlite3/exchange.go
Normal file
1104
database/models/sqlite3/exchange.go
Normal file
File diff suppressed because it is too large
Load Diff
951
database/models/sqlite3/exchange_test.go
Normal file
951
database/models/sqlite3/exchange_test.go
Normal file
@@ -0,0 +1,951 @@
|
||||
// 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 testExchanges(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
query := Exchanges()
|
||||
|
||||
if query.Query == nil {
|
||||
t.Error("expected a query, got nothing")
|
||||
}
|
||||
}
|
||||
|
||||
func testExchangesDelete(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &Exchange{}
|
||||
if err = randomize.Struct(seed, o, exchangeDBTypes, true, exchangeColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Exchange 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 := Exchanges().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testExchangesQueryDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &Exchange{}
|
||||
if err = randomize.Struct(seed, o, exchangeDBTypes, true, exchangeColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Exchange 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 := Exchanges().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 := Exchanges().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testExchangesSliceDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &Exchange{}
|
||||
if err = randomize.Struct(seed, o, exchangeDBTypes, true, exchangeColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Exchange 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 := ExchangeSlice{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 := Exchanges().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testExchangesExists(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &Exchange{}
|
||||
if err = randomize.Struct(seed, o, exchangeDBTypes, true, exchangeColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Exchange 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 := ExchangeExists(ctx, tx, o.ID)
|
||||
if err != nil {
|
||||
t.Errorf("Unable to check if Exchange exists: %s", err)
|
||||
}
|
||||
if !e {
|
||||
t.Errorf("Expected ExchangeExists to return true, but got false.")
|
||||
}
|
||||
}
|
||||
|
||||
func testExchangesFind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &Exchange{}
|
||||
if err = randomize.Struct(seed, o, exchangeDBTypes, true, exchangeColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Exchange 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)
|
||||
}
|
||||
|
||||
exchangeFound, err := FindExchange(ctx, tx, o.ID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if exchangeFound == nil {
|
||||
t.Error("want a record, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func testExchangesBind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &Exchange{}
|
||||
if err = randomize.Struct(seed, o, exchangeDBTypes, true, exchangeColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Exchange 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 = Exchanges().Bind(ctx, tx, o); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testExchangesOne(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &Exchange{}
|
||||
if err = randomize.Struct(seed, o, exchangeDBTypes, true, exchangeColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Exchange 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 := Exchanges().One(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if x == nil {
|
||||
t.Error("expected to get a non nil record")
|
||||
}
|
||||
}
|
||||
|
||||
func testExchangesAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
exchangeOne := &Exchange{}
|
||||
exchangeTwo := &Exchange{}
|
||||
if err = randomize.Struct(seed, exchangeOne, exchangeDBTypes, false, exchangeColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Exchange struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, exchangeTwo, exchangeDBTypes, false, exchangeColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Exchange struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = exchangeOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = exchangeTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := Exchanges().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 2 {
|
||||
t.Error("want 2 records, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
func testExchangesCount(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
seed := randomize.NewSeed()
|
||||
exchangeOne := &Exchange{}
|
||||
exchangeTwo := &Exchange{}
|
||||
if err = randomize.Struct(seed, exchangeOne, exchangeDBTypes, false, exchangeColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Exchange struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, exchangeTwo, exchangeDBTypes, false, exchangeColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Exchange struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = exchangeOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = exchangeTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := Exchanges().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 2 {
|
||||
t.Error("want 2 records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func exchangeBeforeInsertHook(ctx context.Context, e boil.ContextExecutor, o *Exchange) error {
|
||||
*o = Exchange{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func exchangeAfterInsertHook(ctx context.Context, e boil.ContextExecutor, o *Exchange) error {
|
||||
*o = Exchange{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func exchangeAfterSelectHook(ctx context.Context, e boil.ContextExecutor, o *Exchange) error {
|
||||
*o = Exchange{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func exchangeBeforeUpdateHook(ctx context.Context, e boil.ContextExecutor, o *Exchange) error {
|
||||
*o = Exchange{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func exchangeAfterUpdateHook(ctx context.Context, e boil.ContextExecutor, o *Exchange) error {
|
||||
*o = Exchange{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func exchangeBeforeDeleteHook(ctx context.Context, e boil.ContextExecutor, o *Exchange) error {
|
||||
*o = Exchange{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func exchangeAfterDeleteHook(ctx context.Context, e boil.ContextExecutor, o *Exchange) error {
|
||||
*o = Exchange{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func exchangeBeforeUpsertHook(ctx context.Context, e boil.ContextExecutor, o *Exchange) error {
|
||||
*o = Exchange{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func exchangeAfterUpsertHook(ctx context.Context, e boil.ContextExecutor, o *Exchange) error {
|
||||
*o = Exchange{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func testExchangesHooks(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
empty := &Exchange{}
|
||||
o := &Exchange{}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, o, exchangeDBTypes, false); err != nil {
|
||||
t.Errorf("Unable to randomize Exchange object: %s", err)
|
||||
}
|
||||
|
||||
AddExchangeHook(boil.BeforeInsertHook, exchangeBeforeInsertHook)
|
||||
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)
|
||||
}
|
||||
exchangeBeforeInsertHooks = []ExchangeHook{}
|
||||
|
||||
AddExchangeHook(boil.AfterInsertHook, exchangeAfterInsertHook)
|
||||
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)
|
||||
}
|
||||
exchangeAfterInsertHooks = []ExchangeHook{}
|
||||
|
||||
AddExchangeHook(boil.AfterSelectHook, exchangeAfterSelectHook)
|
||||
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)
|
||||
}
|
||||
exchangeAfterSelectHooks = []ExchangeHook{}
|
||||
|
||||
AddExchangeHook(boil.BeforeUpdateHook, exchangeBeforeUpdateHook)
|
||||
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)
|
||||
}
|
||||
exchangeBeforeUpdateHooks = []ExchangeHook{}
|
||||
|
||||
AddExchangeHook(boil.AfterUpdateHook, exchangeAfterUpdateHook)
|
||||
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)
|
||||
}
|
||||
exchangeAfterUpdateHooks = []ExchangeHook{}
|
||||
|
||||
AddExchangeHook(boil.BeforeDeleteHook, exchangeBeforeDeleteHook)
|
||||
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)
|
||||
}
|
||||
exchangeBeforeDeleteHooks = []ExchangeHook{}
|
||||
|
||||
AddExchangeHook(boil.AfterDeleteHook, exchangeAfterDeleteHook)
|
||||
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)
|
||||
}
|
||||
exchangeAfterDeleteHooks = []ExchangeHook{}
|
||||
|
||||
AddExchangeHook(boil.BeforeUpsertHook, exchangeBeforeUpsertHook)
|
||||
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)
|
||||
}
|
||||
exchangeBeforeUpsertHooks = []ExchangeHook{}
|
||||
|
||||
AddExchangeHook(boil.AfterUpsertHook, exchangeAfterUpsertHook)
|
||||
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)
|
||||
}
|
||||
exchangeAfterUpsertHooks = []ExchangeHook{}
|
||||
}
|
||||
|
||||
func testExchangesInsert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &Exchange{}
|
||||
if err = randomize.Struct(seed, o, exchangeDBTypes, true, exchangeColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Exchange 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 := Exchanges().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testExchangesInsertWhitelist(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &Exchange{}
|
||||
if err = randomize.Struct(seed, o, exchangeDBTypes, true); err != nil {
|
||||
t.Errorf("Unable to randomize Exchange struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Whitelist(exchangeColumnsWithoutDefault...)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := Exchanges().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testExchangeOneToOneCandleUsingExchangeNameCandle(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var foreign Candle
|
||||
var local Exchange
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err := randomize.Struct(seed, &foreign, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Candle struct: %s", err)
|
||||
}
|
||||
if err := randomize.Struct(seed, &local, exchangeDBTypes, true, exchangeColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Exchange struct: %s", err)
|
||||
}
|
||||
|
||||
if err := local.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
foreign.ExchangeNameID = local.ID
|
||||
if err := foreign.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
check, err := local.ExchangeNameCandle().One(ctx, tx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if check.ExchangeNameID != foreign.ExchangeNameID {
|
||||
t.Errorf("want: %v, got %v", foreign.ExchangeNameID, check.ExchangeNameID)
|
||||
}
|
||||
|
||||
slice := ExchangeSlice{&local}
|
||||
if err = local.L.LoadExchangeNameCandle(ctx, tx, false, (*[]*Exchange)(&slice), nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.ExchangeNameCandle == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
|
||||
local.R.ExchangeNameCandle = nil
|
||||
if err = local.L.LoadExchangeNameCandle(ctx, tx, true, &local, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.ExchangeNameCandle == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
}
|
||||
|
||||
func testExchangeOneToOneSetOpCandleUsingExchangeNameCandle(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var a Exchange
|
||||
var b, c Candle
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, &a, exchangeDBTypes, false, strmangle.SetComplement(exchangePrimaryKeyColumns, exchangeColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &b, candleDBTypes, false, strmangle.SetComplement(candlePrimaryKeyColumns, candleColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &c, candleDBTypes, false, strmangle.SetComplement(candlePrimaryKeyColumns, candleColumnsWithoutDefault)...); 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 []*Candle{&b, &c} {
|
||||
err = a.SetExchangeNameCandle(ctx, tx, i != 0, x)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if a.R.ExchangeNameCandle != x {
|
||||
t.Error("relationship struct not set to correct value")
|
||||
}
|
||||
if x.R.ExchangeName != &a {
|
||||
t.Error("failed to append to foreign relationship struct")
|
||||
}
|
||||
|
||||
if a.ID != x.ExchangeNameID {
|
||||
t.Error("foreign key was wrong value", a.ID)
|
||||
}
|
||||
|
||||
zero := reflect.Zero(reflect.TypeOf(x.ExchangeNameID))
|
||||
reflect.Indirect(reflect.ValueOf(&x.ExchangeNameID)).Set(zero)
|
||||
|
||||
if err = x.Reload(ctx, tx); err != nil {
|
||||
t.Fatal("failed to reload", err)
|
||||
}
|
||||
|
||||
if a.ID != x.ExchangeNameID {
|
||||
t.Error("foreign key was wrong value", a.ID, x.ExchangeNameID)
|
||||
}
|
||||
|
||||
if _, err = x.Delete(ctx, tx); err != nil {
|
||||
t.Fatal("failed to delete x", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testExchangeToManyExchangeNameWithdrawalHistories(t *testing.T) {
|
||||
var err error
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var a Exchange
|
||||
var b, c WithdrawalHistory
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, &a, exchangeDBTypes, true, exchangeColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Exchange struct: %s", err)
|
||||
}
|
||||
|
||||
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, &b, withdrawalHistoryDBTypes, false, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &c, withdrawalHistoryDBTypes, false, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
b.ExchangeNameID = a.ID
|
||||
c.ExchangeNameID = 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.ExchangeNameWithdrawalHistories().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
bFound, cFound := false, false
|
||||
for _, v := range check {
|
||||
if v.ExchangeNameID == b.ExchangeNameID {
|
||||
bFound = true
|
||||
}
|
||||
if v.ExchangeNameID == c.ExchangeNameID {
|
||||
cFound = true
|
||||
}
|
||||
}
|
||||
|
||||
if !bFound {
|
||||
t.Error("expected to find b")
|
||||
}
|
||||
if !cFound {
|
||||
t.Error("expected to find c")
|
||||
}
|
||||
|
||||
slice := ExchangeSlice{&a}
|
||||
if err = a.L.LoadExchangeNameWithdrawalHistories(ctx, tx, false, (*[]*Exchange)(&slice), nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := len(a.R.ExchangeNameWithdrawalHistories); got != 2 {
|
||||
t.Error("number of eager loaded records wrong, got:", got)
|
||||
}
|
||||
|
||||
a.R.ExchangeNameWithdrawalHistories = nil
|
||||
if err = a.L.LoadExchangeNameWithdrawalHistories(ctx, tx, true, &a, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := len(a.R.ExchangeNameWithdrawalHistories); got != 2 {
|
||||
t.Error("number of eager loaded records wrong, got:", got)
|
||||
}
|
||||
|
||||
if t.Failed() {
|
||||
t.Logf("%#v", check)
|
||||
}
|
||||
}
|
||||
|
||||
func testExchangeToManyAddOpExchangeNameWithdrawalHistories(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var a Exchange
|
||||
var b, c, d, e WithdrawalHistory
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, &a, exchangeDBTypes, false, strmangle.SetComplement(exchangePrimaryKeyColumns, exchangeColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
foreigners := []*WithdrawalHistory{&b, &c, &d, &e}
|
||||
for _, x := range foreigners {
|
||||
if err = randomize.Struct(seed, x, 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)
|
||||
}
|
||||
if err = c.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
foreignersSplitByInsertion := [][]*WithdrawalHistory{
|
||||
{&b, &c},
|
||||
{&d, &e},
|
||||
}
|
||||
|
||||
for i, x := range foreignersSplitByInsertion {
|
||||
err = a.AddExchangeNameWithdrawalHistories(ctx, tx, i != 0, x...)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
first := x[0]
|
||||
second := x[1]
|
||||
|
||||
if a.ID != first.ExchangeNameID {
|
||||
t.Error("foreign key was wrong value", a.ID, first.ExchangeNameID)
|
||||
}
|
||||
if a.ID != second.ExchangeNameID {
|
||||
t.Error("foreign key was wrong value", a.ID, second.ExchangeNameID)
|
||||
}
|
||||
|
||||
if first.R.ExchangeName != &a {
|
||||
t.Error("relationship was not added properly to the foreign slice")
|
||||
}
|
||||
if second.R.ExchangeName != &a {
|
||||
t.Error("relationship was not added properly to the foreign slice")
|
||||
}
|
||||
|
||||
if a.R.ExchangeNameWithdrawalHistories[i*2] != first {
|
||||
t.Error("relationship struct slice not set to correct value")
|
||||
}
|
||||
if a.R.ExchangeNameWithdrawalHistories[i*2+1] != second {
|
||||
t.Error("relationship struct slice not set to correct value")
|
||||
}
|
||||
|
||||
count, err := a.ExchangeNameWithdrawalHistories().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if want := int64((i + 1) * 2); count != want {
|
||||
t.Error("want", want, "got", count)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testExchangesReload(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &Exchange{}
|
||||
if err = randomize.Struct(seed, o, exchangeDBTypes, true, exchangeColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Exchange 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 testExchangesReloadAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &Exchange{}
|
||||
if err = randomize.Struct(seed, o, exchangeDBTypes, true, exchangeColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Exchange 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 := ExchangeSlice{o}
|
||||
|
||||
if err = slice.ReloadAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testExchangesSelect(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &Exchange{}
|
||||
if err = randomize.Struct(seed, o, exchangeDBTypes, true, exchangeColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Exchange 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 := Exchanges().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 1 {
|
||||
t.Error("want one record, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
exchangeDBTypes = map[string]string{`ID`: `TEXT`, `Name`: `TEXT`}
|
||||
_ = bytes.MinRead
|
||||
)
|
||||
|
||||
func testExchangesUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if 0 == len(exchangePrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with no primary key columns")
|
||||
}
|
||||
if len(exchangeAllColumns) == len(exchangePrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &Exchange{}
|
||||
if err = randomize.Struct(seed, o, exchangeDBTypes, true, exchangeColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Exchange 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 := Exchanges().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, exchangeDBTypes, true, exchangePrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize Exchange 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 testExchangesSliceUpdateAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if len(exchangeAllColumns) == len(exchangePrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &Exchange{}
|
||||
if err = randomize.Struct(seed, o, exchangeDBTypes, true, exchangeColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Exchange 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 := Exchanges().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, exchangeDBTypes, true, exchangePrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize Exchange struct: %s", err)
|
||||
}
|
||||
|
||||
// Remove Primary keys and unique columns from what we plan to update
|
||||
var fields []string
|
||||
if strmangle.StringSliceMatch(exchangeAllColumns, exchangePrimaryKeyColumns) {
|
||||
fields = exchangeAllColumns
|
||||
} else {
|
||||
fields = strmangle.SetComplement(
|
||||
exchangeAllColumns,
|
||||
exchangePrimaryKeyColumns,
|
||||
)
|
||||
}
|
||||
|
||||
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 := ExchangeSlice{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)
|
||||
}
|
||||
}
|
||||
@@ -72,21 +72,6 @@ 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
|
||||
|
||||
@@ -109,8 +109,8 @@ 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"}
|
||||
withdrawalFiatColumnsWithoutDefault = []string{"bank_name", "bank_address", "bank_account_name", "bank_account_number", "bank_code", "withdrawal_history_id"}
|
||||
withdrawalFiatColumnsWithDefault = []string{"id", "bsb", "swift_code", "iban"}
|
||||
withdrawalFiatPrimaryKeyColumns = []string{"id"}
|
||||
)
|
||||
|
||||
|
||||
@@ -23,82 +23,85 @@ import (
|
||||
|
||||
// WithdrawalHistory is an object representing the database table.
|
||||
type WithdrawalHistory struct {
|
||||
ID string `boil:"id" json:"id" toml:"id" yaml:"id"`
|
||||
Exchange string `boil:"exchange" json:"exchange" toml:"exchange" yaml:"exchange"`
|
||||
ExchangeID string `boil:"exchange_id" json:"exchange_id" toml:"exchange_id" yaml:"exchange_id"`
|
||||
Status string `boil:"status" json:"status" toml:"status" yaml:"status"`
|
||||
Currency string `boil:"currency" json:"currency" toml:"currency" yaml:"currency"`
|
||||
Amount float64 `boil:"amount" json:"amount" toml:"amount" yaml:"amount"`
|
||||
Description null.String `boil:"description" json:"description,omitempty" toml:"description" yaml:"description,omitempty"`
|
||||
WithdrawType int64 `boil:"withdraw_type" json:"withdraw_type" toml:"withdraw_type" yaml:"withdraw_type"`
|
||||
CreatedAt string `boil:"created_at" json:"created_at" toml:"created_at" yaml:"created_at"`
|
||||
UpdatedAt string `boil:"updated_at" json:"updated_at" toml:"updated_at" yaml:"updated_at"`
|
||||
ID string `boil:"id" json:"id" toml:"id" yaml:"id"`
|
||||
ExchangeNameID string `boil:"exchange_name_id" json:"exchange_name_id" toml:"exchange_name_id" yaml:"exchange_name_id"`
|
||||
ExchangeID string `boil:"exchange_id" json:"exchange_id" toml:"exchange_id" yaml:"exchange_id"`
|
||||
Status string `boil:"status" json:"status" toml:"status" yaml:"status"`
|
||||
Currency string `boil:"currency" json:"currency" toml:"currency" yaml:"currency"`
|
||||
Amount float64 `boil:"amount" json:"amount" toml:"amount" yaml:"amount"`
|
||||
Description null.String `boil:"description" json:"description,omitempty" toml:"description" yaml:"description,omitempty"`
|
||||
WithdrawType int64 `boil:"withdraw_type" json:"withdraw_type" toml:"withdraw_type" yaml:"withdraw_type"`
|
||||
CreatedAt string `boil:"created_at" json:"created_at" toml:"created_at" yaml:"created_at"`
|
||||
UpdatedAt string `boil:"updated_at" json:"updated_at" toml:"updated_at" yaml:"updated_at"`
|
||||
|
||||
R *withdrawalHistoryR `boil:"-" json:"-" toml:"-" yaml:"-"`
|
||||
L withdrawalHistoryL `boil:"-" json:"-" toml:"-" yaml:"-"`
|
||||
}
|
||||
|
||||
var WithdrawalHistoryColumns = struct {
|
||||
ID string
|
||||
Exchange string
|
||||
ExchangeID string
|
||||
Status string
|
||||
Currency string
|
||||
Amount string
|
||||
Description string
|
||||
WithdrawType string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
ID string
|
||||
ExchangeNameID string
|
||||
ExchangeID string
|
||||
Status string
|
||||
Currency string
|
||||
Amount string
|
||||
Description string
|
||||
WithdrawType string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
}{
|
||||
ID: "id",
|
||||
Exchange: "exchange",
|
||||
ExchangeID: "exchange_id",
|
||||
Status: "status",
|
||||
Currency: "currency",
|
||||
Amount: "amount",
|
||||
Description: "description",
|
||||
WithdrawType: "withdraw_type",
|
||||
CreatedAt: "created_at",
|
||||
UpdatedAt: "updated_at",
|
||||
ID: "id",
|
||||
ExchangeNameID: "exchange_name_id",
|
||||
ExchangeID: "exchange_id",
|
||||
Status: "status",
|
||||
Currency: "currency",
|
||||
Amount: "amount",
|
||||
Description: "description",
|
||||
WithdrawType: "withdraw_type",
|
||||
CreatedAt: "created_at",
|
||||
UpdatedAt: "updated_at",
|
||||
}
|
||||
|
||||
// Generated where
|
||||
|
||||
var WithdrawalHistoryWhere = struct {
|
||||
ID whereHelperstring
|
||||
Exchange whereHelperstring
|
||||
ExchangeID whereHelperstring
|
||||
Status whereHelperstring
|
||||
Currency whereHelperstring
|
||||
Amount whereHelperfloat64
|
||||
Description whereHelpernull_String
|
||||
WithdrawType whereHelperint64
|
||||
CreatedAt whereHelperstring
|
||||
UpdatedAt whereHelperstring
|
||||
ID whereHelperstring
|
||||
ExchangeNameID whereHelperstring
|
||||
ExchangeID whereHelperstring
|
||||
Status whereHelperstring
|
||||
Currency whereHelperstring
|
||||
Amount whereHelperfloat64
|
||||
Description whereHelpernull_String
|
||||
WithdrawType whereHelperint64
|
||||
CreatedAt whereHelperstring
|
||||
UpdatedAt whereHelperstring
|
||||
}{
|
||||
ID: whereHelperstring{field: "\"withdrawal_history\".\"id\""},
|
||||
Exchange: whereHelperstring{field: "\"withdrawal_history\".\"exchange\""},
|
||||
ExchangeID: whereHelperstring{field: "\"withdrawal_history\".\"exchange_id\""},
|
||||
Status: whereHelperstring{field: "\"withdrawal_history\".\"status\""},
|
||||
Currency: whereHelperstring{field: "\"withdrawal_history\".\"currency\""},
|
||||
Amount: whereHelperfloat64{field: "\"withdrawal_history\".\"amount\""},
|
||||
Description: whereHelpernull_String{field: "\"withdrawal_history\".\"description\""},
|
||||
WithdrawType: whereHelperint64{field: "\"withdrawal_history\".\"withdraw_type\""},
|
||||
CreatedAt: whereHelperstring{field: "\"withdrawal_history\".\"created_at\""},
|
||||
UpdatedAt: whereHelperstring{field: "\"withdrawal_history\".\"updated_at\""},
|
||||
ID: whereHelperstring{field: "\"withdrawal_history\".\"id\""},
|
||||
ExchangeNameID: whereHelperstring{field: "\"withdrawal_history\".\"exchange_name_id\""},
|
||||
ExchangeID: whereHelperstring{field: "\"withdrawal_history\".\"exchange_id\""},
|
||||
Status: whereHelperstring{field: "\"withdrawal_history\".\"status\""},
|
||||
Currency: whereHelperstring{field: "\"withdrawal_history\".\"currency\""},
|
||||
Amount: whereHelperfloat64{field: "\"withdrawal_history\".\"amount\""},
|
||||
Description: whereHelpernull_String{field: "\"withdrawal_history\".\"description\""},
|
||||
WithdrawType: whereHelperint64{field: "\"withdrawal_history\".\"withdraw_type\""},
|
||||
CreatedAt: whereHelperstring{field: "\"withdrawal_history\".\"created_at\""},
|
||||
UpdatedAt: whereHelperstring{field: "\"withdrawal_history\".\"updated_at\""},
|
||||
}
|
||||
|
||||
// WithdrawalHistoryRels is where relationship names are stored.
|
||||
var WithdrawalHistoryRels = struct {
|
||||
ExchangeName string
|
||||
WithdrawalCryptos string
|
||||
WithdrawalFiats string
|
||||
}{
|
||||
ExchangeName: "ExchangeName",
|
||||
WithdrawalCryptos: "WithdrawalCryptos",
|
||||
WithdrawalFiats: "WithdrawalFiats",
|
||||
}
|
||||
|
||||
// withdrawalHistoryR is where relationships are stored.
|
||||
type withdrawalHistoryR struct {
|
||||
ExchangeName *Exchange
|
||||
WithdrawalCryptos WithdrawalCryptoSlice
|
||||
WithdrawalFiats WithdrawalFiatSlice
|
||||
}
|
||||
@@ -112,8 +115,8 @@ func (*withdrawalHistoryR) NewStruct() *withdrawalHistoryR {
|
||||
type withdrawalHistoryL struct{}
|
||||
|
||||
var (
|
||||
withdrawalHistoryAllColumns = []string{"id", "exchange", "exchange_id", "status", "currency", "amount", "description", "withdraw_type", "created_at", "updated_at"}
|
||||
withdrawalHistoryColumnsWithoutDefault = []string{"id", "exchange", "exchange_id", "status", "currency", "amount", "description", "withdraw_type"}
|
||||
withdrawalHistoryAllColumns = []string{"id", "exchange_name_id", "exchange_id", "status", "currency", "amount", "description", "withdraw_type", "created_at", "updated_at"}
|
||||
withdrawalHistoryColumnsWithoutDefault = []string{"id", "exchange_name_id", "exchange_id", "status", "currency", "amount", "description", "withdraw_type"}
|
||||
withdrawalHistoryColumnsWithDefault = []string{"created_at", "updated_at"}
|
||||
withdrawalHistoryPrimaryKeyColumns = []string{"id"}
|
||||
)
|
||||
@@ -393,6 +396,20 @@ func (q withdrawalHistoryQuery) Exists(ctx context.Context, exec boil.ContextExe
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
// ExchangeName pointed to by the foreign key.
|
||||
func (o *WithdrawalHistory) ExchangeName(mods ...qm.QueryMod) exchangeQuery {
|
||||
queryMods := []qm.QueryMod{
|
||||
qm.Where("\"id\" = ?", o.ExchangeNameID),
|
||||
}
|
||||
|
||||
queryMods = append(queryMods, mods...)
|
||||
|
||||
query := Exchanges(queryMods...)
|
||||
queries.SetFrom(query.Query, "\"exchange\"")
|
||||
|
||||
return query
|
||||
}
|
||||
|
||||
// WithdrawalCryptos retrieves all the withdrawal_crypto's WithdrawalCryptos with an executor.
|
||||
func (o *WithdrawalHistory) WithdrawalCryptos(mods ...qm.QueryMod) withdrawalCryptoQuery {
|
||||
var queryMods []qm.QueryMod
|
||||
@@ -435,6 +452,107 @@ func (o *WithdrawalHistory) WithdrawalFiats(mods ...qm.QueryMod) withdrawalFiatQ
|
||||
return query
|
||||
}
|
||||
|
||||
// LoadExchangeName allows an eager lookup of values, cached into the
|
||||
// loaded structs of the objects. This is for an N-1 relationship.
|
||||
func (withdrawalHistoryL) LoadExchangeName(ctx context.Context, e boil.ContextExecutor, singular bool, maybeWithdrawalHistory interface{}, mods queries.Applicator) error {
|
||||
var slice []*WithdrawalHistory
|
||||
var object *WithdrawalHistory
|
||||
|
||||
if singular {
|
||||
object = maybeWithdrawalHistory.(*WithdrawalHistory)
|
||||
} else {
|
||||
slice = *maybeWithdrawalHistory.(*[]*WithdrawalHistory)
|
||||
}
|
||||
|
||||
args := make([]interface{}, 0, 1)
|
||||
if singular {
|
||||
if object.R == nil {
|
||||
object.R = &withdrawalHistoryR{}
|
||||
}
|
||||
args = append(args, object.ExchangeNameID)
|
||||
|
||||
} else {
|
||||
Outer:
|
||||
for _, obj := range slice {
|
||||
if obj.R == nil {
|
||||
obj.R = &withdrawalHistoryR{}
|
||||
}
|
||||
|
||||
for _, a := range args {
|
||||
if a == obj.ExchangeNameID {
|
||||
continue Outer
|
||||
}
|
||||
}
|
||||
|
||||
args = append(args, obj.ExchangeNameID)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if len(args) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
query := NewQuery(qm.From(`exchange`), qm.WhereIn(`exchange.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 Exchange")
|
||||
}
|
||||
|
||||
var resultSlice []*Exchange
|
||||
if err = queries.Bind(results, &resultSlice); err != nil {
|
||||
return errors.Wrap(err, "failed to bind eager loaded slice Exchange")
|
||||
}
|
||||
|
||||
if err = results.Close(); err != nil {
|
||||
return errors.Wrap(err, "failed to close results of eager load for exchange")
|
||||
}
|
||||
if err = results.Err(); err != nil {
|
||||
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for exchange")
|
||||
}
|
||||
|
||||
if len(withdrawalHistoryAfterSelectHooks) != 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.ExchangeName = foreign
|
||||
if foreign.R == nil {
|
||||
foreign.R = &exchangeR{}
|
||||
}
|
||||
foreign.R.ExchangeNameWithdrawalHistories = append(foreign.R.ExchangeNameWithdrawalHistories, object)
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, local := range slice {
|
||||
for _, foreign := range resultSlice {
|
||||
if local.ExchangeNameID == foreign.ID {
|
||||
local.R.ExchangeName = foreign
|
||||
if foreign.R == nil {
|
||||
foreign.R = &exchangeR{}
|
||||
}
|
||||
foreign.R.ExchangeNameWithdrawalHistories = append(foreign.R.ExchangeNameWithdrawalHistories, local)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadWithdrawalCryptos allows an eager lookup of values, cached into the
|
||||
// loaded structs of the objects. This is for a 1-M or N-M relationship.
|
||||
func (withdrawalHistoryL) LoadWithdrawalCryptos(ctx context.Context, e boil.ContextExecutor, singular bool, maybeWithdrawalHistory interface{}, mods queries.Applicator) error {
|
||||
@@ -625,6 +743,53 @@ func (withdrawalHistoryL) LoadWithdrawalFiats(ctx context.Context, e boil.Contex
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetExchangeName of the withdrawalHistory to the related item.
|
||||
// Sets o.R.ExchangeName to related.
|
||||
// Adds o to related.R.ExchangeNameWithdrawalHistories.
|
||||
func (o *WithdrawalHistory) SetExchangeName(ctx context.Context, exec boil.ContextExecutor, insert bool, related *Exchange) 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_history\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 0, []string{"exchange_name_id"}),
|
||||
strmangle.WhereClause("\"", "\"", 0, withdrawalHistoryPrimaryKeyColumns),
|
||||
)
|
||||
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.ExchangeNameID = related.ID
|
||||
if o.R == nil {
|
||||
o.R = &withdrawalHistoryR{
|
||||
ExchangeName: related,
|
||||
}
|
||||
} else {
|
||||
o.R.ExchangeName = related
|
||||
}
|
||||
|
||||
if related.R == nil {
|
||||
related.R = &exchangeR{
|
||||
ExchangeNameWithdrawalHistories: WithdrawalHistorySlice{o},
|
||||
}
|
||||
} else {
|
||||
related.R.ExchangeNameWithdrawalHistories = append(related.R.ExchangeNameWithdrawalHistories, o)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddWithdrawalCryptos adds the given related objects to the existing relationships
|
||||
// of the withdrawal_history, optionally inserting them as new records.
|
||||
// Appends related to o.R.WithdrawalCryptos.
|
||||
|
||||
@@ -800,6 +800,114 @@ func testWithdrawalHistoryToManyAddOpWithdrawalFiats(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
func testWithdrawalHistoryToOneExchangeUsingExchangeName(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var local WithdrawalHistory
|
||||
var foreign Exchange
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err := randomize.Struct(seed, &local, withdrawalHistoryDBTypes, false, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
if err := randomize.Struct(seed, &foreign, exchangeDBTypes, false, exchangeColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize Exchange struct: %s", err)
|
||||
}
|
||||
|
||||
if err := foreign.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
local.ExchangeNameID = foreign.ID
|
||||
if err := local.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
check, err := local.ExchangeName().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 := WithdrawalHistorySlice{&local}
|
||||
if err = local.L.LoadExchangeName(ctx, tx, false, (*[]*WithdrawalHistory)(&slice), nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.ExchangeName == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
|
||||
local.R.ExchangeName = nil
|
||||
if err = local.L.LoadExchangeName(ctx, tx, true, &local, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.ExchangeName == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoryToOneSetOpExchangeUsingExchangeName(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 Exchange
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, &a, withdrawalHistoryDBTypes, false, strmangle.SetComplement(withdrawalHistoryPrimaryKeyColumns, withdrawalHistoryColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &b, exchangeDBTypes, false, strmangle.SetComplement(exchangePrimaryKeyColumns, exchangeColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &c, exchangeDBTypes, false, strmangle.SetComplement(exchangePrimaryKeyColumns, exchangeColumnsWithoutDefault)...); 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 []*Exchange{&b, &c} {
|
||||
err = a.SetExchangeName(ctx, tx, i != 0, x)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if a.R.ExchangeName != x {
|
||||
t.Error("relationship struct not set to correct value")
|
||||
}
|
||||
|
||||
if x.R.ExchangeNameWithdrawalHistories[0] != &a {
|
||||
t.Error("failed to append to foreign relationship struct")
|
||||
}
|
||||
if a.ExchangeNameID != x.ID {
|
||||
t.Error("foreign key was wrong value", a.ExchangeNameID)
|
||||
}
|
||||
|
||||
zero := reflect.Zero(reflect.TypeOf(a.ExchangeNameID))
|
||||
reflect.Indirect(reflect.ValueOf(&a.ExchangeNameID)).Set(zero)
|
||||
|
||||
if err = a.Reload(ctx, tx); err != nil {
|
||||
t.Fatal("failed to reload", err)
|
||||
}
|
||||
|
||||
if a.ExchangeNameID != x.ID {
|
||||
t.Error("foreign key was wrong value", a.ExchangeNameID, x.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesReload(t *testing.T) {
|
||||
t.Parallel()
|
||||
@@ -875,7 +983,7 @@ func testWithdrawalHistoriesSelect(t *testing.T) {
|
||||
}
|
||||
|
||||
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`}
|
||||
withdrawalHistoryDBTypes = map[string]string{`ID`: `TEXT`, `ExchangeNameID`: `TEXT`, `ExchangeID`: `TEXT`, `Status`: `TEXT`, `Currency`: `TEXT`, `Amount`: `REAL`, `Description`: `TEXT`, `WithdrawType`: `INTEGER`, `CreatedAt`: `TIMESTAMP`, `UpdatedAt`: `TIMESTAMP`}
|
||||
_ = bytes.MinRead
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user