Feature: Candle conversion & Candle validation (#716)

* Remove old concept. Introduce new job types and candle scaling

* Adds extra processing, commands

* new concept for queued jobs. Jobs can pause. New commands to manage status

* =End of day commit designing tables and implementing prerequisites further.

* Adds postgres data history relations

* Fixes table design for sqlite. Fixes all issues from merge

* Fixes craziness of database design. Adds some functions to get related jobs

* Fixes errors

* Updates some documentation, manages prerequisite jobs a little better, adds rpc funcs

* Fixes database design and adjust repo functions

* Tests database relationship

* Test coverage of new job functions

* Finishes coverage of new functions

* Commands and RPC coverage

* New database modifications for new job types

* Adds db support of new columns. Adds conversion validation. lint

* command blurb changes

* Allows websocket test to pass consistently

* Fixes merge issue preventing datahistorymanager from starting via config

* Minor fixes for different job type processing

* Fixes rangeholder issue, fixes validation, does not address jobs not starting or wrong status

* Fixes database tests, but at what cost. Fixes dhm tests

* Fixes dhj completion issue. Adds prerequisite by nickname

* Fixes validation processing. Adds db tests and validation

* Fixes validation job processing range

* Fixes trade sql. Reduces defaults. Validation processing and errors

* Updates cli job commands. adds validation decimal. fix job validation

* Expands run job handling and tests

* Validation work

* Fixes validation processing

* candle relations. new job type. updating database design

* Adds secondary exchange support. Sets stage for candle override

* Re adds accidentally deleted relationship

* Updates loading and saving candles to have relationship data when relevant

* Now validates and replaces candle data appropriately

* Fixes getting and setting datahistory data. Neatens DHM

* Test coverage

* Updates proto for new db types. New test coverage. Secondary exchange work

* Investigation into never-ending validation jobs. Now that intervals are ruled out, now need to complete the job....

* Fixes issues with validation job completion. Fixes validation volume issue for secondary exchange

* Adds candle warning support to the backtester

* Fixes warnings

* lint and begin docs

* Documentation updates. Final testing changes

* Minor fixes

* docs, prerequisite checks, more testing

* Fixes binance trade test. Rename err

* Documentation fixes. Figure fixes

* documentation update

* Fixes remote PSQL tests

* Fix binance mock test

* Remove unnecessary JSON

* regen proto

* Some minor nit fixes

* Var usage, query sorting, log improving, sql mirroring

* Extra coverage

* Experimental removal of m.jobs and mutex. Fix messaging

* Fixes error

* Lint fixes, command description improvements. More isRunning gates

* description improvements

* Lint

* BUFF regenerate

* Rough concept to fix insertions taking up long periods of time

* New calculation for trade data. Adds batch saving

This also adds an experimental request feature to shut down lingering requests. However, its uncertain whether or not this is having any impact. Initially thought it was the trades that was taking time and not SQL. Will investigate further

* Removes experimental requester. Adds documentation. Fixes typo

* rm unused error

* re-adds more forgotten contributors

* Now with proper commit count
This commit is contained in:
Scott
2021-08-05 10:27:27 +10:00
committed by GitHub
parent 3b1fe81d8b
commit 48434dfd46
67 changed files with 24651 additions and 12894 deletions

View File

@@ -193,8 +193,11 @@ func TestInsert(t *testing.T) {
// TestToOne tests cannot be run in parallel
// or deadlocks can occur.
func TestToOne(t *testing.T) {
t.Run("CandleToDatahistoryjobUsingValidationJob", testCandleToOneDatahistoryjobUsingValidationJob)
t.Run("CandleToDatahistoryjobUsingSourceJob", testCandleToOneDatahistoryjobUsingSourceJob)
t.Run("CandleToExchangeUsingExchangeName", testCandleToOneExchangeUsingExchangeName)
t.Run("DatahistoryjobToExchangeUsingExchangeName", testDatahistoryjobToOneExchangeUsingExchangeName)
t.Run("DatahistoryjobToExchangeUsingSecondaryExchange", testDatahistoryjobToOneExchangeUsingSecondaryExchange)
t.Run("DatahistoryjobresultToDatahistoryjobUsingJob", testDatahistoryjobresultToOneDatahistoryjobUsingJob)
t.Run("ScriptExecutionToScriptUsingScript", testScriptExecutionToOneScriptUsingScript)
t.Run("TradeToExchangeUsingExchangeName", testTradeToOneExchangeUsingExchangeName)
@@ -213,8 +216,13 @@ func TestOneToOne(t *testing.T) {
// TestToMany tests cannot be run in parallel
// or deadlocks can occur.
func TestToMany(t *testing.T) {
t.Run("DatahistoryjobToValidationJobCandles", testDatahistoryjobToManyValidationJobCandles)
t.Run("DatahistoryjobToSourceJobCandles", testDatahistoryjobToManySourceJobCandles)
t.Run("DatahistoryjobToPrerequisiteJobDatahistoryjobs", testDatahistoryjobToManyPrerequisiteJobDatahistoryjobs)
t.Run("DatahistoryjobToJobDatahistoryjobs", testDatahistoryjobToManyJobDatahistoryjobs)
t.Run("DatahistoryjobToJobDatahistoryjobresults", testDatahistoryjobToManyJobDatahistoryjobresults)
t.Run("ExchangeToExchangeNameDatahistoryjobs", testExchangeToManyExchangeNameDatahistoryjobs)
t.Run("ExchangeToSecondaryExchangeDatahistoryjobs", testExchangeToManySecondaryExchangeDatahistoryjobs)
t.Run("ExchangeToExchangeNameWithdrawalHistories", testExchangeToManyExchangeNameWithdrawalHistories)
t.Run("ScriptToScriptExecutions", testScriptToManyScriptExecutions)
t.Run("WithdrawalHistoryToWithdrawalCryptos", testWithdrawalHistoryToManyWithdrawalCryptos)
@@ -224,8 +232,11 @@ func TestToMany(t *testing.T) {
// TestToOneSet tests cannot be run in parallel
// or deadlocks can occur.
func TestToOneSet(t *testing.T) {
t.Run("CandleToDatahistoryjobUsingValidationJobCandles", testCandleToOneSetOpDatahistoryjobUsingValidationJob)
t.Run("CandleToDatahistoryjobUsingSourceJobCandles", testCandleToOneSetOpDatahistoryjobUsingSourceJob)
t.Run("CandleToExchangeUsingExchangeNameCandle", testCandleToOneSetOpExchangeUsingExchangeName)
t.Run("DatahistoryjobToExchangeUsingExchangeNameDatahistoryjobs", testDatahistoryjobToOneSetOpExchangeUsingExchangeName)
t.Run("DatahistoryjobToExchangeUsingSecondaryExchangeDatahistoryjobs", testDatahistoryjobToOneSetOpExchangeUsingSecondaryExchange)
t.Run("DatahistoryjobresultToDatahistoryjobUsingJobDatahistoryjobresults", testDatahistoryjobresultToOneSetOpDatahistoryjobUsingJob)
t.Run("ScriptExecutionToScriptUsingScriptExecutions", testScriptExecutionToOneSetOpScriptUsingScript)
t.Run("TradeToExchangeUsingExchangeNameTrade", testTradeToOneSetOpExchangeUsingExchangeName)
@@ -236,7 +247,11 @@ func TestToOneSet(t *testing.T) {
// TestToOneRemove tests cannot be run in parallel
// or deadlocks can occur.
func TestToOneRemove(t *testing.T) {}
func TestToOneRemove(t *testing.T) {
t.Run("CandleToDatahistoryjobUsingValidationJobCandles", testCandleToOneRemoveOpDatahistoryjobUsingValidationJob)
t.Run("CandleToDatahistoryjobUsingSourceJobCandles", testCandleToOneRemoveOpDatahistoryjobUsingSourceJob)
t.Run("DatahistoryjobToExchangeUsingSecondaryExchangeDatahistoryjobs", testDatahistoryjobToOneRemoveOpExchangeUsingSecondaryExchange)
}
// TestOneToOneSet tests cannot be run in parallel
// or deadlocks can occur.
@@ -252,8 +267,13 @@ func TestOneToOneRemove(t *testing.T) {}
// TestToManyAdd tests cannot be run in parallel
// or deadlocks can occur.
func TestToManyAdd(t *testing.T) {
t.Run("DatahistoryjobToValidationJobCandles", testDatahistoryjobToManyAddOpValidationJobCandles)
t.Run("DatahistoryjobToSourceJobCandles", testDatahistoryjobToManyAddOpSourceJobCandles)
t.Run("DatahistoryjobToPrerequisiteJobDatahistoryjobs", testDatahistoryjobToManyAddOpPrerequisiteJobDatahistoryjobs)
t.Run("DatahistoryjobToJobDatahistoryjobs", testDatahistoryjobToManyAddOpJobDatahistoryjobs)
t.Run("DatahistoryjobToJobDatahistoryjobresults", testDatahistoryjobToManyAddOpJobDatahistoryjobresults)
t.Run("ExchangeToExchangeNameDatahistoryjobs", testExchangeToManyAddOpExchangeNameDatahistoryjobs)
t.Run("ExchangeToSecondaryExchangeDatahistoryjobs", testExchangeToManyAddOpSecondaryExchangeDatahistoryjobs)
t.Run("ExchangeToExchangeNameWithdrawalHistories", testExchangeToManyAddOpExchangeNameWithdrawalHistories)
t.Run("ScriptToScriptExecutions", testScriptToManyAddOpScriptExecutions)
t.Run("WithdrawalHistoryToWithdrawalCryptos", testWithdrawalHistoryToManyAddOpWithdrawalCryptos)
@@ -262,11 +282,23 @@ func TestToManyAdd(t *testing.T) {
// TestToManySet tests cannot be run in parallel
// or deadlocks can occur.
func TestToManySet(t *testing.T) {}
func TestToManySet(t *testing.T) {
t.Run("DatahistoryjobToValidationJobCandles", testDatahistoryjobToManySetOpValidationJobCandles)
t.Run("DatahistoryjobToSourceJobCandles", testDatahistoryjobToManySetOpSourceJobCandles)
t.Run("DatahistoryjobToPrerequisiteJobDatahistoryjobs", testDatahistoryjobToManySetOpPrerequisiteJobDatahistoryjobs)
t.Run("DatahistoryjobToJobDatahistoryjobs", testDatahistoryjobToManySetOpJobDatahistoryjobs)
t.Run("ExchangeToSecondaryExchangeDatahistoryjobs", testExchangeToManySetOpSecondaryExchangeDatahistoryjobs)
}
// TestToManyRemove tests cannot be run in parallel
// or deadlocks can occur.
func TestToManyRemove(t *testing.T) {}
func TestToManyRemove(t *testing.T) {
t.Run("DatahistoryjobToValidationJobCandles", testDatahistoryjobToManyRemoveOpValidationJobCandles)
t.Run("DatahistoryjobToSourceJobCandles", testDatahistoryjobToManyRemoveOpSourceJobCandles)
t.Run("DatahistoryjobToPrerequisiteJobDatahistoryjobs", testDatahistoryjobToManyRemoveOpPrerequisiteJobDatahistoryjobs)
t.Run("DatahistoryjobToJobDatahistoryjobs", testDatahistoryjobToManyRemoveOpJobDatahistoryjobs)
t.Run("ExchangeToSecondaryExchangeDatahistoryjobs", testExchangeToManyRemoveOpSecondaryExchangeDatahistoryjobs)
}
func TestReload(t *testing.T) {
t.Run("AuditEvents", testAuditEventsReload)

View File

@@ -4,29 +4,29 @@
package sqlite3
var TableNames = struct {
AuditEvent string
Candle string
Datahistoryjob string
Datahistoryjobresult string
Exchange string
GooseDBVersion string
Script string
ScriptExecution string
Trade string
WithdrawalCrypto string
WithdrawalFiat string
WithdrawalHistory string
AuditEvent string
Candle string
Datahistoryjob string
Datahistoryjobrelations string
Datahistoryjobresult string
Exchange string
Script string
ScriptExecution string
Trade string
WithdrawalCrypto string
WithdrawalFiat string
WithdrawalHistory string
}{
AuditEvent: "audit_event",
Candle: "candle",
Datahistoryjob: "datahistoryjob",
Datahistoryjobresult: "datahistoryjobresult",
Exchange: "exchange",
GooseDBVersion: "goose_db_version",
Script: "script",
ScriptExecution: "script_execution",
Trade: "trade",
WithdrawalCrypto: "withdrawal_crypto",
WithdrawalFiat: "withdrawal_fiat",
WithdrawalHistory: "withdrawal_history",
AuditEvent: "audit_event",
Candle: "candle",
Datahistoryjob: "datahistoryjob",
Datahistoryjobrelations: "datahistoryjobrelations",
Datahistoryjobresult: "datahistoryjobresult",
Exchange: "exchange",
Script: "script",
ScriptExecution: "script_execution",
Trade: "trade",
WithdrawalCrypto: "withdrawal_crypto",
WithdrawalFiat: "withdrawal_fiat",
WithdrawalHistory: "withdrawal_history",
}

View File

@@ -18,53 +18,63 @@ import (
"github.com/thrasher-corp/sqlboiler/queries/qm"
"github.com/thrasher-corp/sqlboiler/queries/qmhelper"
"github.com/thrasher-corp/sqlboiler/strmangle"
"github.com/volatiletech/null"
)
// 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"`
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"`
SourceJobID null.String `boil:"source_job_id" json:"source_job_id,omitempty" toml:"source_job_id" yaml:"source_job_id,omitempty"`
ValidationJobID null.String `boil:"validation_job_id" json:"validation_job_id,omitempty" toml:"validation_job_id" yaml:"validation_job_id,omitempty"`
ValidationIssues null.String `boil:"validation_issues" json:"validation_issues,omitempty" toml:"validation_issues" yaml:"validation_issues,omitempty"`
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 string
ExchangeNameID string
Base string
Quote string
Interval string
Timestamp string
Open string
High string
Low string
Close string
Volume string
Asset string
SourceJobID string
ValidationJobID string
ValidationIssues 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",
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",
SourceJobID: "source_job_id",
ValidationJobID: "validation_job_id",
ValidationIssues: "validation_issues",
}
// Generated where
@@ -84,44 +94,79 @@ func (w whereHelperfloat64) GTE(x float64) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.GTE, x)
}
type whereHelpernull_String struct{ field string }
func (w whereHelpernull_String) EQ(x null.String) qm.QueryMod {
return qmhelper.WhereNullEQ(w.field, false, x)
}
func (w whereHelpernull_String) NEQ(x null.String) qm.QueryMod {
return qmhelper.WhereNullEQ(w.field, true, x)
}
func (w whereHelpernull_String) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) }
func (w whereHelpernull_String) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) }
func (w whereHelpernull_String) LT(x null.String) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.LT, x)
}
func (w whereHelpernull_String) LTE(x null.String) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.LTE, x)
}
func (w whereHelpernull_String) GT(x null.String) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.GT, x)
}
func (w whereHelpernull_String) GTE(x null.String) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.GTE, x)
}
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
ExchangeNameID whereHelperstring
Base whereHelperstring
Quote whereHelperstring
Interval whereHelperstring
Timestamp whereHelperstring
Open whereHelperfloat64
High whereHelperfloat64
Low whereHelperfloat64
Close whereHelperfloat64
Volume whereHelperfloat64
Asset whereHelperstring
SourceJobID whereHelpernull_String
ValidationJobID whereHelpernull_String
ValidationIssues whereHelpernull_String
}{
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\""},
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\""},
SourceJobID: whereHelpernull_String{field: "\"candle\".\"source_job_id\""},
ValidationJobID: whereHelpernull_String{field: "\"candle\".\"validation_job_id\""},
ValidationIssues: whereHelpernull_String{field: "\"candle\".\"validation_issues\""},
}
// CandleRels is where relationship names are stored.
var CandleRels = struct {
ExchangeName string
ValidationJob string
SourceJob string
ExchangeName string
}{
ExchangeName: "ExchangeName",
ValidationJob: "ValidationJob",
SourceJob: "SourceJob",
ExchangeName: "ExchangeName",
}
// candleR is where relationships are stored.
type candleR struct {
ExchangeName *Exchange
ValidationJob *Datahistoryjob
SourceJob *Datahistoryjob
ExchangeName *Exchange
}
// NewStruct creates a new relationship struct
@@ -133,8 +178,8 @@ func (*candleR) NewStruct() *candleR {
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"}
candleAllColumns = []string{"id", "exchange_name_id", "Base", "Quote", "Interval", "Timestamp", "Open", "High", "Low", "Close", "Volume", "Asset", "source_job_id", "validation_job_id", "validation_issues"}
candleColumnsWithoutDefault = []string{"id", "exchange_name_id", "Base", "Quote", "Interval", "Timestamp", "Open", "High", "Low", "Close", "Volume", "Asset", "source_job_id", "validation_job_id", "validation_issues"}
candleColumnsWithDefault = []string{}
candlePrimaryKeyColumns = []string{"id"}
)
@@ -414,6 +459,34 @@ func (q candleQuery) Exists(ctx context.Context, exec boil.ContextExecutor) (boo
return count > 0, nil
}
// ValidationJob pointed to by the foreign key.
func (o *Candle) ValidationJob(mods ...qm.QueryMod) datahistoryjobQuery {
queryMods := []qm.QueryMod{
qm.Where("\"id\" = ?", o.ValidationJobID),
}
queryMods = append(queryMods, mods...)
query := Datahistoryjobs(queryMods...)
queries.SetFrom(query.Query, "\"datahistoryjob\"")
return query
}
// SourceJob pointed to by the foreign key.
func (o *Candle) SourceJob(mods ...qm.QueryMod) datahistoryjobQuery {
queryMods := []qm.QueryMod{
qm.Where("\"id\" = ?", o.SourceJobID),
}
queryMods = append(queryMods, mods...)
query := Datahistoryjobs(queryMods...)
queries.SetFrom(query.Query, "\"datahistoryjob\"")
return query
}
// ExchangeName pointed to by the foreign key.
func (o *Candle) ExchangeName(mods ...qm.QueryMod) exchangeQuery {
queryMods := []qm.QueryMod{
@@ -428,6 +501,216 @@ func (o *Candle) ExchangeName(mods ...qm.QueryMod) exchangeQuery {
return query
}
// LoadValidationJob allows an eager lookup of values, cached into the
// loaded structs of the objects. This is for an N-1 relationship.
func (candleL) LoadValidationJob(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{}
}
if !queries.IsNil(object.ValidationJobID) {
args = append(args, object.ValidationJobID)
}
} else {
Outer:
for _, obj := range slice {
if obj.R == nil {
obj.R = &candleR{}
}
for _, a := range args {
if queries.Equal(a, obj.ValidationJobID) {
continue Outer
}
}
if !queries.IsNil(obj.ValidationJobID) {
args = append(args, obj.ValidationJobID)
}
}
}
if len(args) == 0 {
return nil
}
query := NewQuery(qm.From(`datahistoryjob`), qm.WhereIn(`datahistoryjob.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 Datahistoryjob")
}
var resultSlice []*Datahistoryjob
if err = queries.Bind(results, &resultSlice); err != nil {
return errors.Wrap(err, "failed to bind eager loaded slice Datahistoryjob")
}
if err = results.Close(); err != nil {
return errors.Wrap(err, "failed to close results of eager load for datahistoryjob")
}
if err = results.Err(); err != nil {
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for datahistoryjob")
}
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.ValidationJob = foreign
if foreign.R == nil {
foreign.R = &datahistoryjobR{}
}
foreign.R.ValidationJobCandles = append(foreign.R.ValidationJobCandles, object)
return nil
}
for _, local := range slice {
for _, foreign := range resultSlice {
if queries.Equal(local.ValidationJobID, foreign.ID) {
local.R.ValidationJob = foreign
if foreign.R == nil {
foreign.R = &datahistoryjobR{}
}
foreign.R.ValidationJobCandles = append(foreign.R.ValidationJobCandles, local)
break
}
}
}
return nil
}
// LoadSourceJob allows an eager lookup of values, cached into the
// loaded structs of the objects. This is for an N-1 relationship.
func (candleL) LoadSourceJob(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{}
}
if !queries.IsNil(object.SourceJobID) {
args = append(args, object.SourceJobID)
}
} else {
Outer:
for _, obj := range slice {
if obj.R == nil {
obj.R = &candleR{}
}
for _, a := range args {
if queries.Equal(a, obj.SourceJobID) {
continue Outer
}
}
if !queries.IsNil(obj.SourceJobID) {
args = append(args, obj.SourceJobID)
}
}
}
if len(args) == 0 {
return nil
}
query := NewQuery(qm.From(`datahistoryjob`), qm.WhereIn(`datahistoryjob.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 Datahistoryjob")
}
var resultSlice []*Datahistoryjob
if err = queries.Bind(results, &resultSlice); err != nil {
return errors.Wrap(err, "failed to bind eager loaded slice Datahistoryjob")
}
if err = results.Close(); err != nil {
return errors.Wrap(err, "failed to close results of eager load for datahistoryjob")
}
if err = results.Err(); err != nil {
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for datahistoryjob")
}
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.SourceJob = foreign
if foreign.R == nil {
foreign.R = &datahistoryjobR{}
}
foreign.R.SourceJobCandles = append(foreign.R.SourceJobCandles, object)
return nil
}
for _, local := range slice {
for _, foreign := range resultSlice {
if queries.Equal(local.SourceJobID, foreign.ID) {
local.R.SourceJob = foreign
if foreign.R == nil {
foreign.R = &datahistoryjobR{}
}
foreign.R.SourceJobCandles = append(foreign.R.SourceJobCandles, local)
break
}
}
}
return nil
}
// 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 {
@@ -529,6 +812,162 @@ func (candleL) LoadExchangeName(ctx context.Context, e boil.ContextExecutor, sin
return nil
}
// SetValidationJob of the candle to the related item.
// Sets o.R.ValidationJob to related.
// Adds o to related.R.ValidationJobCandles.
func (o *Candle) SetValidationJob(ctx context.Context, exec boil.ContextExecutor, insert bool, related *Datahistoryjob) 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{"validation_job_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")
}
queries.Assign(&o.ValidationJobID, related.ID)
if o.R == nil {
o.R = &candleR{
ValidationJob: related,
}
} else {
o.R.ValidationJob = related
}
if related.R == nil {
related.R = &datahistoryjobR{
ValidationJobCandles: CandleSlice{o},
}
} else {
related.R.ValidationJobCandles = append(related.R.ValidationJobCandles, o)
}
return nil
}
// RemoveValidationJob relationship.
// Sets o.R.ValidationJob to nil.
// Removes o from all passed in related items' relationships struct (Optional).
func (o *Candle) RemoveValidationJob(ctx context.Context, exec boil.ContextExecutor, related *Datahistoryjob) error {
var err error
queries.SetScanner(&o.ValidationJobID, nil)
if _, err = o.Update(ctx, exec, boil.Whitelist("validation_job_id")); err != nil {
return errors.Wrap(err, "failed to update local table")
}
o.R.ValidationJob = nil
if related == nil || related.R == nil {
return nil
}
for i, ri := range related.R.ValidationJobCandles {
if queries.Equal(o.ValidationJobID, ri.ValidationJobID) {
continue
}
ln := len(related.R.ValidationJobCandles)
if ln > 1 && i < ln-1 {
related.R.ValidationJobCandles[i] = related.R.ValidationJobCandles[ln-1]
}
related.R.ValidationJobCandles = related.R.ValidationJobCandles[:ln-1]
break
}
return nil
}
// SetSourceJob of the candle to the related item.
// Sets o.R.SourceJob to related.
// Adds o to related.R.SourceJobCandles.
func (o *Candle) SetSourceJob(ctx context.Context, exec boil.ContextExecutor, insert bool, related *Datahistoryjob) 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{"source_job_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")
}
queries.Assign(&o.SourceJobID, related.ID)
if o.R == nil {
o.R = &candleR{
SourceJob: related,
}
} else {
o.R.SourceJob = related
}
if related.R == nil {
related.R = &datahistoryjobR{
SourceJobCandles: CandleSlice{o},
}
} else {
related.R.SourceJobCandles = append(related.R.SourceJobCandles, o)
}
return nil
}
// RemoveSourceJob relationship.
// Sets o.R.SourceJob to nil.
// Removes o from all passed in related items' relationships struct (Optional).
func (o *Candle) RemoveSourceJob(ctx context.Context, exec boil.ContextExecutor, related *Datahistoryjob) error {
var err error
queries.SetScanner(&o.SourceJobID, nil)
if _, err = o.Update(ctx, exec, boil.Whitelist("source_job_id")); err != nil {
return errors.Wrap(err, "failed to update local table")
}
o.R.SourceJob = nil
if related == nil || related.R == nil {
return nil
}
for i, ri := range related.R.SourceJobCandles {
if queries.Equal(o.SourceJobID, ri.SourceJobID) {
continue
}
ln := len(related.R.SourceJobCandles)
if ln > 1 && i < ln-1 {
related.R.SourceJobCandles[i] = related.R.SourceJobCandles[ln-1]
}
related.R.SourceJobCandles = related.R.SourceJobCandles[:ln-1]
break
}
return nil
}
// SetExchangeName of the candle to the related item.
// Sets o.R.ExchangeName to related.
// Adds o to related.R.ExchangeNameCandle.

