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

@@ -4,27 +4,29 @@
package postgres
var TableNames = struct {
AuditEvent string
Candle string
Datahistoryjob string
Datahistoryjobresult string
Exchange 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",
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

@@ -19,53 +19,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 int64 `boil:"interval" json:"interval" toml:"interval" yaml:"interval"`
Timestamp time.Time `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 int64 `boil:"interval" json:"interval" toml:"interval" yaml:"interval"`
Timestamp time.Time `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
@@ -85,44 +95,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 whereHelperint64
Timestamp whereHelpertime_Time
Open whereHelperfloat64
High whereHelperfloat64
Low whereHelperfloat64
Close whereHelperfloat64
Volume whereHelperfloat64
Asset whereHelperstring
ID whereHelperstring
ExchangeNameID whereHelperstring
Base whereHelperstring
Quote whereHelperstring
Interval whereHelperint64
Timestamp whereHelpertime_Time
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: whereHelperint64{field: "\"candle\".\"interval\""},
Timestamp: whereHelpertime_Time{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: whereHelperint64{field: "\"candle\".\"interval\""},
Timestamp: whereHelpertime_Time{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
ExchangeName string
SourceJob string
ValidationJob string
}{
ExchangeName: "ExchangeName",
ExchangeName: "ExchangeName",
SourceJob: "SourceJob",
ValidationJob: "ValidationJob",
}
// candleR is where relationships are stored.
type candleR struct {
ExchangeName *Exchange
ExchangeName *Exchange
SourceJob *Datahistoryjob
ValidationJob *Datahistoryjob
}
// NewStruct creates a new relationship struct
@@ -134,8 +179,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{"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{"exchange_name_id", "base", "quote", "interval", "timestamp", "open", "high", "low", "close", "volume", "asset", "source_job_id", "validation_job_id", "validation_issues"}
candleColumnsWithDefault = []string{"id"}
candlePrimaryKeyColumns = []string{"id"}
)
@@ -429,6 +474,34 @@ func (o *Candle) ExchangeName(mods ...qm.QueryMod) exchangeQuery {
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
}
// 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
}
// 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 {
@@ -530,6 +603,216 @@ func (candleL) LoadExchangeName(ctx context.Context, e boil.ContextExecutor, sin
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
}
// 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
}
// SetExchangeName of the candle to the related item.
// Sets o.R.ExchangeName to related.
// Adds o to related.R.ExchangeNameCandles.
@@ -577,6 +860,162 @@ func (o *Candle) SetExchangeName(ctx context.Context, exec boil.ContextExecutor,
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("\"", "\"", 1, []string{"source_job_id"}),
strmangle.WhereClause("\"", "\"", 2, 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
}
// 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("\"", "\"", 1, []string{"validation_job_id"}),
strmangle.WhereClause("\"", "\"", 2, 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
}
// Candles retrieves all the records using an executor.
func Candles(mods ...qm.QueryMod) candleQuery {
mods = append(mods, qm.From("\"candle\""))

View File

@@ -545,6 +545,108 @@ func testCandleToOneExchangeUsingExchangeName(t *testing.T) {
}
}
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 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 testCandleToOneSetOpExchangeUsingExchangeName(t *testing.T) {
var err error
@@ -602,6 +704,223 @@ func testCandleToOneSetOpExchangeUsingExchangeName(t *testing.T) {
}
}
}
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 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 testCandlesReload(t *testing.T) {
t.Parallel()
@@ -677,7 +996,7 @@ func testCandlesSelect(t *testing.T) {
}
var (
candleDBTypes = map[string]string{`ID`: `uuid`, `ExchangeNameID`: `uuid`, `Base`: `character varying`, `Quote`: `character varying`, `Interval`: `bigint`, `Timestamp`: `timestamp with time zone`, `Open`: `double precision`, `High`: `double precision`, `Low`: `double precision`, `Close`: `double precision`, `Volume`: `double precision`, `Asset`: `character varying`}
candleDBTypes = map[string]string{`ID`: `uuid`, `ExchangeNameID`: `uuid`, `Base`: `character varying`, `Quote`: `character varying`, `Interval`: `bigint`, `Timestamp`: `timestamp with time zone`, `Open`: `double precision`, `High`: `double precision`, `Low`: `double precision`, `Close`: `double precision`, `Volume`: `double precision`, `Asset`: `character varying`, `SourceJobID`: `uuid`, `ValidationJobID`: `uuid`, `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

@@ -56,29 +56,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

@@ -50,23 +50,26 @@ var ExchangeWhere = struct {
// ExchangeRels is where relationship names are stored.
var ExchangeRels = struct {
ExchangeNameCandles string
ExchangeNameDatahistoryjobs string
ExchangeNameTrades string
ExchangeNameWithdrawalHistories string
ExchangeNameCandles string
ExchangeNameDatahistoryjobs string
SecondaryExchangeDatahistoryjobs string
ExchangeNameTrades string
ExchangeNameWithdrawalHistories string
}{
ExchangeNameCandles: "ExchangeNameCandles",
ExchangeNameDatahistoryjobs: "ExchangeNameDatahistoryjobs",
ExchangeNameTrades: "ExchangeNameTrades",
ExchangeNameWithdrawalHistories: "ExchangeNameWithdrawalHistories",
ExchangeNameCandles: "ExchangeNameCandles",
ExchangeNameDatahistoryjobs: "ExchangeNameDatahistoryjobs",
SecondaryExchangeDatahistoryjobs: "SecondaryExchangeDatahistoryjobs",
ExchangeNameTrades: "ExchangeNameTrades",
ExchangeNameWithdrawalHistories: "ExchangeNameWithdrawalHistories",
}
// exchangeR is where relationships are stored.
type exchangeR struct {
ExchangeNameCandles CandleSlice
ExchangeNameDatahistoryjobs DatahistoryjobSlice
ExchangeNameTrades TradeSlice
ExchangeNameWithdrawalHistories WithdrawalHistorySlice
ExchangeNameCandles CandleSlice
ExchangeNameDatahistoryjobs DatahistoryjobSlice
SecondaryExchangeDatahistoryjobs DatahistoryjobSlice
ExchangeNameTrades TradeSlice
ExchangeNameWithdrawalHistories WithdrawalHistorySlice
}
// NewStruct creates a new relationship struct
@@ -401,6 +404,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
}
// ExchangeNameTrades retrieves all the trade's Trades with an executor via exchange_name_id column.
func (o *Exchange) ExchangeNameTrades(mods ...qm.QueryMod) tradeQuery {
var queryMods []qm.QueryMod
@@ -633,6 +657,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
}
// LoadExchangeNameTrades 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) LoadExchangeNameTrades(ctx context.Context, e boil.ContextExecutor, singular bool, maybeExchange interface{}, mods queries.Applicator) error {
@@ -929,6 +1048,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("\"", "\"", 1, []string{"secondary_exchange_id"}),
strmangle.WhereClause("\"", "\"", 2, 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\" = $1"
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
}
// AddExchangeNameTrades adds the given related objects to the existing relationships
// of the exchange, optionally inserting them as new records.
// Appends related to o.R.ExchangeNameTrades.

View File

@@ -650,6 +650,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 testExchangeToManyExchangeNameTrades(t *testing.T) {
var err error
ctx := context.Background()
@@ -956,6 +1033,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 testExchangeToManyAddOpExchangeNameTrades(t *testing.T) {
var err error