mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-23 07:26:47 +00:00
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:
@@ -0,0 +1,9 @@
|
||||
-- +goose Up
|
||||
CREATE TABLE datahistoryjobrelations
|
||||
(
|
||||
prerequisite_job_id uuid not null REFERENCES datahistoryjob(id),
|
||||
job_id uuid not null REFERENCES datahistoryjob(id),
|
||||
PRIMARY KEY (prerequisite_job_id, job_id)
|
||||
);
|
||||
-- +goose Down
|
||||
DROP TABLE datahistoryjobrelations;
|
||||
@@ -0,0 +1,11 @@
|
||||
-- +goose Up
|
||||
CREATE TABLE datahistoryjobrelations
|
||||
(
|
||||
prerequisite_job_id text not null,
|
||||
job_id text not null,
|
||||
PRIMARY KEY (prerequisite_job_id, job_id),
|
||||
FOREIGN KEY (prerequisite_job_id) REFERENCES datahistoryjob(id) ON DELETE RESTRICT,
|
||||
FOREIGN KEY (job_id) REFERENCES datahistoryjob(id) ON DELETE RESTRICT
|
||||
);
|
||||
-- +goose Down
|
||||
DROP TABLE datahistoryjobrelations;
|
||||
@@ -0,0 +1,19 @@
|
||||
-- +goose Up
|
||||
ALTER TABLE datahistoryjob
|
||||
ADD conversion_interval DOUBLE PRECISION,
|
||||
ADD overwrite_data boolean,
|
||||
ADD decimal_place_comparison INTEGER,
|
||||
ADD secondary_exchange_id uuid REFERENCES exchange(id),
|
||||
ADD issue_tolerance_percentage DOUBLE PRECISION,
|
||||
ADD replace_on_issue boolean;
|
||||
|
||||
-- +goose Down
|
||||
ALTER TABLE datahistoryjob
|
||||
DROP replace_on_issue,
|
||||
DROP issue_tolerance_percentage,
|
||||
DROP CONSTRAINT datahistoryjob_secondary_exchange_id_fkey,
|
||||
DROP secondary_exchange_id,
|
||||
DROP decimal_place_comparison,
|
||||
DROP overwrite_data,
|
||||
DROP conversion_interval;
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
-- +goose Up
|
||||
ALTER TABLE datahistoryjob
|
||||
ADD conversion_interval real;
|
||||
ALTER TABLE datahistoryjob
|
||||
ADD overwrite_data integer;
|
||||
ALTER TABLE datahistoryjob
|
||||
ADD decimal_place_comparison integer;
|
||||
ALTER TABLE datahistoryjob
|
||||
ADD secondary_exchange_id text REFERENCES exchange(id) ON DELETE RESTRICT;
|
||||
ALTER TABLE datahistoryjob
|
||||
ADD issue_tolerance_percentage real;
|
||||
ALTER TABLE datahistoryjob
|
||||
ADD replace_on_issue integer;
|
||||
|
||||
-- +goose Down
|
||||
ALTER TABLE datahistoryjob
|
||||
DROP replace_on_issue;
|
||||
ALTER TABLE datahistoryjob
|
||||
DROP issue_tolerance_percentage;
|
||||
ALTER TABLE datahistoryjob
|
||||
DROP secondary_exchange_id;
|
||||
ALTER TABLE datahistoryjob
|
||||
DROP decimal_place_comparison;
|
||||
ALTER TABLE datahistoryjob
|
||||
DROP overwrite_data;
|
||||
ALTER TABLE datahistoryjob
|
||||
DROP conversion_interval;
|
||||
@@ -0,0 +1,12 @@
|
||||
-- +goose Up
|
||||
ALTER TABLE candle
|
||||
ADD source_job_id uuid references datahistoryjob(id),
|
||||
ADD validation_job_id uuid REFERENCES datahistoryjob(id),
|
||||
ADD validation_issues TEXT;
|
||||
-- +goose Down
|
||||
ALTER TABLE candle
|
||||
DROP validation_issues,
|
||||
DROP CONSTRAINT candle_validation_job_id_fkey,
|
||||
DROP validation_job_id,
|
||||
DROP CONSTRAINT candle_source_job_id_fkey,
|
||||
DROP source_job_id;
|
||||
@@ -0,0 +1,15 @@
|
||||
-- +goose Up
|
||||
ALTER TABLE candle
|
||||
ADD source_job_id TEXT REFERENCES datahistoryjob(id);
|
||||
ALTER TABLE candle
|
||||
ADD validation_job_id TEXT REFERENCES datahistoryjob(id);
|
||||
ALTER TABLE candle
|
||||
ADD validation_issues TEXT;
|
||||
-- +goose Down
|
||||
ALTER TABLE candle
|
||||
DROP validation_issues;
|
||||
ALTER TABLE candle
|
||||
DROP validation_job_id;
|
||||
ALTER TABLE candle
|
||||
DROP source_job_id;
|
||||
|
||||
@@ -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",
|
||||
}
|
||||
|
||||
@@ -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\""))
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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",
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/sqlboiler/boil"
|
||||
"github.com/thrasher-corp/sqlboiler/queries/qm"
|
||||
"github.com/volatiletech/null"
|
||||
)
|
||||
|
||||
// Series returns candle data
|
||||
@@ -34,6 +35,7 @@ func Series(exchangeName, base, quote string, interval int64, asset string, star
|
||||
qm.Where("quote = ?", strings.ToUpper(quote)),
|
||||
qm.Where("interval = ?", interval),
|
||||
qm.Where("asset = ?", strings.ToLower(asset)),
|
||||
qm.OrderBy("timestamp"),
|
||||
}
|
||||
|
||||
exchangeUUID, errS := exchange.UUIDByName(exchangeName)
|
||||
@@ -53,12 +55,15 @@ func Series(exchangeName, base, quote string, interval int64, asset string, star
|
||||
return out, errT
|
||||
}
|
||||
out.Candles = append(out.Candles, Candle{
|
||||
Timestamp: t,
|
||||
Open: retCandle[x].Open,
|
||||
High: retCandle[x].High,
|
||||
Low: retCandle[x].Low,
|
||||
Close: retCandle[x].Close,
|
||||
Volume: retCandle[x].Volume,
|
||||
Timestamp: t,
|
||||
Open: retCandle[x].Open,
|
||||
High: retCandle[x].High,
|
||||
Low: retCandle[x].Low,
|
||||
Close: retCandle[x].Close,
|
||||
Volume: retCandle[x].Volume,
|
||||
SourceJobID: retCandle[x].SourceJobID.String,
|
||||
ValidationJobID: retCandle[x].ValidationJobID.String,
|
||||
ValidationIssues: retCandle[x].ValidationIssues.String,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
@@ -70,12 +75,15 @@ func Series(exchangeName, base, quote string, interval int64, asset string, star
|
||||
|
||||
for x := range retCandle {
|
||||
out.Candles = append(out.Candles, Candle{
|
||||
Timestamp: retCandle[x].Timestamp,
|
||||
Open: retCandle[x].Open,
|
||||
High: retCandle[x].High,
|
||||
Low: retCandle[x].Low,
|
||||
Close: retCandle[x].Close,
|
||||
Volume: retCandle[x].Volume,
|
||||
Timestamp: retCandle[x].Timestamp,
|
||||
Open: retCandle[x].Open,
|
||||
High: retCandle[x].High,
|
||||
Low: retCandle[x].Low,
|
||||
Close: retCandle[x].Close,
|
||||
Volume: retCandle[x].Volume,
|
||||
SourceJobID: retCandle[x].SourceJobID.String,
|
||||
ValidationJobID: retCandle[x].ValidationJobID.String,
|
||||
ValidationIssues: retCandle[x].ValidationIssues.String,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -229,6 +237,9 @@ func insertSQLite(ctx context.Context, tx *sql.Tx, in *Item) (uint64, error) {
|
||||
return 0, err
|
||||
}
|
||||
tempCandle.ID = tempUUID.String()
|
||||
tempCandle.ValidationJobID = null.String{String: in.Candles[x].ValidationJobID, Valid: in.Candles[x].ValidationJobID != ""}
|
||||
tempCandle.ValidationIssues = null.String{String: in.Candles[x].ValidationIssues, Valid: in.Candles[x].ValidationIssues != ""}
|
||||
tempCandle.SourceJobID = null.String{String: in.Candles[x].SourceJobID, Valid: in.Candles[x].SourceJobID != ""}
|
||||
err = tempCandle.Insert(ctx, tx, boil.Infer())
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -256,6 +267,9 @@ func insertPostgresSQL(ctx context.Context, tx *sql.Tx, in *Item) (uint64, error
|
||||
Close: in.Candles[x].Close,
|
||||
Volume: in.Candles[x].Volume,
|
||||
}
|
||||
tempCandle.ValidationJobID = null.String{String: in.Candles[x].ValidationJobID, Valid: in.Candles[x].ValidationJobID != ""}
|
||||
tempCandle.ValidationIssues = null.String{String: in.Candles[x].ValidationIssues, Valid: in.Candles[x].ValidationIssues != ""}
|
||||
tempCandle.SourceJobID = null.String{String: in.Candles[x].SourceJobID, Valid: in.Candles[x].SourceJobID != ""}
|
||||
err := tempCandle.Upsert(ctx, tx, true, []string{"timestamp", "exchange_name_id", "base", "quote", "interval", "asset"}, boil.Infer(), boil.Infer())
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
||||
@@ -298,12 +298,13 @@ func genOHCLVData() (out Item, err error) {
|
||||
start := time.Date(2019, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
for x := 0; x < 365; x++ {
|
||||
out.Candles = append(out.Candles, Candle{
|
||||
Timestamp: start.Add(time.Hour * 24 * time.Duration(x)),
|
||||
Open: 1000,
|
||||
High: 1000,
|
||||
Low: 1000,
|
||||
Close: 1000,
|
||||
Volume: 1000,
|
||||
Timestamp: start.Add(time.Hour * 24 * time.Duration(x)),
|
||||
Open: 1000,
|
||||
High: 1000,
|
||||
Low: 1000,
|
||||
Close: 1000,
|
||||
Volume: 1000,
|
||||
ValidationIssues: "hello world!",
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -25,10 +25,13 @@ type Item struct {
|
||||
|
||||
// Candle holds each interval
|
||||
type Candle struct {
|
||||
Timestamp time.Time
|
||||
Open float64
|
||||
High float64
|
||||
Low float64
|
||||
Close float64
|
||||
Volume float64
|
||||
Timestamp time.Time
|
||||
Open float64
|
||||
High float64
|
||||
Low float64
|
||||
Close float64
|
||||
Volume float64
|
||||
SourceJobID string
|
||||
ValidationJobID string
|
||||
ValidationIssues string
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,7 @@
|
||||
package datahistoryjob
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
@@ -172,8 +173,8 @@ func TestDataHistoryJob(t *testing.T) {
|
||||
}
|
||||
|
||||
results, err := db.GetAllIncompleteJobsAndResults()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Errorf("received %v expected %v", err, nil)
|
||||
}
|
||||
if len(results) != 19 {
|
||||
t.Errorf("expected 19, received %v", len(results))
|
||||
@@ -188,24 +189,112 @@ func TestDataHistoryJob(t *testing.T) {
|
||||
}
|
||||
|
||||
results, err = db.GetJobsBetween(time.Now().Add(-time.Hour), time.Now())
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Errorf("received %v expected %v", err, nil)
|
||||
}
|
||||
if len(results) != 20 {
|
||||
t.Errorf("expected 20, received %v", len(results))
|
||||
}
|
||||
|
||||
jerb, err = db.GetJobAndAllResults(jerberoos[0].Nickname)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
jerb, err = db.GetJobAndAllResults(results[0].Nickname)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Errorf("received %v expected %v", err, nil)
|
||||
}
|
||||
if !strings.EqualFold(jerb.Nickname, jerberoos[0].Nickname) {
|
||||
if !strings.EqualFold(jerb.Nickname, results[0].Nickname) {
|
||||
t.Errorf("expected %v, received %v", jerb.Nickname, jerberoos[0].Nickname)
|
||||
}
|
||||
|
||||
err = db.SetRelationshipByID(results[0].ID, results[1].ID, 1337)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Errorf("received %v expected %v", err, nil)
|
||||
}
|
||||
|
||||
jerb, err = db.GetByID(results[1].ID)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Errorf("received %v expected %v", err, nil)
|
||||
}
|
||||
if jerb.Status != 1337 {
|
||||
t.Error("expected 1337")
|
||||
}
|
||||
|
||||
rel, err := db.GetRelatedUpcomingJobs(results[0].Nickname)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Errorf("received %v expected %v", err, nil)
|
||||
}
|
||||
if len(rel) != 1 {
|
||||
t.Fatal("expected 1")
|
||||
}
|
||||
if rel[0].ID != results[1].ID {
|
||||
t.Errorf("received %v expected %v", rel[0].ID, results[1].ID)
|
||||
}
|
||||
|
||||
err = db.SetRelationshipByID(results[0].ID, results[2].ID, 1337)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Errorf("received %v expected %v", err, nil)
|
||||
}
|
||||
rel, err = db.GetRelatedUpcomingJobs(results[0].Nickname)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Errorf("received %v expected %v", err, nil)
|
||||
}
|
||||
if len(rel) != 2 {
|
||||
t.Fatal("expected 2")
|
||||
}
|
||||
for i := range rel {
|
||||
if rel[i].ID != results[1].ID && rel[i].ID != results[2].ID {
|
||||
t.Errorf("received %v expected %v or %v", rel[i].ID, results[1].ID, results[2].ID)
|
||||
}
|
||||
}
|
||||
|
||||
jerb, err = db.GetPrerequisiteJob(results[1].Nickname)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Errorf("received %v expected %v", err, nil)
|
||||
}
|
||||
if jerb.ID != results[0].ID {
|
||||
t.Errorf("received %v expected %v", jerb.ID, results[0].ID)
|
||||
}
|
||||
|
||||
jerb, err = db.GetPrerequisiteJob(results[2].Nickname)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Errorf("received %v expected %v", err, nil)
|
||||
}
|
||||
if jerb.ID != results[0].ID {
|
||||
t.Errorf("received %v expected %v", jerb.ID, results[0].ID)
|
||||
}
|
||||
|
||||
err = db.SetRelationshipByNickname(results[4].Nickname, results[2].Nickname, 0)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Errorf("received %v expected %v", err, nil)
|
||||
}
|
||||
err = db.SetRelationshipByNickname(results[2].Nickname, results[2].Nickname, 0)
|
||||
if !errors.Is(err, errCannotSetSamePrerequisite) {
|
||||
t.Errorf("received %v expected %v", err, errCannotSetSamePrerequisite)
|
||||
}
|
||||
err = db.SetRelationshipByNickname(results[3].Nickname, results[2].Nickname, 0)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Errorf("received %v expected %v", err, nil)
|
||||
}
|
||||
|
||||
// ensure only one prerequisite can be associated at once
|
||||
// after setting the prerequisite twice
|
||||
rel, err = db.GetRelatedUpcomingJobs(results[4].Nickname)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Errorf("received %v expected %v", err, nil)
|
||||
}
|
||||
if len(rel) != 0 {
|
||||
t.Errorf("received %v expected %v", len(rel), 0)
|
||||
}
|
||||
|
||||
rel, err = db.GetRelatedUpcomingJobs(results[3].Nickname)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Errorf("received %v expected %v", err, nil)
|
||||
}
|
||||
if len(rel) != 1 {
|
||||
t.Errorf("received %v expected %v", len(rel), 1)
|
||||
}
|
||||
|
||||
err = testhelpers.CloseDatabase(dbConn)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Errorf("received %v expected %v", err, nil)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,31 +1,42 @@
|
||||
package datahistoryjob
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/database"
|
||||
"github.com/thrasher-corp/gocryptotrader/database/repository/datahistoryjobresult"
|
||||
)
|
||||
|
||||
var errCannotSetSamePrerequisite = errors.New("prerequisite job cannot be the same as the following job")
|
||||
|
||||
// DataHistoryJob is a DTO for database data
|
||||
type DataHistoryJob struct {
|
||||
ID string
|
||||
Nickname string
|
||||
ExchangeID string
|
||||
ExchangeName string
|
||||
Asset string
|
||||
Base string
|
||||
Quote string
|
||||
StartDate time.Time
|
||||
EndDate time.Time
|
||||
Interval int64
|
||||
RequestSizeLimit int64
|
||||
DataType int64
|
||||
MaxRetryAttempts int64
|
||||
BatchSize int64
|
||||
Status int64
|
||||
CreatedDate time.Time
|
||||
Results []*datahistoryjobresult.DataHistoryJobResult
|
||||
ID string
|
||||
Nickname string
|
||||
ExchangeID string
|
||||
ExchangeName string
|
||||
Asset string
|
||||
Base string
|
||||
Quote string
|
||||
StartDate time.Time
|
||||
EndDate time.Time
|
||||
Interval int64
|
||||
RequestSizeLimit int64
|
||||
DataType int64
|
||||
MaxRetryAttempts int64
|
||||
BatchSize int64
|
||||
Status int64
|
||||
CreatedDate time.Time
|
||||
Results []*datahistoryjobresult.DataHistoryJobResult
|
||||
PrerequisiteJobID string
|
||||
PrerequisiteJobNickname string
|
||||
ConversionInterval int64
|
||||
OverwriteData bool
|
||||
DecimalPlaceComparison int64
|
||||
SecondarySourceExchangeName string
|
||||
IssueTolerancePercentage float64
|
||||
ReplaceOnIssue bool
|
||||
}
|
||||
|
||||
// DBService is a service which allows the interaction with
|
||||
@@ -38,10 +49,13 @@ type DBService struct {
|
||||
// IDBService allows using data history job database service
|
||||
// without needing to care about implementation
|
||||
type IDBService interface {
|
||||
Upsert(jobs ...*DataHistoryJob) error
|
||||
GetByNickName(nickname string) (*DataHistoryJob, error)
|
||||
GetByID(id string) (*DataHistoryJob, error)
|
||||
GetJobsBetween(startDate, endDate time.Time) ([]DataHistoryJob, error)
|
||||
Upsert(...*DataHistoryJob) error
|
||||
GetByNickName(string) (*DataHistoryJob, error)
|
||||
GetByID(string) (*DataHistoryJob, error)
|
||||
GetJobsBetween(time.Time, time.Time) ([]DataHistoryJob, error)
|
||||
GetAllIncompleteJobsAndResults() ([]DataHistoryJob, error)
|
||||
GetJobAndAllResults(nickname string) (*DataHistoryJob, error)
|
||||
GetJobAndAllResults(string) (*DataHistoryJob, error)
|
||||
GetRelatedUpcomingJobs(string) ([]*DataHistoryJob, error)
|
||||
SetRelationshipByID(string, string, int64) error
|
||||
SetRelationshipByNickname(string, string, int64) error
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ func upsertPostgres(ctx context.Context, tx *sql.Tx, results ...*DataHistoryJobR
|
||||
IntervalEndTime: results[i].IntervalEndDate.UTC(),
|
||||
RunTime: results[i].Date.UTC(),
|
||||
}
|
||||
err = tempEvent.Upsert(ctx, tx, true, nil, boil.Infer(), boil.Infer())
|
||||
err = tempEvent.Upsert(ctx, tx, false, nil, boil.Infer(), boil.Infer())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -272,7 +272,7 @@ func getByUUIDPostgres(uuid string) (td Data, err error) {
|
||||
|
||||
td = Data{
|
||||
ID: result.ID,
|
||||
Timestamp: result.Timestamp,
|
||||
Timestamp: result.Timestamp.UTC(),
|
||||
Exchange: result.ExchangeNameID,
|
||||
Base: strings.ToUpper(result.Base),
|
||||
Quote: strings.ToUpper(result.Quote),
|
||||
@@ -315,7 +315,7 @@ func getInRangeSQLite(exchangeName, assetType, base, quote string, startDate, en
|
||||
"base": strings.ToUpper(base),
|
||||
"quote": strings.ToUpper(quote),
|
||||
}
|
||||
q := generateQuery(wheres, startDate, endDate)
|
||||
q := generateQuery(wheres, startDate, endDate, true)
|
||||
query := sqlite3.Trades(q...)
|
||||
var result []*sqlite3.Trade
|
||||
result, err = query.All(context.Background(), database.DB.SQL)
|
||||
@@ -357,7 +357,8 @@ func getInRangePostgres(exchangeName, assetType, base, quote string, startDate,
|
||||
"base": strings.ToUpper(base),
|
||||
"quote": strings.ToUpper(quote),
|
||||
}
|
||||
q := generateQuery(wheres, startDate, endDate)
|
||||
|
||||
q := generateQuery(wheres, startDate, endDate, false)
|
||||
query := postgres.Trades(q...)
|
||||
var result []*postgres.Trade
|
||||
result, err = query.All(context.Background(), database.DB.SQL)
|
||||
@@ -432,12 +433,18 @@ func deleteTradesPostgres(ctx context.Context, tx *sql.Tx, trades ...Data) error
|
||||
return err
|
||||
}
|
||||
|
||||
func generateQuery(clauses map[string]interface{}, start, end time.Time) []qm.QueryMod {
|
||||
func generateQuery(clauses map[string]interface{}, start, end time.Time, isSQLite bool) []qm.QueryMod {
|
||||
query := []qm.QueryMod{
|
||||
qm.Where("timestamp BETWEEN ? AND ?", start.UTC().Format(time.RFC3339), end.UTC().Format(time.RFC3339)),
|
||||
qm.OrderBy("timestamp"),
|
||||
}
|
||||
if isSQLite {
|
||||
query = append(query, qm.Where("timestamp BETWEEN ? AND ?", start.UTC().Format(time.RFC3339), end.UTC().Format(time.RFC3339)))
|
||||
} else {
|
||||
query = append(query, qm.Where("timestamp BETWEEN ? AND ?", start.UTC(), end.UTC()))
|
||||
}
|
||||
for k, v := range clauses {
|
||||
query = append(query, qm.Where(k+` = ?`, v))
|
||||
}
|
||||
|
||||
return query
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user