View File

@@ -494,6 +494,108 @@ func testCandlesInsertWhitelist(t *testing.T) {
}
}
func testCandleToOneDatahistoryjobUsingValidationJob(t *testing.T) {
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
var local Candle
var foreign Datahistoryjob
seed := randomize.NewSeed()
if err := randomize.Struct(seed, &local, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
if err := randomize.Struct(seed, &foreign, datahistoryjobDBTypes, false, datahistoryjobColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
}
if err := foreign.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
queries.Assign(&local.ValidationJobID, foreign.ID)
if err := local.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
check, err := local.ValidationJob().One(ctx, tx)
if err != nil {
t.Fatal(err)
}
if !queries.Equal(check.ID, foreign.ID) {
t.Errorf("want: %v, got %v", foreign.ID, check.ID)
}
slice := CandleSlice{&local}
if err = local.L.LoadValidationJob(ctx, tx, false, (*[]*Candle)(&slice), nil); err != nil {
t.Fatal(err)
}
if local.R.ValidationJob == nil {
t.Error("struct should have been eager loaded")
}
local.R.ValidationJob = nil
if err = local.L.LoadValidationJob(ctx, tx, true, &local, nil); err != nil {
t.Fatal(err)
}
if local.R.ValidationJob == nil {
t.Error("struct should have been eager loaded")
}
}
func testCandleToOneDatahistoryjobUsingSourceJob(t *testing.T) {
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
var local Candle
var foreign Datahistoryjob
seed := randomize.NewSeed()
if err := randomize.Struct(seed, &local, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
if err := randomize.Struct(seed, &foreign, datahistoryjobDBTypes, false, datahistoryjobColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Datahistoryjob struct: %s", err)
}
if err := foreign.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
queries.Assign(&local.SourceJobID, foreign.ID)
if err := local.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
check, err := local.SourceJob().One(ctx, tx)
if err != nil {
t.Fatal(err)
}
if !queries.Equal(check.ID, foreign.ID) {
t.Errorf("want: %v, got %v", foreign.ID, check.ID)
}
slice := CandleSlice{&local}
if err = local.L.LoadSourceJob(ctx, tx, false, (*[]*Candle)(&slice), nil); err != nil {
t.Fatal(err)
}
if local.R.SourceJob == nil {
t.Error("struct should have been eager loaded")
}
local.R.SourceJob = nil
if err = local.L.LoadSourceJob(ctx, tx, true, &local, nil); err != nil {
t.Fatal(err)
}
if local.R.SourceJob == nil {
t.Error("struct should have been eager loaded")
}
}
func testCandleToOneExchangeUsingExchangeName(t *testing.T) {
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
@@ -545,6 +647,224 @@ func testCandleToOneExchangeUsingExchangeName(t *testing.T) {
}
}
func testCandleToOneSetOpDatahistoryjobUsingValidationJob(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 Datahistoryjob
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, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
t.Fatal(err)
}
if err = randomize.Struct(seed, &c, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); 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 []*Datahistoryjob{&b, &c} {
err = a.SetValidationJob(ctx, tx, i != 0, x)
if err != nil {
t.Fatal(err)
}
if a.R.ValidationJob != x {
t.Error("relationship struct not set to correct value")
}
if x.R.ValidationJobCandles[0] != &a {
t.Error("failed to append to foreign relationship struct")
}
if !queries.Equal(a.ValidationJobID, x.ID) {
t.Error("foreign key was wrong value", a.ValidationJobID)
}
zero := reflect.Zero(reflect.TypeOf(a.ValidationJobID))
reflect.Indirect(reflect.ValueOf(&a.ValidationJobID)).Set(zero)
if err = a.Reload(ctx, tx); err != nil {
t.Fatal("failed to reload", err)
}
if !queries.Equal(a.ValidationJobID, x.ID) {
t.Error("foreign key was wrong value", a.ValidationJobID, x.ID)
}
}
}
func testCandleToOneRemoveOpDatahistoryjobUsingValidationJob(t *testing.T) {
var err error
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
var a Candle
var b Datahistoryjob
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, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
t.Fatal(err)
}
if err = a.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
if err = a.SetValidationJob(ctx, tx, true, &b); err != nil {
t.Fatal(err)
}
if err = a.RemoveValidationJob(ctx, tx, &b); err != nil {
t.Error("failed to remove relationship")
}
count, err := a.ValidationJob().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 0 {
t.Error("want no relationships remaining")
}
if a.R.ValidationJob != nil {
t.Error("R struct entry should be nil")
}
if !queries.IsValuerNil(a.ValidationJobID) {
t.Error("foreign key value should be nil")
}
if len(b.R.ValidationJobCandles) != 0 {
t.Error("failed to remove a from b's relationships")
}
}
func testCandleToOneSetOpDatahistoryjobUsingSourceJob(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 Datahistoryjob
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, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
t.Fatal(err)
}
if err = randomize.Struct(seed, &c, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); 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 []*Datahistoryjob{&b, &c} {
err = a.SetSourceJob(ctx, tx, i != 0, x)
if err != nil {
t.Fatal(err)
}
if a.R.SourceJob != x {
t.Error("relationship struct not set to correct value")
}
if x.R.SourceJobCandles[0] != &a {
t.Error("failed to append to foreign relationship struct")
}
if !queries.Equal(a.SourceJobID, x.ID) {
t.Error("foreign key was wrong value", a.SourceJobID)
}
zero := reflect.Zero(reflect.TypeOf(a.SourceJobID))
reflect.Indirect(reflect.ValueOf(&a.SourceJobID)).Set(zero)
if err = a.Reload(ctx, tx); err != nil {
t.Fatal("failed to reload", err)
}
if !queries.Equal(a.SourceJobID, x.ID) {
t.Error("foreign key was wrong value", a.SourceJobID, x.ID)
}
}
}
func testCandleToOneRemoveOpDatahistoryjobUsingSourceJob(t *testing.T) {
var err error
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
var a Candle
var b Datahistoryjob
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, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
t.Fatal(err)
}
if err = a.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
if err = a.SetSourceJob(ctx, tx, true, &b); err != nil {
t.Fatal(err)
}
if err = a.RemoveSourceJob(ctx, tx, &b); err != nil {
t.Error("failed to remove relationship")
}
count, err := a.SourceJob().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 0 {
t.Error("want no relationships remaining")
}
if a.R.SourceJob != nil {
t.Error("R struct entry should be nil")
}
if !queries.IsValuerNil(a.SourceJobID) {
t.Error("foreign key value should be nil")
}
if len(b.R.SourceJobCandles) != 0 {
t.Error("failed to remove a from b's relationships")
}
}
func testCandleToOneSetOpExchangeUsingExchangeName(t *testing.T) {
var err error
@@ -677,7 +997,7 @@ func testCandlesSelect(t *testing.T) {
}
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`}
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`, `SourceJobID`: `TEXT`, `ValidationJobID`: `TEXT`, `ValidationIssues`: `TEXT`}
_ = bytes.MinRead
)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -55,29 +55,6 @@ var DatahistoryjobresultColumns = struct {
// Generated where
type whereHelpernull_String struct{ field string }
func (w whereHelpernull_String) EQ(x null.String) qm.QueryMod {
return qmhelper.WhereNullEQ(w.field, false, x)
}
func (w whereHelpernull_String) NEQ(x null.String) qm.QueryMod {
return qmhelper.WhereNullEQ(w.field, true, x)
}
func (w whereHelpernull_String) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) }
func (w whereHelpernull_String) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) }
func (w whereHelpernull_String) LT(x null.String) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.LT, x)
}
func (w whereHelpernull_String) LTE(x null.String) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.LTE, x)
}
func (w whereHelpernull_String) GT(x null.String) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.GT, x)
}
func (w whereHelpernull_String) GTE(x null.String) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.GTE, x)
}
var DatahistoryjobresultWhere = struct {
ID whereHelperstring
JobID whereHelperstring

View File

@@ -49,23 +49,26 @@ var ExchangeWhere = struct {
// ExchangeRels is where relationship names are stored.
var ExchangeRels = struct {
ExchangeNameCandle string
ExchangeNameTrade string
ExchangeNameDatahistoryjobs string
ExchangeNameWithdrawalHistories string
ExchangeNameCandle string
ExchangeNameTrade string
ExchangeNameDatahistoryjobs string
SecondaryExchangeDatahistoryjobs string
ExchangeNameWithdrawalHistories string
}{
ExchangeNameCandle: "ExchangeNameCandle",
ExchangeNameTrade: "ExchangeNameTrade",
ExchangeNameDatahistoryjobs: "ExchangeNameDatahistoryjobs",
ExchangeNameWithdrawalHistories: "ExchangeNameWithdrawalHistories",
ExchangeNameCandle: "ExchangeNameCandle",
ExchangeNameTrade: "ExchangeNameTrade",
ExchangeNameDatahistoryjobs: "ExchangeNameDatahistoryjobs",
SecondaryExchangeDatahistoryjobs: "SecondaryExchangeDatahistoryjobs",
ExchangeNameWithdrawalHistories: "ExchangeNameWithdrawalHistories",
}
// exchangeR is where relationships are stored.
type exchangeR struct {
ExchangeNameCandle *Candle
ExchangeNameTrade *Trade
ExchangeNameDatahistoryjobs DatahistoryjobSlice
ExchangeNameWithdrawalHistories WithdrawalHistorySlice
ExchangeNameCandle *Candle
ExchangeNameTrade *Trade
ExchangeNameDatahistoryjobs DatahistoryjobSlice
SecondaryExchangeDatahistoryjobs DatahistoryjobSlice
ExchangeNameWithdrawalHistories WithdrawalHistorySlice
}
// NewStruct creates a new relationship struct
@@ -407,6 +410,27 @@ func (o *Exchange) ExchangeNameDatahistoryjobs(mods ...qm.QueryMod) datahistoryj
return query
}
// SecondaryExchangeDatahistoryjobs retrieves all the datahistoryjob's Datahistoryjobs with an executor via secondary_exchange_id column.
func (o *Exchange) SecondaryExchangeDatahistoryjobs(mods ...qm.QueryMod) datahistoryjobQuery {
var queryMods []qm.QueryMod
if len(mods) != 0 {
queryMods = append(queryMods, mods...)
}
queryMods = append(queryMods,
qm.Where("\"datahistoryjob\".\"secondary_exchange_id\"=?", o.ID),
)
query := Datahistoryjobs(queryMods...)
queries.SetFrom(query.Query, "\"datahistoryjob\"")
if len(queries.GetSelect(query.Query)) == 0 {
queries.SetSelect(query.Query, []string{"\"datahistoryjob\".*"})
}
return query
}
// ExchangeNameWithdrawalHistories retrieves all the withdrawal_history's WithdrawalHistories with an executor via exchange_name_id column.
func (o *Exchange) ExchangeNameWithdrawalHistories(mods ...qm.QueryMod) withdrawalHistoryQuery {
var queryMods []qm.QueryMod
@@ -719,6 +743,101 @@ func (exchangeL) LoadExchangeNameDatahistoryjobs(ctx context.Context, e boil.Con
return nil
}
// LoadSecondaryExchangeDatahistoryjobs 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 (exchangeL) LoadSecondaryExchangeDatahistoryjobs(ctx context.Context, e boil.ContextExecutor, singular bool, maybeExchange interface{}, mods queries.Applicator) error {
var slice []*Exchange
var object *Exchange
if singular {
object = maybeExchange.(*Exchange)
} else {
slice = *maybeExchange.(*[]*Exchange)
}
args := make([]interface{}, 0, 1)
if singular {
if object.R == nil {
object.R = &exchangeR{}
}
args = append(args, object.ID)
} else {
Outer:
for _, obj := range slice {
if obj.R == nil {
obj.R = &exchangeR{}
}
for _, a := range args {
if queries.Equal(a, obj.ID) {
continue Outer
}
}
args = append(args, obj.ID)
}
}
if len(args) == 0 {
return nil
}
query := NewQuery(qm.From(`datahistoryjob`), qm.WhereIn(`datahistoryjob.secondary_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 datahistoryjob")
}
var resultSlice []*Datahistoryjob
if err = queries.Bind(results, &resultSlice); err != nil {
return errors.Wrap(err, "failed to bind eager loaded slice datahistoryjob")
}
if err = results.Close(); err != nil {
return errors.Wrap(err, "failed to close results in eager load on datahistoryjob")
}
if err = results.Err(); err != nil {
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for datahistoryjob")
}
if len(datahistoryjobAfterSelectHooks) != 0 {
for _, obj := range resultSlice {
if err := obj.doAfterSelectHooks(ctx, e); err != nil {
return err
}
}
}
if singular {
object.R.SecondaryExchangeDatahistoryjobs = resultSlice
for _, foreign := range resultSlice {
if foreign.R == nil {
foreign.R = &datahistoryjobR{}
}
foreign.R.SecondaryExchange = object
}
return nil
}
for _, foreign := range resultSlice {
for _, local := range slice {
if queries.Equal(local.ID, foreign.SecondaryExchangeID) {
local.R.SecondaryExchangeDatahistoryjobs = append(local.R.SecondaryExchangeDatahistoryjobs, foreign)
if foreign.R == nil {
foreign.R = &datahistoryjobR{}
}
foreign.R.SecondaryExchange = local
break
}
}
}
return nil
}
// LoadExchangeNameWithdrawalHistories 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 (exchangeL) LoadExchangeNameWithdrawalHistories(ctx context.Context, e boil.ContextExecutor, singular bool, maybeExchange interface{}, mods queries.Applicator) error {
@@ -969,6 +1088,129 @@ func (o *Exchange) AddExchangeNameDatahistoryjobs(ctx context.Context, exec boil
return nil
}
// AddSecondaryExchangeDatahistoryjobs adds the given related objects to the existing relationships
// of the exchange, optionally inserting them as new records.
// Appends related to o.R.SecondaryExchangeDatahistoryjobs.
// Sets related.R.SecondaryExchange appropriately.
func (o *Exchange) AddSecondaryExchangeDatahistoryjobs(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*Datahistoryjob) error {
var err error
for _, rel := range related {
if insert {
queries.Assign(&rel.SecondaryExchangeID, o.ID)
if err = rel.Insert(ctx, exec, boil.Infer()); err != nil {
return errors.Wrap(err, "failed to insert into foreign table")
}
} else {
updateQuery := fmt.Sprintf(
"UPDATE \"datahistoryjob\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, []string{"secondary_exchange_id"}),
strmangle.WhereClause("\"", "\"", 0, datahistoryjobPrimaryKeyColumns),
)
values := []interface{}{o.ID, rel.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 foreign table")
}
queries.Assign(&rel.SecondaryExchangeID, o.ID)
}
}
if o.R == nil {
o.R = &exchangeR{
SecondaryExchangeDatahistoryjobs: related,
}
} else {
o.R.SecondaryExchangeDatahistoryjobs = append(o.R.SecondaryExchangeDatahistoryjobs, related...)
}
for _, rel := range related {
if rel.R == nil {
rel.R = &datahistoryjobR{
SecondaryExchange: o,
}
} else {
rel.R.SecondaryExchange = o
}
}
return nil
}
// SetSecondaryExchangeDatahistoryjobs removes all previously related items of the
// exchange replacing them completely with the passed
// in related items, optionally inserting them as new records.
// Sets o.R.SecondaryExchange's SecondaryExchangeDatahistoryjobs accordingly.
// Replaces o.R.SecondaryExchangeDatahistoryjobs with related.
// Sets related.R.SecondaryExchange's SecondaryExchangeDatahistoryjobs accordingly.
func (o *Exchange) SetSecondaryExchangeDatahistoryjobs(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*Datahistoryjob) error {
query := "update \"datahistoryjob\" set \"secondary_exchange_id\" = null where \"secondary_exchange_id\" = ?"
values := []interface{}{o.ID}
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, query)
fmt.Fprintln(boil.DebugWriter, values)
}
_, err := exec.ExecContext(ctx, query, values...)
if err != nil {
return errors.Wrap(err, "failed to remove relationships before set")
}
if o.R != nil {
for _, rel := range o.R.SecondaryExchangeDatahistoryjobs {
queries.SetScanner(&rel.SecondaryExchangeID, nil)
if rel.R == nil {
continue
}
rel.R.SecondaryExchange = nil
}
o.R.SecondaryExchangeDatahistoryjobs = nil
}
return o.AddSecondaryExchangeDatahistoryjobs(ctx, exec, insert, related...)
}
// RemoveSecondaryExchangeDatahistoryjobs relationships from objects passed in.
// Removes related items from R.SecondaryExchangeDatahistoryjobs (uses pointer comparison, removal does not keep order)
// Sets related.R.SecondaryExchange.
func (o *Exchange) RemoveSecondaryExchangeDatahistoryjobs(ctx context.Context, exec boil.ContextExecutor, related ...*Datahistoryjob) error {
var err error
for _, rel := range related {
queries.SetScanner(&rel.SecondaryExchangeID, nil)
if rel.R != nil {
rel.R.SecondaryExchange = nil
}
if _, err = rel.Update(ctx, exec, boil.Whitelist("secondary_exchange_id")); err != nil {
return err
}
}
if o.R == nil {
return nil
}
for _, rel := range related {
for i, ri := range o.R.SecondaryExchangeDatahistoryjobs {
if rel != ri {
continue
}
ln := len(o.R.SecondaryExchangeDatahistoryjobs)
if ln > 1 && i < ln-1 {
o.R.SecondaryExchangeDatahistoryjobs[i] = o.R.SecondaryExchangeDatahistoryjobs[ln-1]
}
o.R.SecondaryExchangeDatahistoryjobs = o.R.SecondaryExchangeDatahistoryjobs[:ln-1]
break
}
}
return nil
}
// AddExchangeNameWithdrawalHistories adds the given related objects to the existing relationships
// of the exchange, optionally inserting them as new records.
// Appends related to o.R.ExchangeNameWithdrawalHistories.

View File

@@ -797,6 +797,83 @@ func testExchangeToManyExchangeNameDatahistoryjobs(t *testing.T) {
}
}
func testExchangeToManySecondaryExchangeDatahistoryjobs(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 Datahistoryjob
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, datahistoryjobDBTypes, false, datahistoryjobColumnsWithDefault...); err != nil {
t.Fatal(err)
}
if err = randomize.Struct(seed, &c, datahistoryjobDBTypes, false, datahistoryjobColumnsWithDefault...); err != nil {
t.Fatal(err)
}
queries.Assign(&b.SecondaryExchangeID, a.ID)
queries.Assign(&c.SecondaryExchangeID, 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.SecondaryExchangeDatahistoryjobs().All(ctx, tx)
if err != nil {
t.Fatal(err)
}
bFound, cFound := false, false
for _, v := range check {
if queries.Equal(v.SecondaryExchangeID, b.SecondaryExchangeID) {
bFound = true
}
if queries.Equal(v.SecondaryExchangeID, c.SecondaryExchangeID) {
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.LoadSecondaryExchangeDatahistoryjobs(ctx, tx, false, (*[]*Exchange)(&slice), nil); err != nil {
t.Fatal(err)
}
if got := len(a.R.SecondaryExchangeDatahistoryjobs); got != 2 {
t.Error("number of eager loaded records wrong, got:", got)
}
a.R.SecondaryExchangeDatahistoryjobs = nil
if err = a.L.LoadSecondaryExchangeDatahistoryjobs(ctx, tx, true, &a, nil); err != nil {
t.Fatal(err)
}
if got := len(a.R.SecondaryExchangeDatahistoryjobs); got != 2 {
t.Error("number of eager loaded records wrong, got:", got)
}
if t.Failed() {
t.Logf("%#v", check)
}
}
func testExchangeToManyExchangeNameWithdrawalHistories(t *testing.T) {
var err error
ctx := context.Background()
@@ -950,6 +1027,257 @@ func testExchangeToManyAddOpExchangeNameDatahistoryjobs(t *testing.T) {
}
}
}
func testExchangeToManyAddOpSecondaryExchangeDatahistoryjobs(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 Datahistoryjob
seed := randomize.NewSeed()
if err = randomize.Struct(seed, &a, exchangeDBTypes, false, strmangle.SetComplement(exchangePrimaryKeyColumns, exchangeColumnsWithoutDefault)...); err != nil {
t.Fatal(err)
}
foreigners := []*Datahistoryjob{&b, &c, &d, &e}
for _, x := range foreigners {
if err = randomize.Struct(seed, x, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); 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 := [][]*Datahistoryjob{
{&b, &c},
{&d, &e},
}
for i, x := range foreignersSplitByInsertion {
err = a.AddSecondaryExchangeDatahistoryjobs(ctx, tx, i != 0, x...)
if err != nil {
t.Fatal(err)
}
first := x[0]
second := x[1]
if !queries.Equal(a.ID, first.SecondaryExchangeID) {
t.Error("foreign key was wrong value", a.ID, first.SecondaryExchangeID)
}
if !queries.Equal(a.ID, second.SecondaryExchangeID) {
t.Error("foreign key was wrong value", a.ID, second.SecondaryExchangeID)
}
if first.R.SecondaryExchange != &a {
t.Error("relationship was not added properly to the foreign slice")
}
if second.R.SecondaryExchange != &a {
t.Error("relationship was not added properly to the foreign slice")
}
if a.R.SecondaryExchangeDatahistoryjobs[i*2] != first {
t.Error("relationship struct slice not set to correct value")
}
if a.R.SecondaryExchangeDatahistoryjobs[i*2+1] != second {
t.Error("relationship struct slice not set to correct value")
}
count, err := a.SecondaryExchangeDatahistoryjobs().Count(ctx, tx)
if err != nil {
t.Fatal(err)
}
if want := int64((i + 1) * 2); count != want {
t.Error("want", want, "got", count)
}
}
}
func testExchangeToManySetOpSecondaryExchangeDatahistoryjobs(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 Datahistoryjob
seed := randomize.NewSeed()
if err = randomize.Struct(seed, &a, exchangeDBTypes, false, strmangle.SetComplement(exchangePrimaryKeyColumns, exchangeColumnsWithoutDefault)...); err != nil {
t.Fatal(err)
}
foreigners := []*Datahistoryjob{&b, &c, &d, &e}
for _, x := range foreigners {
if err = randomize.Struct(seed, x, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); 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)
}
err = a.SetSecondaryExchangeDatahistoryjobs(ctx, tx, false, &b, &c)
if err != nil {
t.Fatal(err)
}
count, err := a.SecondaryExchangeDatahistoryjobs().Count(ctx, tx)
if err != nil {
t.Fatal(err)
}
if count != 2 {
t.Error("count was wrong:", count)
}
err = a.SetSecondaryExchangeDatahistoryjobs(ctx, tx, true, &d, &e)
if err != nil {
t.Fatal(err)
}
count, err = a.SecondaryExchangeDatahistoryjobs().Count(ctx, tx)
if err != nil {
t.Fatal(err)
}
if count != 2 {
t.Error("count was wrong:", count)
}
if !queries.IsValuerNil(b.SecondaryExchangeID) {
t.Error("want b's foreign key value to be nil")
}
if !queries.IsValuerNil(c.SecondaryExchangeID) {
t.Error("want c's foreign key value to be nil")
}
if !queries.Equal(a.ID, d.SecondaryExchangeID) {
t.Error("foreign key was wrong value", a.ID, d.SecondaryExchangeID)
}
if !queries.Equal(a.ID, e.SecondaryExchangeID) {
t.Error("foreign key was wrong value", a.ID, e.SecondaryExchangeID)
}
if b.R.SecondaryExchange != nil {
t.Error("relationship was not removed properly from the foreign struct")
}
if c.R.SecondaryExchange != nil {
t.Error("relationship was not removed properly from the foreign struct")
}
if d.R.SecondaryExchange != &a {
t.Error("relationship was not added properly to the foreign struct")
}
if e.R.SecondaryExchange != &a {
t.Error("relationship was not added properly to the foreign struct")
}
if a.R.SecondaryExchangeDatahistoryjobs[0] != &d {
t.Error("relationship struct slice not set to correct value")
}
if a.R.SecondaryExchangeDatahistoryjobs[1] != &e {
t.Error("relationship struct slice not set to correct value")
}
}
func testExchangeToManyRemoveOpSecondaryExchangeDatahistoryjobs(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 Datahistoryjob
seed := randomize.NewSeed()
if err = randomize.Struct(seed, &a, exchangeDBTypes, false, strmangle.SetComplement(exchangePrimaryKeyColumns, exchangeColumnsWithoutDefault)...); err != nil {
t.Fatal(err)
}
foreigners := []*Datahistoryjob{&b, &c, &d, &e}
for _, x := range foreigners {
if err = randomize.Struct(seed, x, datahistoryjobDBTypes, false, strmangle.SetComplement(datahistoryjobPrimaryKeyColumns, datahistoryjobColumnsWithoutDefault)...); err != nil {
t.Fatal(err)
}
}
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
err = a.AddSecondaryExchangeDatahistoryjobs(ctx, tx, true, foreigners...)
if err != nil {
t.Fatal(err)
}
count, err := a.SecondaryExchangeDatahistoryjobs().Count(ctx, tx)
if err != nil {
t.Fatal(err)
}
if count != 4 {
t.Error("count was wrong:", count)
}
err = a.RemoveSecondaryExchangeDatahistoryjobs(ctx, tx, foreigners[:2]...)
if err != nil {
t.Fatal(err)
}
count, err = a.SecondaryExchangeDatahistoryjobs().Count(ctx, tx)
if err != nil {
t.Fatal(err)
}
if count != 2 {
t.Error("count was wrong:", count)
}
if !queries.IsValuerNil(b.SecondaryExchangeID) {
t.Error("want b's foreign key value to be nil")
}
if !queries.IsValuerNil(c.SecondaryExchangeID) {
t.Error("want c's foreign key value to be nil")
}
if b.R.SecondaryExchange != nil {
t.Error("relationship was not removed properly from the foreign struct")
}
if c.R.SecondaryExchange != nil {
t.Error("relationship was not removed properly from the foreign struct")
}
if d.R.SecondaryExchange != &a {
t.Error("relationship to a should have been preserved")
}
if e.R.SecondaryExchange != &a {
t.Error("relationship to a should have been preserved")
}
if len(a.R.SecondaryExchangeDatahistoryjobs) != 2 {
t.Error("should have preserved two relationships")
}
// Removal doesn't do a stable deletion for performance so we have to flip the order
if a.R.SecondaryExchangeDatahistoryjobs[1] != &d {
t.Error("relationship to d should have been preserved")
}
if a.R.SecondaryExchangeDatahistoryjobs[0] != &e {
t.Error("relationship to e should have been preserved")
}
}
func testExchangeToManyAddOpExchangeNameWithdrawalHistories(t *testing.T) {
var err error