(Feature) OHLCV data storage and retrieval (#522)

* WIP

* end of day WIP started migration of trade history

* added kline support to hitbtc huobi lbank

* added exchangehistory to all supported exchanges started work on coinbase 300 candles/request method

* end of day WIP

* removed unused ta and misc changes to flag ready for review

* yobit cleanup

* revert coinbase changES

* general code clean up and added zb support

* poloniex support added

* renamed method to FormatExchangeKlineInterval other misc fixes

* linter fixes

* linter fixes

* removed verbose

* fixed poloniex test coverage

* revert poloniex mock data

* regenerated poloniex mock data

* a very verbose clean up

* binance mock clean up

* removed unneeded t.Log()

* setting verbose to true to debug CI issue

* first pass changes addressed

* common.ErrNotYetImplemented implemented :D

* comments added

* WIP-addressed exchange requests and reverted previous GetExchangeHistory changes

* WIP-addressed exchange requests and reverted previous GetExchangeHistory changes

* increased test coverage added kraken support

* OKGroup support completed started work on address GetExchangeHistory feedback and migrating to own PR under https://github.com/xtda/gocryptotrader/tree/exchange_history

* convert zb ratelimits

* gofmt run on okcoin

* increased delay on rate limit

* gofmt package

* fixed panic with coinbene and bithumb if conversion fails

* very broken end of day WIP

* added support for GetHistoricCandlesEx to coinbase and binance

* gofmt package

* coinbase, btcmarkets, zb ex wrapper function added

* added all exchange support for ex regenerated mock data

* update bithumb to return wrapper method

* gofmt package

* end of day started work on changes

* models created for exchange/asset/currency/currencypair, new seed system created

* reworked test coverage added okgroup support general fixes/change requests addressed

* Added OneMonth

* limit checks on supportedexchanges

* reverted getexchangehistory

* started work on currency seeding and insertion

* reworked binance tesT

* added workaround for kraken panic

* :D extremely broken WIP

* renamed command to extended removed interval check on non-implemented commands

* added wrapperconfig back

* increased test coverage for FormatExchangeKlineInterval

* WIP

* increased test coverage for FormatExchangeKlineInterval bitfinex/gateio/huobi

* linter fixes

* zb kraken lbank coinbene btcmarkets support added

* removed verbose

* OK group support for other asset types added

* swapped margin to use spot endpoint

* index support added test coverage added for asset types

* added asset type to okcoin test

* gofmt

* add asset to extended method

* removed verbose

* Very broken WIP models need to be regenerated

* add support for coinbene swap increase test coverage

* removed verbose

* small clean up of okgroup wrapper functions

* verbose to troubleshoot CI issues

* removed verbose

* added error check reverted coinbasechanges

* attempting to fix broken model generation

* readme updated

* :D i broke so much

* model regeneration fixed & complete

* candle model filled out

* removed unused start/finish started work on decoupling api requests from kline package

* restructured coinbene, bithumb methods, added bitstamp support

* kraken time fix

* BTCMarkets restructure

* typo fix

* removed test for futures due to contact changing

* removed test for futures due to contact changing

* added start/end date to extended method over range

* WIP

* added sync option to candles

* converted to assettranslator

* removed verbose

* removed verbose

* removed invalid char

* reverted incorrectly removed return

* added import

* further template updates

* macos hates my keyboard :D

* misc canges

* started work on creating kline from databases eed

* x -> i

* removed verbose

* updated fixCasing to allocate var before checks

* sqlite3 supported work started

* removed time conversion

* further work on tets

* sort all outgoing kline candles

* fixCasing fix

* after/before checks added

* added parallel to test

* logic check on BTCmarkets

* removed unused param, used correct iterator

* converted HitBTC to use time.Time

* test update

* add iszero false check to candle times

* Seed exchange & OHCLV data for test usage

* updated resultlimit to 5000

* new line added

* added comment to exported const

* move date forward

* use configured ratelimit

* fixed pair for test

* panic fixed WIP on fixCasing

* fixCasing rework, started work on readme docs

* enable rate limiter for wrapper issues tool

* docs updated

* removed unused vars from tests

* removed err from return and formatted currency

* updated Yobit supported status

* Updated HitBTC to use onehour candles due to test exeuction times

* added further details to gctcli output

* added link to docs

* added link to tempalte

* disable FTX websocket in config_example

* fix poloneix

* regenerated poloniex mock data

* removed recording flag

* format on package

* moved exchange var outside of method scope

* reworked seeding into package

* verbose output improved

* removed verbose from candles

* Added comments to exported functions

* removed verbose output

* Reworking of tests

* end of day commit

* added SQLite migration for asset, test updates for exchange, added support for withdrawal for new exchange_name_id relation

* regenerated database models

* WIP

* test rework, sqlite migration updates for withdrawal

* Reworked error returns to stop duplications, format all output to UTC, changed gctscript OHLCV output to be unix timestmap, started work on seeding tool

* gofmt

* dbseed command for seeding exchanges added, removed seed from dbmigrate, LoadCSV method added for exchange

* go mod tidy

* added import candle from csv command to dbseed

* Removed reset & duplicate migrate command from helper, renamed struct to Item/Candle over Candle/Tick, added test coverage to dbseed, improved withdraw tests

* remove broken tests due to ORM generation of Fk, removed go unneeded goroutine for inserting records

* removed t.Cleanup usage because appveyor

* added test coverage to StoreInDatabase()

* removed unneeded data from config for test

* added new line

* Added down migration support to candle/asset removal, return original error and display rollback error

* removed unneeded err assignment, break out of loop on error

* add err check to method for test

* first pass changes

* WIP

* Updated migrations for both sqlite3 & postgres to create exchanges if any withdrawal_history records are found, removed migrate command

* removed argusage as usage information is provided by flags

* added inserted records return count and test coverage

* new line added

* Database: comment config details out to disable local postgresl testing by default

* added asset support

* Database: added error return when no exchanges are found, title exchange name across queries

* Fixed test data

* Database: removed migration bool from ConnectToDatabase(), removed empty line, insert asset on test

* Database: verbose linter :D

* Database/OHLCV: removed go module from dbseed command and reverted back to main module, converted interval to int64 to match other parts of code base, provided migrations to update database, poloniex fix to skip first candle

* dbseed: add completed message to output

* Database: added migration to add asset to uniq index for candle table

* Database: database -> exchange

* Database: add asset to upsert conflict

* Poloneix: fix for invalid interval

* regenerated poloniex mock data

* Database: added down migration for candle interval update

* OHCLV/Database: WIP

* OHLCV/Datastore: added new ValidateKline() method to check that asset, pair, interval are enabled/supported by exchange and updated tests

* revert configtest changes

* OHCLV/Kline: pointer assignment to ErrorKline & format pairs on check

* goimports

* migration updates

* Database/Candle: updated tests

* revert configtest changes

* ZB: updaed defaults to use uppercase pairs

* ZB: updaed defaults to use uppercase pairs

* revert pair formatting

* Switch over to .Cotains() method from pairManagement

* Added comment & ftx back 😆

* OHLCV/Datastore: (Candles): added not null to asset, (WithdrawalHistory): added not null to exchange_name_id), reworked KlineError return

* set verbose to false

* updated btc markets test

* Updated readme

* removed ability to have blank exchange name as indexing requires it

* remove old usedb and empty exchange check, return error on no data instead

* Updated kline test to match date range

* Renamed candles.exchange_id column to candles.xchange_name_id to match withdrawal table, return err on unwrap, zb fix revert

* regenerated sqlite3 models

* force UTC for sqlite.... because sqlite

* OHLCV/Datastore: upper case pairs on insert for consistency, remove unneeded rollback call on commit failure as it has no effect, move rollback outside of insertsqlite/insertpsql methods

* add error check for no candles

* nil length/cap is 0 in golang :D

* OHLCV/Datastore: updated wording on examples, removed duplicate testfile

* OHLCV/Datastore: updated README with links to dbseed

* dbtool -> dbseed
This commit is contained in:
Andrew
2020-09-03 17:13:53 +10:00
committed by GitHub
parent 4b0b0f97a1
commit 39bbd8dfc9
122 changed files with 21985 additions and 6020 deletions

View File

@@ -106,6 +106,9 @@ dbmigrate -command "up"
dbmigrate provides a -migrationdir flag override to tell it what path to look in for migrations
###### Note: its highly recommended to backup any data before running migrations against a production database especially if you are running SQLite due to alter table limitations
##### Adding a new model
Model's are generated using [SQLBoiler](https://github.com/thrasher-corp/sqlboiler)
A helper tool has been made located in gen_sqlboiler_config that will parse your GoCryptoTrader config and output a SQLBoiler config
@@ -123,7 +126,6 @@ along with the location of the sqlboiler generated config
-outdir "~/.gocryptotrader/"
```
Generate a new model that gets placed in ./database/models/<databasetype> folder
Linux:
@@ -144,6 +146,10 @@ And in the contrib/sqlboiler.cmd for windows users
##### Adding a Repository
+ Create Repository directory in github.com/thrasher-corp/gocryptotrader/database/repository/
##### DBSeed helper
A helper tool [cmd/dbseed](../cmd/dbseed/README.md) has been created for assisting with data migration
## Contribution
Please feel free to submit any pull requests or suggest any desired features to be added.

View File

@@ -53,4 +53,6 @@ const (
DBSQLite3 = "sqlite3"
// DBPostgreSQL const string for PostgreSQL across code base
DBPostgreSQL = "postgres"
// DBInvalidDriver const string for invalid driver
DBInvalidDriver = "invalid driver"
)

View File

@@ -0,0 +1,12 @@
-- +goose Up
-- SQL in this section is executed when the migration is applied.
CREATE TABLE IF NOT EXISTS exchange
(
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
name varchar(255) NOT NULL
);
CREATE UNIQUE INDEX IF NOT EXISTS "index_name_on_exchange" ON exchange using btree(name);
-- +goose Down
-- SQL in this section is executed when the migration is rolled back.
DROP TABLE exchange;

View File

@@ -0,0 +1,11 @@
-- +goose Up
-- SQL in this section is executed when the migration is applied.
CREATE TABLE "exchange" (
id text not null primary key,
name text not null,
unique(name) ON CONFLICT IGNORE
);
-- +goose Down
-- SQL in this section is executed when the migration is rolled back.
DROP TABLE "exchange";

View File

@@ -0,0 +1,22 @@
-- +goose Up
-- SQL in this section is executed when the migration is applied.
CREATE TABLE IF NOT EXISTS candle
(
ID uuid PRIMARY KEY DEFAULT gen_random_uuid(),
exchange_id uuid REFERENCES exchange(id) NOT NULL,
Base varchar(30) NOT NULL,
Quote varchar(30) NOT NULL,
Interval varchar(30) NOT NULL,
Timestamp TIMESTAMPTZ NOT NULL,
Open DOUBLE PRECISION NOT NULL,
High DOUBLE PRECISION NOT NULL,
Low DOUBLE PRECISION NOT NULL,
Close DOUBLE PRECISION NOT NULL,
Volume DOUBLE PRECISION NOT NULL,
unique(Timestamp, exchange_id, Base, Quote, Interval)
);
-- +goose Down
-- SQL in this section is executed when the migration is rolled back.
DROP TABLE candle;

View File

@@ -0,0 +1,19 @@
-- +goose Up
-- SQL in this section is executed when the migration is applied.
CREATE TABLE "candle" (
id text not null primary key,
exchange_id uuid REFERENCES exchange(id),
Base text NOT NULL,
Quote text NOT NULL,
Interval text NOT NULL,
Timestamp TIMESTAMP NOT NULL,
Open REAL NOT NULL,
High REAL NOT NULL,
Low REAL NOT NULL,
Close REAL NOT NULL,
Volume REAL NOT NULL,
unique(Timestamp, exchange_id, Base, Quote, Interval) ON CONFLICT IGNORE
);
-- +goose Down
-- SQL in this section is executed when the migration is rolled back.
DROP TABLE "candle";

View File

@@ -0,0 +1,6 @@
-- +goose Up
-- SQL in this section is executed when the migration is applied.
ALTER TABLE candle ADD COLUMN asset VARCHAR(255) NOT NULL;
-- +goose Down
-- SQL in this section is executed when the migration is rolled back.
ALTER TABLE candle DROP COLUMN asset;

View File

@@ -0,0 +1,23 @@
-- +goose Up
-- SQL in this section is executed when the migration is applied.
ALTER TABLE candle ADD COLUMN asset text;
-- +goose Down
-- SQL in this section is executed when the migration is rolled back.
CREATE TABLE "candle_new" (
id text not null primary key,
exchange_id uuid REFERENCES exchange(id),
Base text NOT NULL,
Quote text NOT NULL,
Interval text NOT NULL,
Timestamp TIMESTAMP NOT NULL,
Open REAL NOT NULL,
High REAL NOT NULL,
Low REAL NOT NULL,
Close REAL NOT NULL,
Volume REAL NOT NULL,
unique(Timestamp, exchange_id, Base, Quote, Interval) ON CONFLICT IGNORE
);
INSERT INTO candle_new SELECT id, exchange_id, Base, Quote, Interval, Timestamp, Open, High, Low, Close, Volume FROM candle;
DROP TABLE candle;
ALTER TABLE candle_new RENAME TO candle;

View File

@@ -0,0 +1,14 @@
-- +goose Up
-- SQL in this section is executed when the migration is applied.
INSERT INTO exchange(name) SELECT exchange from withdrawal_history;
ALTER TABLE withdrawal_history ADD COLUMN exchange_name_id UUID REFERENCES exchange(id);
UPDATE withdrawal_history SET exchange_name_id = r.ID FROM (SELECT * from exchange) as r WHERE exchange = r.name;
ALTER TABLE withdrawal_history DROP COLUMN exchange;
-- +goose Down
-- SQL in this section is executed when the migration is rolled back.
ALTER TABLE withdrawal_history ADD COLUMN exchange TEXT;
UPDATE withdrawal_history SET exchange = r.name FROM (SELECT * from exchange) as r WHERE exchange_name_id = r.id;
ALTER TABLE withdrawal_history ALTER COLUMN exchange SET NOT NULL;
ALTER TABLE withdrawal_history DROP CONSTRAINT withdrawal_history_exchange_name_id_fkey;
ALTER TABLE withdrawal_history DROP COLUMN exchange_name_id;

View File

@@ -0,0 +1,84 @@
-- +goose Up
-- SQL in this section is executed when the migration is applied.
INSERT INTO exchange(id, name)
SELECT
lower(hex( randomblob(4)) || '-' || hex( randomblob(2)) || '-' || '4' || substr( hex( randomblob(2)), 2) || '-'
|| substr('AB89', 1 + (abs(random()) % 4) , 1) ||
substr(hex(randomblob(2)), 2) || '-' || hex(randomblob(6))), exchange
from withdrawal_history;
ALTER TABLE withdrawal_history ADD COLUMN exchange_name_id;
UPDATE withdrawal_history
SET
exchange_name_id = (SELECT id FROM exchange WHERE withdrawal_history.exchange = lower(name))
WHERE
EXISTS(
SELECT *
FROM exchange
WHERE lower("exchange".name) = withdrawal_history.exchange
);
CREATE TABLE IF NOT EXISTS withdrawal_history_new
(
id text PRIMARY KEY NOT NULL,
exchange_name_id text,
exchange_id text NOT NULL,
status text NOT NULL,
currency text NOT NULL,
amount real NOT NULL,
description text,
withdraw_type integer NOT NULL,
created_at timestamp NOT NULL default CURRENT_TIMESTAMP,
updated_at timestamp NOT NULL default CURRENT_TIMESTAMP,
FOREIGN KEY(exchange_name_id) REFERENCES exchange(id) ON DELETE RESTRICT
);
INSERT INTO
withdrawal_history_new (id, exchange_name_id, exchange_id, status, currency, amount, description, withdraw_type, created_at, updated_at)
SELECT
id, exchange_name_id, exchange_id, status, currency, amount, description, withdraw_type, created_at, updated_at
FROM
withdrawal_history;
DROP TABLE withdrawal_history;
ALTER TABLE withdrawal_history_new RENAME TO withdrawal_history;
-- +goose Down
-- SQL in this section is executed when the migration is rolled back.
ALTER TABLE withdrawal_history ADD COLUMN exchange;
UPDATE withdrawal_history
SET
exchange = (SELECT name FROM exchange WHERE withdrawal_history.exchange_name_id = id)
WHERE
EXISTS(
SELECT *
FROM exchange
WHERE exchange.id = withdrawal_history.exchange_name_id
);
CREATE TABLE IF NOT EXISTS withdrawal_history_new
(
id text PRIMARY KEY NOT NULL,
exchange text NOT NULL,
exchange_id text NOT NULL,
status text NOT NULL,
currency text NOT NULL,
amount real NOT NULL,
description text,
withdraw_type integer NOT NULL,
created_at timestamp NOT NULL default CURRENT_TIMESTAMP,
updated_at timestamp NOT NULL default CURRENT_TIMESTAMP
);
INSERT INTO
withdrawal_history_new (id, exchange, exchange_id, status, currency, amount, description, withdraw_type, created_at, updated_at)
SELECT
id, exchange, exchange_id, status, currency, amount, description, withdraw_type, created_at, updated_at
FROM
withdrawal_history;
DROP TABLE withdrawal_history;
ALTER TABLE withdrawal_history_new RENAME TO withdrawal_history;

View File

@@ -0,0 +1,35 @@
-- +goose Up
-- SQL in this section is executed when the migration is applied.
UPDATE candle SET interval = replace (candle.interval, '15s', '15');
UPDATE candle SET interval = replace (candle.interval, '1m', '60');
UPDATE candle SET interval = replace (candle.interval, '3m', '180');
UPDATE candle SET interval = replace (candle.interval, '5m', '300');
UPDATE candle SET interval = replace (candle.interval, '10m', '600');
UPDATE candle SET interval = replace (candle.interval, '15m', '900');
UPDATE candle SET interval = replace (candle.interval, '30m', '1800');
UPDATE candle SET interval = replace (candle.interval, '1h', '3600');
UPDATE candle SET interval = replace (candle.interval, '6h', '21600');
UPDATE candle SET interval = replace (candle.interval, '8h', '28800');
UPDATE candle SET interval = replace (candle.interval, '12h', '43200');
UPDATE candle SET interval = replace (candle.interval, '24h', '86400');
UPDATE candle SET interval = replace (candle.interval, '3d', '259200');
UPDATE candle SET interval = replace (candle.interval, '7w', '604800');
UPDATE candle SET interval = replace (candle.interval, '15d', '1296000');
UPDATE candle SET interval = replace (candle.interval, '1w', '604800');
UPDATE candle SET interval = replace (candle.interval, '2W', '1209600');
UPDATE candle SET interval = replace (candle.interval, '1M', '2678400');
UPDATE candle SET interval = replace (candle.interval, '1Y', '31536000');
UPDATE candle SET interval = replace (candle.interval, '1d', '86400');
UPDATE candle SET interval = replace (candle.interval, '72h', '259200');
UPDATE candle SET interval = replace (candle.interval, '168h', '604800');
UPDATE candle SET interval = replace (candle.interval, '360h', '1296000');
UPDATE candle SET interval = replace (candle.interval, '336h', '1209600');
UPDATE candle SET interval = replace (candle.interval, '744h', '2678400');
UPDATE candle SET interval = replace (candle.interval, '8760h', '31536000');
UPDATE candle SET interval = replace (candle.interval, '4h', '14400');
UPDATE candle SET interval = replace (candle.interval, '2h', '7200');
alter table candle alter column interval type bigint using interval::bigint;
-- +goose Down
-- SQL in this section is executed when the migration is rolled back.
alter table candle alter column interval type varchar(30) using interval::varchar(30);

View File

@@ -0,0 +1,34 @@
-- +goose Up
-- SQL in this section is executed when the migration is applied.
UPDATE candle SET interval = replace (candle.interval, '15s', '15');
UPDATE candle SET interval = replace (candle.interval, '1m', '60');
UPDATE candle SET interval = replace (candle.interval, '3m', '180');
UPDATE candle SET interval = replace (candle.interval, '5m', '300');
UPDATE candle SET interval = replace (candle.interval, '10m', '600');
UPDATE candle SET interval = replace (candle.interval, '15m', '900');
UPDATE candle SET interval = replace (candle.interval, '30m', '1800');
UPDATE candle SET interval = replace (candle.interval, '1h', '3600');
UPDATE candle SET interval = replace (candle.interval, '6h', '21600');
UPDATE candle SET interval = replace (candle.interval, '8h', '28800');
UPDATE candle SET interval = replace (candle.interval, '12h', '43200');
UPDATE candle SET interval = replace (candle.interval, '24h', '86400');
UPDATE candle SET interval = replace (candle.interval, '3d', '259200');
UPDATE candle SET interval = replace (candle.interval, '7w', '604800');
UPDATE candle SET interval = replace (candle.interval, '15d', '1296000');
UPDATE candle SET interval = replace (candle.interval, '1w', '604800');
UPDATE candle SET interval = replace (candle.interval, '2W', '1209600');
UPDATE candle SET interval = replace (candle.interval, '1M', '2678400');
UPDATE candle SET interval = replace (candle.interval, '1Y', '31536000');
UPDATE candle SET interval = replace (candle.interval, '1d', '86400');
UPDATE candle SET interval = replace (candle.interval, '72h', '259200');
UPDATE candle SET interval = replace (candle.interval, '168h', '604800');
UPDATE candle SET interval = replace (candle.interval, '360h', '1296000');
UPDATE candle SET interval = replace (candle.interval, '336h', '1209600');
UPDATE candle SET interval = replace (candle.interval, '744h', '2678400');
UPDATE candle SET interval = replace (candle.interval, '8760h', '31536000');
UPDATE candle SET interval = replace (candle.interval, '4h', '14400');
UPDATE candle SET interval = replace (candle.interval, '2h', '7200');
-- +goose Down
-- SQL in this section is executed when the migration is rolled back.
-- Nothing to run for sqlite as we leave the type as text

View File

@@ -0,0 +1,6 @@
-- +goose Up
ALTER TABLE candle DROP CONSTRAINT candle_timestamp_exchange_id_base_quote_interval_key;
ALTER TABLE candle ADD CONSTRAINT candle_timestamp_exchange_id_base_quote_interval_asset_key UNIQUE(Timestamp, exchange_id, Base, Quote, Interval, asset);
-- +goose Down
ALTER TABLE candle DROP CONSTRAINT candle_timestamp_exchange_id_base_quote_interval_asset_key;
ALTER TABLE candle ADD CONSTRAINT candle_timestamp_exchange_id_base_quote_interval_key UNIQUE(Timestamp, exchange_id, Base, Quote, Interval);

View File

@@ -0,0 +1,39 @@
-- +goose Up
CREATE TABLE "candle_new" (
id text not null primary key,
exchange_id uuid REFERENCES exchange(id),
Base text NOT NULL,
Quote text NOT NULL,
Interval text NOT NULL,
Timestamp TIMESTAMP NOT NULL,
Open REAL NOT NULL,
High REAL NOT NULL,
Low REAL NOT NULL,
Close REAL NOT NULL,
Volume REAL NOT NULL,
Asset text,
unique(Timestamp, exchange_id, Base, Quote, Interval, asset) ON CONFLICT IGNORE
);
INSERT INTO candle_new SELECT id, exchange_id, Base, Quote, Interval, Timestamp, Open, High, Low, Close, Volume, Asset FROM candle;
DROP TABLE candle;
ALTER TABLE candle_new RENAME TO candle;
-- +goose Down
CREATE TABLE "candle_new" (
id text not null primary key,
exchange_id uuid REFERENCES exchange(id),
Base text NOT NULL,
Quote text NOT NULL,
Interval text NOT NULL,
Timestamp TIMESTAMP NOT NULL,
Open REAL NOT NULL,
High REAL NOT NULL,
Low REAL NOT NULL,
Close REAL NOT NULL,
Volume REAL NOT NULL,
Asset TEXT,
unique(Timestamp, exchange_id, Base, Quote, Interval) ON CONFLICT IGNORE
);
INSERT INTO candle_new SELECT id, exchange_id, Base, Quote, Interval, Timestamp, Open, High, Low, Close, Volume, Asset FROM candle;
DROP TABLE candle;
ALTER TABLE candle_new RENAME TO candle;

View File

@@ -0,0 +1,7 @@
-- +goose Up
-- SQL in this section is executed when the migration is applied.
ALTER TABLE withdrawal_history ALTER COLUMN exchange_name_id SET NOT NULL;
-- +goose Down
-- SQL in this section is executed when the migration is rolled back.
ALTER TABLE withdrawal_history ALTER COLUMN exchange_name_id SET NULL;

View File

@@ -0,0 +1,51 @@
-- +goose Up
-- SQL in this section is executed when the migration is applied.
CREATE TABLE IF NOT EXISTS withdrawal_history_new
(
id text PRIMARY KEY NOT NULL,
exchange_name_id text NOT NULL,
exchange_id text NOT NULL,
status text NOT NULL,
currency text NOT NULL,
amount real NOT NULL,
description text,
withdraw_type integer NOT NULL,
created_at timestamp NOT NULL default CURRENT_TIMESTAMP,
updated_at timestamp NOT NULL default CURRENT_TIMESTAMP,
FOREIGN KEY(exchange_name_id) REFERENCES exchange(id) ON DELETE RESTRICT
);
INSERT INTO
withdrawal_history_new (id, exchange_name_id, exchange_id, status, currency, amount, description, withdraw_type, created_at, updated_at)
SELECT
id, exchange_name_id, exchange_id, status, currency, amount, description, withdraw_type, created_at, updated_at
FROM
withdrawal_history;
DROP TABLE withdrawal_history;
ALTER TABLE withdrawal_history_new RENAME TO withdrawal_history;
-- +goose Down
-- SQL in this section is executed when the migration is rolled back.
CREATE TABLE IF NOT EXISTS withdrawal_history_new
(
id text PRIMARY KEY NOT NULL,
exchange_name_id text,
exchange_id text NOT NULL,
status text NOT NULL,
currency text NOT NULL,
amount real NOT NULL,
description text,
withdraw_type integer NOT NULL,
created_at timestamp NOT NULL default CURRENT_TIMESTAMP,
updated_at timestamp NOT NULL default CURRENT_TIMESTAMP
);
INSERT INTO
withdrawal_history_new (id, exchange_name_id, exchange_id, status, currency, amount, description, withdraw_type, created_at, updated_at)
SELECT
id, exchange_name_id, exchange_id, status, currency, amount, description, withdraw_type, created_at, updated_at
FROM
withdrawal_history;
DROP TABLE withdrawal_history;
ALTER TABLE withdrawal_history_new RENAME TO withdrawal_history;

View File

@@ -0,0 +1,7 @@
-- +goose Up
-- SQL in this section is executed when the migration is applied.
ALTER TABLE candle ALTER COLUMN asset SET NOT NULL;
-- +goose Down
-- SQL in this section is executed when the migration is rolled back.
ALTER TABLE candle ALTER COLUMN aseet SET NULL;

View File

@@ -0,0 +1,39 @@
-- +goose Up
CREATE TABLE "candle_new" (
id text not null primary key,
exchange_id uuid REFERENCES exchange(id),
Base text NOT NULL,
Quote text NOT NULL,
Interval text NOT NULL,
Timestamp TIMESTAMP NOT NULL,
Open REAL NOT NULL,
High REAL NOT NULL,
Low REAL NOT NULL,
Close REAL NOT NULL,
Volume REAL NOT NULL,
Asset text NOT NULL,
unique(Timestamp, exchange_id, Base, Quote, Interval, Asset) ON CONFLICT IGNORE
);
INSERT INTO candle_new SELECT id, exchange_id, Base, Quote, Interval, Timestamp, Open, High, Low, Close, Volume, Asset FROM candle;
DROP TABLE candle;
ALTER TABLE candle_new RENAME TO candle;
-- +goose Down
CREATE TABLE "candle_new" (
id text not null primary key,
exchange_id uuid REFERENCES exchange(id),
Base text NOT NULL,
Quote text NOT NULL,
Interval text NOT NULL,
Timestamp TIMESTAMP NOT NULL,
Open REAL NOT NULL,
High REAL NOT NULL,
Low REAL NOT NULL,
Close REAL NOT NULL,
Volume REAL NOT NULL,
Asset TEXT,
unique(Timestamp, exchange_id, Base, Quote, Interval, Asset) ON CONFLICT IGNORE
);
INSERT INTO candle_new SELECT id, exchange_id, Base, Quote, Interval, Timestamp, Open, High, Low, Close, Volume, Asset FROM candle;
DROP TABLE candle;
ALTER TABLE candle_new RENAME TO candle;

View File

@@ -0,0 +1,10 @@
-- +goose Up
ALTER TABLE candle DROP CONSTRAINT candle_timestamp_exchange_id_base_quote_interval_asset_key;
ALTER TABLE candle RENAME COLUMN exchange_id TO exchange_name_id;
ALTER TABLE candle ALTER COLUMN exchange_name_id SET NOT NULL;
ALTER TABLE candle ADD CONSTRAINT candle_timestamp_exchange_id_base_quote_interval_asset_key UNIQUE(Timestamp, exchange_name_id, Base, Quote, Interval, asset);
-- +goose Down
ALTER TABLE candle DROP CONSTRAINT candle_timestamp_exchange_id_base_quote_interval_asset_key;
ALTER TABLE candle RENAME COLUMN exchange_name_id TO exchange_id;
ALTER TABLE candle ALTER COLUMN exchange_id SET NOT NULL;
ALTER TABLE candle ADD CONSTRAINT candle_timestamp_exchange_id_base_quote_interval_asset_key UNIQUE(Timestamp, exchange_id, Base, Quote, Interval);

View File

@@ -0,0 +1,39 @@
-- +goose Up
CREATE TABLE "candle_new" (
id text not null primary key,
exchange_name_id uuid REFERENCES exchange(id) NOT NULL,
Base text NOT NULL,
Quote text NOT NULL,
Interval text NOT NULL,
Timestamp TIMESTAMP NOT NULL,
Open REAL NOT NULL,
High REAL NOT NULL,
Low REAL NOT NULL,
Close REAL NOT NULL,
Volume REAL NOT NULL,
Asset text NOT NULL,
unique(Timestamp, exchange_name_id, Base, Quote, Interval, Asset) ON CONFLICT IGNORE
);
INSERT INTO candle_new SELECT id, exchange_id, Base, Quote, Interval, Timestamp, Open, High, Low, Close, Volume, Asset FROM candle;
DROP TABLE candle;
ALTER TABLE candle_new RENAME TO candle;
-- +goose Down
CREATE TABLE "candle_new" (
id text not null primary key,
exchange_id uuid REFERENCES exchange(id),
Base text NOT NULL,
Quote text NOT NULL,
Interval text NOT NULL,
Timestamp TIMESTAMP NOT NULL,
Open REAL NOT NULL,
High REAL NOT NULL,
Low REAL NOT NULL,
Close REAL NOT NULL,
Volume REAL NOT NULL,
Asset TEXT,
unique(Timestamp, exchange_id, Base, Quote, Interval, Asset) ON CONFLICT IGNORE
);
INSERT INTO candle_new SELECT id, exchange_name_id, Base, Quote, Interval, Timestamp, Open, High, Low, Close, Volume, Asset FROM candle;
DROP TABLE candle;
ALTER TABLE candle_new RENAME TO candle;

View File

@@ -13,77 +13,77 @@ import "testing"
// Separating the tests thusly grants avoidance of Postgres deadlocks.
func TestParent(t *testing.T) {
t.Run("AuditEvents", testAuditEvents)
t.Run("Exchanges", testExchanges)
t.Run("Scripts", testScripts)
t.Run("WithdrawalHistories", testWithdrawalHistories)
}
func TestDelete(t *testing.T) {
t.Run("AuditEvents", testAuditEventsDelete)
t.Run("Exchanges", testExchangesDelete)
t.Run("Scripts", testScriptsDelete)
t.Run("WithdrawalHistories", testWithdrawalHistoriesDelete)
}
func TestQueryDeleteAll(t *testing.T) {
t.Run("AuditEvents", testAuditEventsQueryDeleteAll)
t.Run("Exchanges", testExchangesQueryDeleteAll)
t.Run("Scripts", testScriptsQueryDeleteAll)
t.Run("WithdrawalHistories", testWithdrawalHistoriesQueryDeleteAll)
}
func TestSliceDeleteAll(t *testing.T) {
t.Run("AuditEvents", testAuditEventsSliceDeleteAll)
t.Run("Exchanges", testExchangesSliceDeleteAll)
t.Run("Scripts", testScriptsSliceDeleteAll)
t.Run("WithdrawalHistories", testWithdrawalHistoriesSliceDeleteAll)
}
func TestExists(t *testing.T) {
t.Run("AuditEvents", testAuditEventsExists)
t.Run("Exchanges", testExchangesExists)
t.Run("Scripts", testScriptsExists)
t.Run("WithdrawalHistories", testWithdrawalHistoriesExists)
}
func TestFind(t *testing.T) {
t.Run("AuditEvents", testAuditEventsFind)
t.Run("Exchanges", testExchangesFind)
t.Run("Scripts", testScriptsFind)
t.Run("WithdrawalHistories", testWithdrawalHistoriesFind)
}
func TestBind(t *testing.T) {
t.Run("AuditEvents", testAuditEventsBind)
t.Run("Exchanges", testExchangesBind)
t.Run("Scripts", testScriptsBind)
t.Run("WithdrawalHistories", testWithdrawalHistoriesBind)
}
func TestOne(t *testing.T) {
t.Run("AuditEvents", testAuditEventsOne)
t.Run("Exchanges", testExchangesOne)
t.Run("Scripts", testScriptsOne)
t.Run("WithdrawalHistories", testWithdrawalHistoriesOne)
}
func TestAll(t *testing.T) {
t.Run("AuditEvents", testAuditEventsAll)
t.Run("Exchanges", testExchangesAll)
t.Run("Scripts", testScriptsAll)
t.Run("WithdrawalHistories", testWithdrawalHistoriesAll)
}
func TestCount(t *testing.T) {
t.Run("AuditEvents", testAuditEventsCount)
t.Run("Exchanges", testExchangesCount)
t.Run("Scripts", testScriptsCount)
t.Run("WithdrawalHistories", testWithdrawalHistoriesCount)
}
func TestHooks(t *testing.T) {
t.Run("AuditEvents", testAuditEventsHooks)
t.Run("Exchanges", testExchangesHooks)
t.Run("Scripts", testScriptsHooks)
t.Run("WithdrawalHistories", testWithdrawalHistoriesHooks)
}
func TestInsert(t *testing.T) {
t.Run("AuditEvents", testAuditEventsInsert)
t.Run("AuditEvents", testAuditEventsInsertWhitelist)
t.Run("Exchanges", testExchangesInsert)
t.Run("Exchanges", testExchangesInsertWhitelist)
t.Run("Scripts", testScriptsInsert)
t.Run("Scripts", testScriptsInsertWhitelist)
t.Run("WithdrawalHistories", testWithdrawalHistoriesInsert)
t.Run("WithdrawalHistories", testWithdrawalHistoriesInsertWhitelist)
}
// TestToOne tests cannot be run in parallel
@@ -128,30 +128,29 @@ func TestToManyRemove(t *testing.T) {}
func TestReload(t *testing.T) {
t.Run("AuditEvents", testAuditEventsReload)
t.Run("Scripts", testScriptsReload)
t.Run("WithdrawalHistories", testWithdrawalHistoriesReload)
t.Run("Exchanges", testExchangesReload)
}
func TestReloadAll(t *testing.T) {
t.Run("AuditEvents", testAuditEventsReloadAll)
t.Run("Exchanges", testExchangesReloadAll)
t.Run("Scripts", testScriptsReloadAll)
t.Run("WithdrawalHistories", testWithdrawalHistoriesReloadAll)
}
func TestSelect(t *testing.T) {
t.Run("AuditEvents", testAuditEventsSelect)
t.Run("Exchanges", testExchangesSelect)
t.Run("Scripts", testScriptsSelect)
t.Run("WithdrawalHistories", testWithdrawalHistoriesSelect)
}
func TestUpdate(t *testing.T) {
t.Run("AuditEvents", testAuditEventsUpdate)
t.Run("Exchanges", testExchangesUpdate)
t.Run("Scripts", testScriptsUpdate)
t.Run("WithdrawalHistories", testWithdrawalHistoriesUpdate)
}
func TestSliceUpdateAll(t *testing.T) {
t.Run("AuditEvents", testAuditEventsSliceUpdateAll)
t.Run("Exchanges", testExchangesSliceUpdateAll)
t.Run("Scripts", testScriptsSliceUpdateAll)
t.Run("WithdrawalHistories", testWithdrawalHistoriesSliceUpdateAll)
}

View File

@@ -5,6 +5,8 @@ package postgres
var TableNames = struct {
AuditEvent string
Candle string
Exchange string
Script string
ScriptExecution string
WithdrawalCrypto string
@@ -12,6 +14,8 @@ var TableNames = struct {
WithdrawalHistory string
}{
AuditEvent: "audit_event",
Candle: "candle",
Exchange: "exchange",
Script: "script",
ScriptExecution: "script_execution",
WithdrawalCrypto: "withdrawal_crypto",

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,841 @@
// Code generated by SQLBoiler 3.5.0-gct (https://github.com/thrasher-corp/sqlboiler). DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package postgres
import (
"bytes"
"context"
"reflect"
"testing"
"github.com/thrasher-corp/sqlboiler/boil"
"github.com/thrasher-corp/sqlboiler/queries"
"github.com/thrasher-corp/sqlboiler/randomize"
"github.com/thrasher-corp/sqlboiler/strmangle"
)
var (
// Relationships sometimes use the reflection helper queries.Equal/queries.Assign
// so force a package dependency in case they don't.
_ = queries.Equal
)
func testCandles(t *testing.T) {
t.Parallel()
query := Candles()
if query.Query == nil {
t.Error("expected a query, got nothing")
}
}
func testCandlesDelete(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Candle{}
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if rowsAff, err := o.Delete(ctx, tx); err != nil {
t.Error(err)
} else if rowsAff != 1 {
t.Error("should only have deleted one row, but affected:", rowsAff)
}
count, err := Candles().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 0 {
t.Error("want zero records, got:", count)
}
}
func testCandlesQueryDeleteAll(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Candle{}
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if rowsAff, err := Candles().DeleteAll(ctx, tx); err != nil {
t.Error(err)
} else if rowsAff != 1 {
t.Error("should only have deleted one row, but affected:", rowsAff)
}
count, err := Candles().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 0 {
t.Error("want zero records, got:", count)
}
}
func testCandlesSliceDeleteAll(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Candle{}
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
slice := CandleSlice{o}
if rowsAff, err := slice.DeleteAll(ctx, tx); err != nil {
t.Error(err)
} else if rowsAff != 1 {
t.Error("should only have deleted one row, but affected:", rowsAff)
}
count, err := Candles().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 0 {
t.Error("want zero records, got:", count)
}
}
func testCandlesExists(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Candle{}
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
e, err := CandleExists(ctx, tx, o.ID)
if err != nil {
t.Errorf("Unable to check if Candle exists: %s", err)
}
if !e {
t.Errorf("Expected CandleExists to return true, but got false.")
}
}
func testCandlesFind(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Candle{}
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
candleFound, err := FindCandle(ctx, tx, o.ID)
if err != nil {
t.Error(err)
}
if candleFound == nil {
t.Error("want a record, got nil")
}
}
func testCandlesBind(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Candle{}
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if err = Candles().Bind(ctx, tx, o); err != nil {
t.Error(err)
}
}
func testCandlesOne(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Candle{}
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if x, err := Candles().One(ctx, tx); err != nil {
t.Error(err)
} else if x == nil {
t.Error("expected to get a non nil record")
}
}
func testCandlesAll(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
candleOne := &Candle{}
candleTwo := &Candle{}
if err = randomize.Struct(seed, candleOne, candleDBTypes, false, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
if err = randomize.Struct(seed, candleTwo, candleDBTypes, false, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = candleOne.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if err = candleTwo.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
slice, err := Candles().All(ctx, tx)
if err != nil {
t.Error(err)
}
if len(slice) != 2 {
t.Error("want 2 records, got:", len(slice))
}
}
func testCandlesCount(t *testing.T) {
t.Parallel()
var err error
seed := randomize.NewSeed()
candleOne := &Candle{}
candleTwo := &Candle{}
if err = randomize.Struct(seed, candleOne, candleDBTypes, false, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
if err = randomize.Struct(seed, candleTwo, candleDBTypes, false, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = candleOne.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if err = candleTwo.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
count, err := Candles().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 2 {
t.Error("want 2 records, got:", count)
}
}
func candleBeforeInsertHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
*o = Candle{}
return nil
}
func candleAfterInsertHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
*o = Candle{}
return nil
}
func candleAfterSelectHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
*o = Candle{}
return nil
}
func candleBeforeUpdateHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
*o = Candle{}
return nil
}
func candleAfterUpdateHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
*o = Candle{}
return nil
}
func candleBeforeDeleteHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
*o = Candle{}
return nil
}
func candleAfterDeleteHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
*o = Candle{}
return nil
}
func candleBeforeUpsertHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
*o = Candle{}
return nil
}
func candleAfterUpsertHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
*o = Candle{}
return nil
}
func testCandlesHooks(t *testing.T) {
t.Parallel()
var err error
ctx := context.Background()
empty := &Candle{}
o := &Candle{}
seed := randomize.NewSeed()
if err = randomize.Struct(seed, o, candleDBTypes, false); err != nil {
t.Errorf("Unable to randomize Candle object: %s", err)
}
AddCandleHook(boil.BeforeInsertHook, candleBeforeInsertHook)
if err = o.doBeforeInsertHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doBeforeInsertHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected BeforeInsertHook function to empty object, but got: %#v", o)
}
candleBeforeInsertHooks = []CandleHook{}
AddCandleHook(boil.AfterInsertHook, candleAfterInsertHook)
if err = o.doAfterInsertHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doAfterInsertHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected AfterInsertHook function to empty object, but got: %#v", o)
}
candleAfterInsertHooks = []CandleHook{}
AddCandleHook(boil.AfterSelectHook, candleAfterSelectHook)
if err = o.doAfterSelectHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doAfterSelectHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected AfterSelectHook function to empty object, but got: %#v", o)
}
candleAfterSelectHooks = []CandleHook{}
AddCandleHook(boil.BeforeUpdateHook, candleBeforeUpdateHook)
if err = o.doBeforeUpdateHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doBeforeUpdateHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected BeforeUpdateHook function to empty object, but got: %#v", o)
}
candleBeforeUpdateHooks = []CandleHook{}
AddCandleHook(boil.AfterUpdateHook, candleAfterUpdateHook)
if err = o.doAfterUpdateHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doAfterUpdateHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected AfterUpdateHook function to empty object, but got: %#v", o)
}
candleAfterUpdateHooks = []CandleHook{}
AddCandleHook(boil.BeforeDeleteHook, candleBeforeDeleteHook)
if err = o.doBeforeDeleteHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doBeforeDeleteHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected BeforeDeleteHook function to empty object, but got: %#v", o)
}
candleBeforeDeleteHooks = []CandleHook{}
AddCandleHook(boil.AfterDeleteHook, candleAfterDeleteHook)
if err = o.doAfterDeleteHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doAfterDeleteHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected AfterDeleteHook function to empty object, but got: %#v", o)
}
candleAfterDeleteHooks = []CandleHook{}
AddCandleHook(boil.BeforeUpsertHook, candleBeforeUpsertHook)
if err = o.doBeforeUpsertHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doBeforeUpsertHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected BeforeUpsertHook function to empty object, but got: %#v", o)
}
candleBeforeUpsertHooks = []CandleHook{}
AddCandleHook(boil.AfterUpsertHook, candleAfterUpsertHook)
if err = o.doAfterUpsertHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doAfterUpsertHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected AfterUpsertHook function to empty object, but got: %#v", o)
}
candleAfterUpsertHooks = []CandleHook{}
}
func testCandlesInsert(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Candle{}
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
count, err := Candles().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 1 {
t.Error("want one record, got:", count)
}
}
func testCandlesInsertWhitelist(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Candle{}
if err = randomize.Struct(seed, o, candleDBTypes, true); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Whitelist(candleColumnsWithoutDefault...)); err != nil {
t.Error(err)
}
count, err := Candles().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 1 {
t.Error("want one record, got:", count)
}
}
func testCandleToOneExchangeUsingExchangeName(t *testing.T) {
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
var local Candle
var foreign Exchange
seed := randomize.NewSeed()
if err := randomize.Struct(seed, &local, candleDBTypes, false, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
if err := randomize.Struct(seed, &foreign, exchangeDBTypes, false, exchangeColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Exchange struct: %s", err)
}
if err := foreign.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
local.ExchangeNameID = foreign.ID
if err := local.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
check, err := local.ExchangeName().One(ctx, tx)
if err != nil {
t.Fatal(err)
}
if check.ID != foreign.ID {
t.Errorf("want: %v, got %v", foreign.ID, check.ID)
}
slice := CandleSlice{&local}
if err = local.L.LoadExchangeName(ctx, tx, false, (*[]*Candle)(&slice), nil); err != nil {
t.Fatal(err)
}
if local.R.ExchangeName == nil {
t.Error("struct should have been eager loaded")
}
local.R.ExchangeName = nil
if err = local.L.LoadExchangeName(ctx, tx, true, &local, nil); err != nil {
t.Fatal(err)
}
if local.R.ExchangeName == nil {
t.Error("struct should have been eager loaded")
}
}
func testCandleToOneSetOpExchangeUsingExchangeName(t *testing.T) {
var err error
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
var a Candle
var b, c Exchange
seed := randomize.NewSeed()
if err = randomize.Struct(seed, &a, candleDBTypes, false, strmangle.SetComplement(candlePrimaryKeyColumns, candleColumnsWithoutDefault)...); err != nil {
t.Fatal(err)
}
if err = randomize.Struct(seed, &b, exchangeDBTypes, false, strmangle.SetComplement(exchangePrimaryKeyColumns, exchangeColumnsWithoutDefault)...); err != nil {
t.Fatal(err)
}
if err = randomize.Struct(seed, &c, exchangeDBTypes, false, strmangle.SetComplement(exchangePrimaryKeyColumns, exchangeColumnsWithoutDefault)...); err != nil {
t.Fatal(err)
}
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
for i, x := range []*Exchange{&b, &c} {
err = a.SetExchangeName(ctx, tx, i != 0, x)
if err != nil {
t.Fatal(err)
}
if a.R.ExchangeName != x {
t.Error("relationship struct not set to correct value")
}
if x.R.ExchangeNameCandles[0] != &a {
t.Error("failed to append to foreign relationship struct")
}
if a.ExchangeNameID != x.ID {
t.Error("foreign key was wrong value", a.ExchangeNameID)
}
zero := reflect.Zero(reflect.TypeOf(a.ExchangeNameID))
reflect.Indirect(reflect.ValueOf(&a.ExchangeNameID)).Set(zero)
if err = a.Reload(ctx, tx); err != nil {
t.Fatal("failed to reload", err)
}
if a.ExchangeNameID != x.ID {
t.Error("foreign key was wrong value", a.ExchangeNameID, x.ID)
}
}
}
func testCandlesReload(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Candle{}
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if err = o.Reload(ctx, tx); err != nil {
t.Error(err)
}
}
func testCandlesReloadAll(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Candle{}
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
slice := CandleSlice{o}
if err = slice.ReloadAll(ctx, tx); err != nil {
t.Error(err)
}
}
func testCandlesSelect(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Candle{}
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
slice, err := Candles().All(ctx, tx)
if err != nil {
t.Error(err)
}
if len(slice) != 1 {
t.Error("want one record, got:", len(slice))
}
}
var (
candleDBTypes = map[string]string{`ID`: `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`}
_ = bytes.MinRead
)
func testCandlesUpdate(t *testing.T) {
t.Parallel()
if 0 == len(candlePrimaryKeyColumns) {
t.Skip("Skipping table with no primary key columns")
}
if len(candleAllColumns) == len(candlePrimaryKeyColumns) {
t.Skip("Skipping table with only primary key columns")
}
seed := randomize.NewSeed()
var err error
o := &Candle{}
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
count, err := Candles().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 1 {
t.Error("want one record, got:", count)
}
if err = randomize.Struct(seed, o, candleDBTypes, true, candlePrimaryKeyColumns...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
if rowsAff, err := o.Update(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
} else if rowsAff != 1 {
t.Error("should only affect one row but affected", rowsAff)
}
}
func testCandlesSliceUpdateAll(t *testing.T) {
t.Parallel()
if len(candleAllColumns) == len(candlePrimaryKeyColumns) {
t.Skip("Skipping table with only primary key columns")
}
seed := randomize.NewSeed()
var err error
o := &Candle{}
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
count, err := Candles().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 1 {
t.Error("want one record, got:", count)
}
if err = randomize.Struct(seed, o, candleDBTypes, true, candlePrimaryKeyColumns...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
// Remove Primary keys and unique columns from what we plan to update
var fields []string
if strmangle.StringSliceMatch(candleAllColumns, candlePrimaryKeyColumns) {
fields = candleAllColumns
} else {
fields = strmangle.SetComplement(
candleAllColumns,
candlePrimaryKeyColumns,
)
}
value := reflect.Indirect(reflect.ValueOf(o))
typ := reflect.TypeOf(o).Elem()
n := typ.NumField()
updateMap := M{}
for _, col := range fields {
for i := 0; i < n; i++ {
f := typ.Field(i)
if f.Tag.Get("boil") == col {
updateMap[col] = value.Field(i).Interface()
}
}
}
slice := CandleSlice{o}
if rowsAff, err := slice.UpdateAll(ctx, tx, updateMap); err != nil {
t.Error(err)
} else if rowsAff != 1 {
t.Error("wanted one record updated but got", rowsAff)
}
}
func testCandlesUpsert(t *testing.T) {
t.Parallel()
if len(candleAllColumns) == len(candlePrimaryKeyColumns) {
t.Skip("Skipping table with only primary key columns")
}
seed := randomize.NewSeed()
var err error
// Attempt the INSERT side of an UPSERT
o := Candle{}
if err = randomize.Struct(seed, &o, candleDBTypes, true); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Upsert(ctx, tx, false, nil, boil.Infer(), boil.Infer()); err != nil {
t.Errorf("Unable to upsert Candle: %s", err)
}
count, err := Candles().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 1 {
t.Error("want one record, got:", count)
}
// Attempt the UPDATE side of an UPSERT
if err = randomize.Struct(seed, &o, candleDBTypes, false, candlePrimaryKeyColumns...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
if err = o.Upsert(ctx, tx, true, nil, boil.Infer(), boil.Infer()); err != nil {
t.Errorf("Unable to upsert Candle: %s", err)
}
count, err = Candles().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 1 {
t.Error("want one record, got:", count)
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -7,6 +7,6 @@ import "testing"
func TestUpsert(t *testing.T) {
t.Run("AuditEvents", testAuditEventsUpsert)
t.Run("Exchanges", testExchangesUpsert)
t.Run("Scripts", testScriptsUpsert)
t.Run("WithdrawalHistories", testWithdrawalHistoriesUpsert)
}

View File

@@ -50,21 +50,6 @@ var WithdrawalCryptoColumns = struct {
// Generated where
type whereHelperfloat64 struct{ field string }
func (w whereHelperfloat64) EQ(x float64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) }
func (w whereHelperfloat64) NEQ(x float64) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.NEQ, x)
}
func (w whereHelperfloat64) LT(x float64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) }
func (w whereHelperfloat64) LTE(x float64) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.LTE, x)
}
func (w whereHelperfloat64) GT(x float64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) }
func (w whereHelperfloat64) GTE(x float64) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.GTE, x)
}
var WithdrawalCryptoWhere = struct {
ID whereHelperint64
WithdrawalCryptoID whereHelpernull_String

View File

@@ -111,8 +111,8 @@ type withdrawalFiatL struct{}
var (
withdrawalFiatAllColumns = []string{"id", "withdrawal_fiat_id", "bank_name", "bank_address", "bank_account_name", "bank_account_number", "bsb", "swift_code", "iban", "bank_code"}
withdrawalFiatColumnsWithoutDefault = []string{"withdrawal_fiat_id", "bank_name", "bank_address", "bank_account_name", "bank_account_number", "bsb", "swift_code", "iban", "bank_code"}
withdrawalFiatColumnsWithDefault = []string{"id"}
withdrawalFiatColumnsWithoutDefault = []string{"withdrawal_fiat_id", "bank_name", "bank_address", "bank_account_name", "bank_account_number", "bank_code"}
withdrawalFiatColumnsWithDefault = []string{"id", "bsb", "swift_code", "iban"}
withdrawalFiatPrimaryKeyColumns = []string{"id"}
)

View File

@@ -24,43 +24,43 @@ import (
// WithdrawalHistory is an object representing the database table.
type WithdrawalHistory struct {
ID string `boil:"id" json:"id" toml:"id" yaml:"id"`
Exchange string `boil:"exchange" json:"exchange" toml:"exchange" yaml:"exchange"`
ExchangeID string `boil:"exchange_id" json:"exchange_id" toml:"exchange_id" yaml:"exchange_id"`
Status string `boil:"status" json:"status" toml:"status" yaml:"status"`
Currency string `boil:"currency" json:"currency" toml:"currency" yaml:"currency"`
Amount float64 `boil:"amount" json:"amount" toml:"amount" yaml:"amount"`
Description null.String `boil:"description" json:"description,omitempty" toml:"description" yaml:"description,omitempty"`
WithdrawType int `boil:"withdraw_type" json:"withdraw_type" toml:"withdraw_type" yaml:"withdraw_type"`
CreatedAt time.Time `boil:"created_at" json:"created_at" toml:"created_at" yaml:"created_at"`
UpdatedAt time.Time `boil:"updated_at" json:"updated_at" toml:"updated_at" yaml:"updated_at"`
ID string `boil:"id" json:"id" toml:"id" yaml:"id"`
ExchangeID string `boil:"exchange_id" json:"exchange_id" toml:"exchange_id" yaml:"exchange_id"`
Status string `boil:"status" json:"status" toml:"status" yaml:"status"`
Currency string `boil:"currency" json:"currency" toml:"currency" yaml:"currency"`
Amount float64 `boil:"amount" json:"amount" toml:"amount" yaml:"amount"`
Description null.String `boil:"description" json:"description,omitempty" toml:"description" yaml:"description,omitempty"`
WithdrawType int `boil:"withdraw_type" json:"withdraw_type" toml:"withdraw_type" yaml:"withdraw_type"`
CreatedAt time.Time `boil:"created_at" json:"created_at" toml:"created_at" yaml:"created_at"`
UpdatedAt time.Time `boil:"updated_at" json:"updated_at" toml:"updated_at" yaml:"updated_at"`
ExchangeNameID string `boil:"exchange_name_id" json:"exchange_name_id" toml:"exchange_name_id" yaml:"exchange_name_id"`
R *withdrawalHistoryR `boil:"-" json:"-" toml:"-" yaml:"-"`
L withdrawalHistoryL `boil:"-" json:"-" toml:"-" yaml:"-"`
}
var WithdrawalHistoryColumns = struct {
ID string
Exchange string
ExchangeID string
Status string
Currency string
Amount string
Description string
WithdrawType string
CreatedAt string
UpdatedAt string
ID string
ExchangeID string
Status string
Currency string
Amount string
Description string
WithdrawType string
CreatedAt string
UpdatedAt string
ExchangeNameID string
}{
ID: "id",
Exchange: "exchange",
ExchangeID: "exchange_id",
Status: "status",
Currency: "currency",
Amount: "amount",
Description: "description",
WithdrawType: "withdraw_type",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
ID: "id",
ExchangeID: "exchange_id",
Status: "status",
Currency: "currency",
Amount: "amount",
Description: "description",
WithdrawType: "withdraw_type",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
ExchangeNameID: "exchange_name_id",
}
// Generated where
@@ -82,40 +82,43 @@ func (w whereHelperint) IN(slice []int) qm.QueryMod {
}
var WithdrawalHistoryWhere = struct {
ID whereHelperstring
Exchange whereHelperstring
ExchangeID whereHelperstring
Status whereHelperstring
Currency whereHelperstring
Amount whereHelperfloat64
Description whereHelpernull_String
WithdrawType whereHelperint
CreatedAt whereHelpertime_Time
UpdatedAt whereHelpertime_Time
ID whereHelperstring
ExchangeID whereHelperstring
Status whereHelperstring
Currency whereHelperstring
Amount whereHelperfloat64
Description whereHelpernull_String
WithdrawType whereHelperint
CreatedAt whereHelpertime_Time
UpdatedAt whereHelpertime_Time
ExchangeNameID whereHelperstring
}{
ID: whereHelperstring{field: "\"withdrawal_history\".\"id\""},
Exchange: whereHelperstring{field: "\"withdrawal_history\".\"exchange\""},
ExchangeID: whereHelperstring{field: "\"withdrawal_history\".\"exchange_id\""},
Status: whereHelperstring{field: "\"withdrawal_history\".\"status\""},
Currency: whereHelperstring{field: "\"withdrawal_history\".\"currency\""},
Amount: whereHelperfloat64{field: "\"withdrawal_history\".\"amount\""},
Description: whereHelpernull_String{field: "\"withdrawal_history\".\"description\""},
WithdrawType: whereHelperint{field: "\"withdrawal_history\".\"withdraw_type\""},
CreatedAt: whereHelpertime_Time{field: "\"withdrawal_history\".\"created_at\""},
UpdatedAt: whereHelpertime_Time{field: "\"withdrawal_history\".\"updated_at\""},
ID: whereHelperstring{field: "\"withdrawal_history\".\"id\""},
ExchangeID: whereHelperstring{field: "\"withdrawal_history\".\"exchange_id\""},
Status: whereHelperstring{field: "\"withdrawal_history\".\"status\""},
Currency: whereHelperstring{field: "\"withdrawal_history\".\"currency\""},
Amount: whereHelperfloat64{field: "\"withdrawal_history\".\"amount\""},
Description: whereHelpernull_String{field: "\"withdrawal_history\".\"description\""},
WithdrawType: whereHelperint{field: "\"withdrawal_history\".\"withdraw_type\""},
CreatedAt: whereHelpertime_Time{field: "\"withdrawal_history\".\"created_at\""},
UpdatedAt: whereHelpertime_Time{field: "\"withdrawal_history\".\"updated_at\""},
ExchangeNameID: whereHelperstring{field: "\"withdrawal_history\".\"exchange_name_id\""},
}
// WithdrawalHistoryRels is where relationship names are stored.
var WithdrawalHistoryRels = struct {
ExchangeName string
WithdrawalCryptoWithdrawalCryptos string
WithdrawalFiatWithdrawalFiats string
}{
ExchangeName: "ExchangeName",
WithdrawalCryptoWithdrawalCryptos: "WithdrawalCryptoWithdrawalCryptos",
WithdrawalFiatWithdrawalFiats: "WithdrawalFiatWithdrawalFiats",
}
// withdrawalHistoryR is where relationships are stored.
type withdrawalHistoryR struct {
ExchangeName *Exchange
WithdrawalCryptoWithdrawalCryptos WithdrawalCryptoSlice
WithdrawalFiatWithdrawalFiats WithdrawalFiatSlice
}
@@ -129,8 +132,8 @@ func (*withdrawalHistoryR) NewStruct() *withdrawalHistoryR {
type withdrawalHistoryL struct{}
var (
withdrawalHistoryAllColumns = []string{"id", "exchange", "exchange_id", "status", "currency", "amount", "description", "withdraw_type", "created_at", "updated_at"}
withdrawalHistoryColumnsWithoutDefault = []string{"exchange", "exchange_id", "status", "currency", "amount", "description", "withdraw_type"}
withdrawalHistoryAllColumns = []string{"id", "exchange_id", "status", "currency", "amount", "description", "withdraw_type", "created_at", "updated_at", "exchange_name_id"}
withdrawalHistoryColumnsWithoutDefault = []string{"exchange_id", "status", "currency", "amount", "description", "withdraw_type", "exchange_name_id"}
withdrawalHistoryColumnsWithDefault = []string{"id", "created_at", "updated_at"}
withdrawalHistoryPrimaryKeyColumns = []string{"id"}
)
@@ -410,6 +413,20 @@ func (q withdrawalHistoryQuery) Exists(ctx context.Context, exec boil.ContextExe
return count > 0, nil
}
// ExchangeName pointed to by the foreign key.
func (o *WithdrawalHistory) ExchangeName(mods ...qm.QueryMod) exchangeQuery {
queryMods := []qm.QueryMod{
qm.Where("\"id\" = ?", o.ExchangeNameID),
}
queryMods = append(queryMods, mods...)
query := Exchanges(queryMods...)
queries.SetFrom(query.Query, "\"exchange\"")
return query
}
// WithdrawalCryptoWithdrawalCryptos retrieves all the withdrawal_crypto's WithdrawalCryptos with an executor via withdrawal_crypto_id column.
func (o *WithdrawalHistory) WithdrawalCryptoWithdrawalCryptos(mods ...qm.QueryMod) withdrawalCryptoQuery {
var queryMods []qm.QueryMod
@@ -452,6 +469,107 @@ func (o *WithdrawalHistory) WithdrawalFiatWithdrawalFiats(mods ...qm.QueryMod) w
return query
}
// LoadExchangeName allows an eager lookup of values, cached into the
// loaded structs of the objects. This is for an N-1 relationship.
func (withdrawalHistoryL) LoadExchangeName(ctx context.Context, e boil.ContextExecutor, singular bool, maybeWithdrawalHistory interface{}, mods queries.Applicator) error {
var slice []*WithdrawalHistory
var object *WithdrawalHistory
if singular {
object = maybeWithdrawalHistory.(*WithdrawalHistory)
} else {
slice = *maybeWithdrawalHistory.(*[]*WithdrawalHistory)
}
args := make([]interface{}, 0, 1)
if singular {
if object.R == nil {
object.R = &withdrawalHistoryR{}
}
args = append(args, object.ExchangeNameID)
} else {
Outer:
for _, obj := range slice {
if obj.R == nil {
obj.R = &withdrawalHistoryR{}
}
for _, a := range args {
if a == obj.ExchangeNameID {
continue Outer
}
}
args = append(args, obj.ExchangeNameID)
}
}
if len(args) == 0 {
return nil
}
query := NewQuery(qm.From(`exchange`), qm.WhereIn(`exchange.id in ?`, args...))
if mods != nil {
mods.Apply(query)
}
results, err := query.QueryContext(ctx, e)
if err != nil {
return errors.Wrap(err, "failed to eager load Exchange")
}
var resultSlice []*Exchange
if err = queries.Bind(results, &resultSlice); err != nil {
return errors.Wrap(err, "failed to bind eager loaded slice Exchange")
}
if err = results.Close(); err != nil {
return errors.Wrap(err, "failed to close results of eager load for exchange")
}
if err = results.Err(); err != nil {
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for exchange")
}
if len(withdrawalHistoryAfterSelectHooks) != 0 {
for _, obj := range resultSlice {
if err := obj.doAfterSelectHooks(ctx, e); err != nil {
return err
}
}
}
if len(resultSlice) == 0 {
return nil
}
if singular {
foreign := resultSlice[0]
object.R.ExchangeName = foreign
if foreign.R == nil {
foreign.R = &exchangeR{}
}
foreign.R.ExchangeNameWithdrawalHistories = append(foreign.R.ExchangeNameWithdrawalHistories, object)
return nil
}
for _, local := range slice {
for _, foreign := range resultSlice {
if local.ExchangeNameID == foreign.ID {
local.R.ExchangeName = foreign
if foreign.R == nil {
foreign.R = &exchangeR{}
}
foreign.R.ExchangeNameWithdrawalHistories = append(foreign.R.ExchangeNameWithdrawalHistories, local)
break
}
}
}
return nil
}
// LoadWithdrawalCryptoWithdrawalCryptos allows an eager lookup of values, cached into the
// loaded structs of the objects. This is for a 1-M or N-M relationship.
func (withdrawalHistoryL) LoadWithdrawalCryptoWithdrawalCryptos(ctx context.Context, e boil.ContextExecutor, singular bool, maybeWithdrawalHistory interface{}, mods queries.Applicator) error {
@@ -642,6 +760,53 @@ func (withdrawalHistoryL) LoadWithdrawalFiatWithdrawalFiats(ctx context.Context,
return nil
}
// SetExchangeName of the withdrawalHistory to the related item.
// Sets o.R.ExchangeName to related.
// Adds o to related.R.ExchangeNameWithdrawalHistories.
func (o *WithdrawalHistory) SetExchangeName(ctx context.Context, exec boil.ContextExecutor, insert bool, related *Exchange) error {
var err error
if insert {
if err = related.Insert(ctx, exec, boil.Infer()); err != nil {
return errors.Wrap(err, "failed to insert into foreign table")
}
}
updateQuery := fmt.Sprintf(
"UPDATE \"withdrawal_history\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 1, []string{"exchange_name_id"}),
strmangle.WhereClause("\"", "\"", 2, withdrawalHistoryPrimaryKeyColumns),
)
values := []interface{}{related.ID, o.ID}
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, updateQuery)
fmt.Fprintln(boil.DebugWriter, values)
}
if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil {
return errors.Wrap(err, "failed to update local table")
}
o.ExchangeNameID = related.ID
if o.R == nil {
o.R = &withdrawalHistoryR{
ExchangeName: related,
}
} else {
o.R.ExchangeName = related
}
if related.R == nil {
related.R = &exchangeR{
ExchangeNameWithdrawalHistories: WithdrawalHistorySlice{o},
}
} else {
related.R.ExchangeNameWithdrawalHistories = append(related.R.ExchangeNameWithdrawalHistories, o)
}
return nil
}
// AddWithdrawalCryptoWithdrawalCryptos adds the given related objects to the existing relationships
// of the withdrawal_history, optionally inserting them as new records.
// Appends related to o.R.WithdrawalCryptoWithdrawalCryptos.

View File

@@ -1150,6 +1150,115 @@ func testWithdrawalHistoryToManyRemoveOpWithdrawalFiatWithdrawalFiats(t *testing
}
}
func testWithdrawalHistoryToOneExchangeUsingExchangeName(t *testing.T) {
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
var local WithdrawalHistory
var foreign Exchange
seed := randomize.NewSeed()
if err := randomize.Struct(seed, &local, withdrawalHistoryDBTypes, false, withdrawalHistoryColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
}
if err := randomize.Struct(seed, &foreign, exchangeDBTypes, false, exchangeColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Exchange struct: %s", err)
}
if err := foreign.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
local.ExchangeNameID = foreign.ID
if err := local.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
check, err := local.ExchangeName().One(ctx, tx)
if err != nil {
t.Fatal(err)
}
if check.ID != foreign.ID {
t.Errorf("want: %v, got %v", foreign.ID, check.ID)
}
slice := WithdrawalHistorySlice{&local}
if err = local.L.LoadExchangeName(ctx, tx, false, (*[]*WithdrawalHistory)(&slice), nil); err != nil {
t.Fatal(err)
}
if local.R.ExchangeName == nil {
t.Error("struct should have been eager loaded")
}
local.R.ExchangeName = nil
if err = local.L.LoadExchangeName(ctx, tx, true, &local, nil); err != nil {
t.Fatal(err)
}
if local.R.ExchangeName == nil {
t.Error("struct should have been eager loaded")
}
}
func testWithdrawalHistoryToOneSetOpExchangeUsingExchangeName(t *testing.T) {
var err error
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
var a WithdrawalHistory
var b, c Exchange
seed := randomize.NewSeed()
if err = randomize.Struct(seed, &a, withdrawalHistoryDBTypes, false, strmangle.SetComplement(withdrawalHistoryPrimaryKeyColumns, withdrawalHistoryColumnsWithoutDefault)...); err != nil {
t.Fatal(err)
}
if err = randomize.Struct(seed, &b, exchangeDBTypes, false, strmangle.SetComplement(exchangePrimaryKeyColumns, exchangeColumnsWithoutDefault)...); err != nil {
t.Fatal(err)
}
if err = randomize.Struct(seed, &c, exchangeDBTypes, false, strmangle.SetComplement(exchangePrimaryKeyColumns, exchangeColumnsWithoutDefault)...); err != nil {
t.Fatal(err)
}
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
for i, x := range []*Exchange{&b, &c} {
err = a.SetExchangeName(ctx, tx, i != 0, x)
if err != nil {
t.Fatal(err)
}
if a.R.ExchangeName != x {
t.Error("relationship struct not set to correct value")
}
if x.R.ExchangeNameWithdrawalHistories[0] != &a {
t.Error("failed to append to foreign relationship struct")
}
if a.ExchangeNameID != x.ID {
t.Error("foreign key was wrong value", a.ExchangeNameID)
}
zero := reflect.Zero(reflect.TypeOf(a.ExchangeNameID))
reflect.Indirect(reflect.ValueOf(&a.ExchangeNameID)).Set(zero)
if err = a.Reload(ctx, tx); err != nil {
t.Fatal("failed to reload", err)
}
if a.ExchangeNameID != x.ID {
t.Error("foreign key was wrong value", a.ExchangeNameID, x.ID)
}
}
}
func testWithdrawalHistoriesReload(t *testing.T) {
t.Parallel()
@@ -1224,7 +1333,7 @@ func testWithdrawalHistoriesSelect(t *testing.T) {
}
var (
withdrawalHistoryDBTypes = map[string]string{`ID`: `uuid`, `Exchange`: `text`, `ExchangeID`: `text`, `Status`: `character varying`, `Currency`: `text`, `Amount`: `double precision`, `Description`: `text`, `WithdrawType`: `integer`, `CreatedAt`: `timestamp without time zone`, `UpdatedAt`: `timestamp without time zone`}
withdrawalHistoryDBTypes = map[string]string{`ID`: `uuid`, `ExchangeID`: `text`, `Status`: `character varying`, `Currency`: `text`, `Amount`: `double precision`, `Description`: `text`, `WithdrawType`: `integer`, `CreatedAt`: `timestamp without time zone`, `UpdatedAt`: `timestamp without time zone`, `ExchangeNameID`: `uuid`}
_ = bytes.MinRead
)

View File

@@ -13,6 +13,8 @@ import "testing"
// Separating the tests thusly grants avoidance of Postgres deadlocks.
func TestParent(t *testing.T) {
t.Run("AuditEvents", testAuditEvents)
t.Run("Candles", testCandles)
t.Run("Exchanges", testExchanges)
t.Run("Scripts", testScripts)
t.Run("ScriptExecutions", testScriptExecutions)
t.Run("WithdrawalCryptos", testWithdrawalCryptos)
@@ -22,6 +24,8 @@ func TestParent(t *testing.T) {
func TestDelete(t *testing.T) {
t.Run("AuditEvents", testAuditEventsDelete)
t.Run("Candles", testCandlesDelete)
t.Run("Exchanges", testExchangesDelete)
t.Run("Scripts", testScriptsDelete)
t.Run("ScriptExecutions", testScriptExecutionsDelete)
t.Run("WithdrawalCryptos", testWithdrawalCryptosDelete)
@@ -31,6 +35,8 @@ func TestDelete(t *testing.T) {
func TestQueryDeleteAll(t *testing.T) {
t.Run("AuditEvents", testAuditEventsQueryDeleteAll)
t.Run("Candles", testCandlesQueryDeleteAll)
t.Run("Exchanges", testExchangesQueryDeleteAll)
t.Run("Scripts", testScriptsQueryDeleteAll)
t.Run("ScriptExecutions", testScriptExecutionsQueryDeleteAll)
t.Run("WithdrawalCryptos", testWithdrawalCryptosQueryDeleteAll)
@@ -40,6 +46,8 @@ func TestQueryDeleteAll(t *testing.T) {
func TestSliceDeleteAll(t *testing.T) {
t.Run("AuditEvents", testAuditEventsSliceDeleteAll)
t.Run("Candles", testCandlesSliceDeleteAll)
t.Run("Exchanges", testExchangesSliceDeleteAll)
t.Run("Scripts", testScriptsSliceDeleteAll)
t.Run("ScriptExecutions", testScriptExecutionsSliceDeleteAll)
t.Run("WithdrawalCryptos", testWithdrawalCryptosSliceDeleteAll)
@@ -49,6 +57,8 @@ func TestSliceDeleteAll(t *testing.T) {
func TestExists(t *testing.T) {
t.Run("AuditEvents", testAuditEventsExists)
t.Run("Candles", testCandlesExists)
t.Run("Exchanges", testExchangesExists)
t.Run("Scripts", testScriptsExists)
t.Run("ScriptExecutions", testScriptExecutionsExists)
t.Run("WithdrawalCryptos", testWithdrawalCryptosExists)
@@ -58,6 +68,8 @@ func TestExists(t *testing.T) {
func TestFind(t *testing.T) {
t.Run("AuditEvents", testAuditEventsFind)
t.Run("Candles", testCandlesFind)
t.Run("Exchanges", testExchangesFind)
t.Run("Scripts", testScriptsFind)
t.Run("ScriptExecutions", testScriptExecutionsFind)
t.Run("WithdrawalCryptos", testWithdrawalCryptosFind)
@@ -67,6 +79,8 @@ func TestFind(t *testing.T) {
func TestBind(t *testing.T) {
t.Run("AuditEvents", testAuditEventsBind)
t.Run("Candles", testCandlesBind)
t.Run("Exchanges", testExchangesBind)
t.Run("Scripts", testScriptsBind)
t.Run("ScriptExecutions", testScriptExecutionsBind)
t.Run("WithdrawalCryptos", testWithdrawalCryptosBind)
@@ -76,6 +90,8 @@ func TestBind(t *testing.T) {
func TestOne(t *testing.T) {
t.Run("AuditEvents", testAuditEventsOne)
t.Run("Candles", testCandlesOne)
t.Run("Exchanges", testExchangesOne)
t.Run("Scripts", testScriptsOne)
t.Run("ScriptExecutions", testScriptExecutionsOne)
t.Run("WithdrawalCryptos", testWithdrawalCryptosOne)
@@ -85,6 +101,8 @@ func TestOne(t *testing.T) {
func TestAll(t *testing.T) {
t.Run("AuditEvents", testAuditEventsAll)
t.Run("Candles", testCandlesAll)
t.Run("Exchanges", testExchangesAll)
t.Run("Scripts", testScriptsAll)
t.Run("ScriptExecutions", testScriptExecutionsAll)
t.Run("WithdrawalCryptos", testWithdrawalCryptosAll)
@@ -94,6 +112,8 @@ func TestAll(t *testing.T) {
func TestCount(t *testing.T) {
t.Run("AuditEvents", testAuditEventsCount)
t.Run("Candles", testCandlesCount)
t.Run("Exchanges", testExchangesCount)
t.Run("Scripts", testScriptsCount)
t.Run("ScriptExecutions", testScriptExecutionsCount)
t.Run("WithdrawalCryptos", testWithdrawalCryptosCount)
@@ -103,6 +123,8 @@ func TestCount(t *testing.T) {
func TestHooks(t *testing.T) {
t.Run("AuditEvents", testAuditEventsHooks)
t.Run("Candles", testCandlesHooks)
t.Run("Exchanges", testExchangesHooks)
t.Run("Scripts", testScriptsHooks)
t.Run("ScriptExecutions", testScriptExecutionsHooks)
t.Run("WithdrawalCryptos", testWithdrawalCryptosHooks)
@@ -113,6 +135,10 @@ func TestHooks(t *testing.T) {
func TestInsert(t *testing.T) {
t.Run("AuditEvents", testAuditEventsInsert)
t.Run("AuditEvents", testAuditEventsInsertWhitelist)
t.Run("Candles", testCandlesInsert)
t.Run("Candles", testCandlesInsertWhitelist)
t.Run("Exchanges", testExchangesInsert)
t.Run("Exchanges", testExchangesInsertWhitelist)
t.Run("Scripts", testScriptsInsert)
t.Run("Scripts", testScriptsInsertWhitelist)
t.Run("ScriptExecutions", testScriptExecutionsInsert)
@@ -128,18 +154,23 @@ func TestInsert(t *testing.T) {
// TestToOne tests cannot be run in parallel
// or deadlocks can occur.
func TestToOne(t *testing.T) {
t.Run("CandleToExchangeUsingExchangeName", testCandleToOneExchangeUsingExchangeName)
t.Run("ScriptExecutionToScriptUsingScript", testScriptExecutionToOneScriptUsingScript)
t.Run("WithdrawalCryptoToWithdrawalHistoryUsingWithdrawalHistory", testWithdrawalCryptoToOneWithdrawalHistoryUsingWithdrawalHistory)
t.Run("WithdrawalFiatToWithdrawalHistoryUsingWithdrawalHistory", testWithdrawalFiatToOneWithdrawalHistoryUsingWithdrawalHistory)
t.Run("WithdrawalHistoryToExchangeUsingExchangeName", testWithdrawalHistoryToOneExchangeUsingExchangeName)
}
// TestOneToOne tests cannot be run in parallel
// or deadlocks can occur.
func TestOneToOne(t *testing.T) {}
func TestOneToOne(t *testing.T) {
t.Run("ExchangeToCandleUsingExchangeNameCandle", testExchangeOneToOneCandleUsingExchangeNameCandle)
}
// TestToMany tests cannot be run in parallel
// or deadlocks can occur.
func TestToMany(t *testing.T) {
t.Run("ExchangeToExchangeNameWithdrawalHistories", testExchangeToManyExchangeNameWithdrawalHistories)
t.Run("ScriptToScriptExecutions", testScriptToManyScriptExecutions)
t.Run("WithdrawalHistoryToWithdrawalCryptos", testWithdrawalHistoryToManyWithdrawalCryptos)
t.Run("WithdrawalHistoryToWithdrawalFiats", testWithdrawalHistoryToManyWithdrawalFiats)
@@ -148,9 +179,11 @@ func TestToMany(t *testing.T) {
// TestToOneSet tests cannot be run in parallel
// or deadlocks can occur.
func TestToOneSet(t *testing.T) {
t.Run("CandleToExchangeUsingExchangeNameCandle", testCandleToOneSetOpExchangeUsingExchangeName)
t.Run("ScriptExecutionToScriptUsingScriptExecutions", testScriptExecutionToOneSetOpScriptUsingScript)
t.Run("WithdrawalCryptoToWithdrawalHistoryUsingWithdrawalCryptos", testWithdrawalCryptoToOneSetOpWithdrawalHistoryUsingWithdrawalHistory)
t.Run("WithdrawalFiatToWithdrawalHistoryUsingWithdrawalFiats", testWithdrawalFiatToOneSetOpWithdrawalHistoryUsingWithdrawalHistory)
t.Run("WithdrawalHistoryToExchangeUsingExchangeNameWithdrawalHistories", testWithdrawalHistoryToOneSetOpExchangeUsingExchangeName)
}
// TestToOneRemove tests cannot be run in parallel
@@ -159,7 +192,9 @@ func TestToOneRemove(t *testing.T) {}
// TestOneToOneSet tests cannot be run in parallel
// or deadlocks can occur.
func TestOneToOneSet(t *testing.T) {}
func TestOneToOneSet(t *testing.T) {
t.Run("ExchangeToCandleUsingExchangeNameCandle", testExchangeOneToOneSetOpCandleUsingExchangeNameCandle)
}
// TestOneToOneRemove tests cannot be run in parallel
// or deadlocks can occur.
@@ -168,6 +203,7 @@ func TestOneToOneRemove(t *testing.T) {}
// TestToManyAdd tests cannot be run in parallel
// or deadlocks can occur.
func TestToManyAdd(t *testing.T) {
t.Run("ExchangeToExchangeNameWithdrawalHistories", testExchangeToManyAddOpExchangeNameWithdrawalHistories)
t.Run("ScriptToScriptExecutions", testScriptToManyAddOpScriptExecutions)
t.Run("WithdrawalHistoryToWithdrawalCryptos", testWithdrawalHistoryToManyAddOpWithdrawalCryptos)
t.Run("WithdrawalHistoryToWithdrawalFiats", testWithdrawalHistoryToManyAddOpWithdrawalFiats)
@@ -183,6 +219,8 @@ func TestToManyRemove(t *testing.T) {}
func TestReload(t *testing.T) {
t.Run("AuditEvents", testAuditEventsReload)
t.Run("Candles", testCandlesReload)
t.Run("Exchanges", testExchangesReload)
t.Run("Scripts", testScriptsReload)
t.Run("ScriptExecutions", testScriptExecutionsReload)
t.Run("WithdrawalCryptos", testWithdrawalCryptosReload)
@@ -192,6 +230,8 @@ func TestReload(t *testing.T) {
func TestReloadAll(t *testing.T) {
t.Run("AuditEvents", testAuditEventsReloadAll)
t.Run("Candles", testCandlesReloadAll)
t.Run("Exchanges", testExchangesReloadAll)
t.Run("Scripts", testScriptsReloadAll)
t.Run("ScriptExecutions", testScriptExecutionsReloadAll)
t.Run("WithdrawalCryptos", testWithdrawalCryptosReloadAll)
@@ -201,6 +241,8 @@ func TestReloadAll(t *testing.T) {
func TestSelect(t *testing.T) {
t.Run("AuditEvents", testAuditEventsSelect)
t.Run("Candles", testCandlesSelect)
t.Run("Exchanges", testExchangesSelect)
t.Run("Scripts", testScriptsSelect)
t.Run("ScriptExecutions", testScriptExecutionsSelect)
t.Run("WithdrawalCryptos", testWithdrawalCryptosSelect)
@@ -210,6 +252,8 @@ func TestSelect(t *testing.T) {
func TestUpdate(t *testing.T) {
t.Run("AuditEvents", testAuditEventsUpdate)
t.Run("Candles", testCandlesUpdate)
t.Run("Exchanges", testExchangesUpdate)
t.Run("Scripts", testScriptsUpdate)
t.Run("ScriptExecutions", testScriptExecutionsUpdate)
t.Run("WithdrawalCryptos", testWithdrawalCryptosUpdate)
@@ -219,6 +263,8 @@ func TestUpdate(t *testing.T) {
func TestSliceUpdateAll(t *testing.T) {
t.Run("AuditEvents", testAuditEventsSliceUpdateAll)
t.Run("Candles", testCandlesSliceUpdateAll)
t.Run("Exchanges", testExchangesSliceUpdateAll)
t.Run("Scripts", testScriptsSliceUpdateAll)
t.Run("ScriptExecutions", testScriptExecutionsSliceUpdateAll)
t.Run("WithdrawalCryptos", testWithdrawalCryptosSliceUpdateAll)

View File

@@ -5,6 +5,8 @@ package sqlite3
var TableNames = struct {
AuditEvent string
Candle string
Exchange string
Script string
ScriptExecution string
WithdrawalCrypto string
@@ -12,6 +14,8 @@ var TableNames = struct {
WithdrawalHistory string
}{
AuditEvent: "audit_event",
Candle: "candle",
Exchange: "exchange",
Script: "script",
ScriptExecution: "script_execution",
WithdrawalCrypto: "withdrawal_crypto",

View File

@@ -0,0 +1,996 @@
// Code generated by SQLBoiler 3.5.0-gct (https://github.com/thrasher-corp/sqlboiler). DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package sqlite3
import (
"context"
"database/sql"
"fmt"
"reflect"
"strings"
"sync"
"time"
"github.com/pkg/errors"
"github.com/thrasher-corp/sqlboiler/boil"
"github.com/thrasher-corp/sqlboiler/queries"
"github.com/thrasher-corp/sqlboiler/queries/qm"
"github.com/thrasher-corp/sqlboiler/queries/qmhelper"
"github.com/thrasher-corp/sqlboiler/strmangle"
)
// Candle is an object representing the database table.
type Candle struct {
ID string `boil:"id" json:"id" toml:"id" yaml:"id"`
ExchangeNameID string `boil:"exchange_name_id" json:"exchange_name_id" toml:"exchange_name_id" yaml:"exchange_name_id"`
Base string `boil:"Base" json:"Base" toml:"Base" yaml:"Base"`
Quote string `boil:"Quote" json:"Quote" toml:"Quote" yaml:"Quote"`
Interval string `boil:"Interval" json:"Interval" toml:"Interval" yaml:"Interval"`
Timestamp string `boil:"Timestamp" json:"Timestamp" toml:"Timestamp" yaml:"Timestamp"`
Open float64 `boil:"Open" json:"Open" toml:"Open" yaml:"Open"`
High float64 `boil:"High" json:"High" toml:"High" yaml:"High"`
Low float64 `boil:"Low" json:"Low" toml:"Low" yaml:"Low"`
Close float64 `boil:"Close" json:"Close" toml:"Close" yaml:"Close"`
Volume float64 `boil:"Volume" json:"Volume" toml:"Volume" yaml:"Volume"`
Asset string `boil:"Asset" json:"Asset" toml:"Asset" yaml:"Asset"`
R *candleR `boil:"-" json:"-" toml:"-" yaml:"-"`
L candleL `boil:"-" json:"-" toml:"-" yaml:"-"`
}
var CandleColumns = struct {
ID string
ExchangeNameID string
Base string
Quote string
Interval string
Timestamp string
Open string
High string
Low string
Close string
Volume string
Asset string
}{
ID: "id",
ExchangeNameID: "exchange_name_id",
Base: "Base",
Quote: "Quote",
Interval: "Interval",
Timestamp: "Timestamp",
Open: "Open",
High: "High",
Low: "Low",
Close: "Close",
Volume: "Volume",
Asset: "Asset",
}
// Generated where
type whereHelperfloat64 struct{ field string }
func (w whereHelperfloat64) EQ(x float64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) }
func (w whereHelperfloat64) NEQ(x float64) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.NEQ, x)
}
func (w whereHelperfloat64) LT(x float64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) }
func (w whereHelperfloat64) LTE(x float64) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.LTE, x)
}
func (w whereHelperfloat64) GT(x float64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) }
func (w whereHelperfloat64) GTE(x float64) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.GTE, x)
}
var CandleWhere = struct {
ID whereHelperstring
ExchangeNameID whereHelperstring
Base whereHelperstring
Quote whereHelperstring
Interval whereHelperstring
Timestamp whereHelperstring
Open whereHelperfloat64
High whereHelperfloat64
Low whereHelperfloat64
Close whereHelperfloat64
Volume whereHelperfloat64
Asset whereHelperstring
}{
ID: whereHelperstring{field: "\"candle\".\"id\""},
ExchangeNameID: whereHelperstring{field: "\"candle\".\"exchange_name_id\""},
Base: whereHelperstring{field: "\"candle\".\"Base\""},
Quote: whereHelperstring{field: "\"candle\".\"Quote\""},
Interval: whereHelperstring{field: "\"candle\".\"Interval\""},
Timestamp: whereHelperstring{field: "\"candle\".\"Timestamp\""},
Open: whereHelperfloat64{field: "\"candle\".\"Open\""},
High: whereHelperfloat64{field: "\"candle\".\"High\""},
Low: whereHelperfloat64{field: "\"candle\".\"Low\""},
Close: whereHelperfloat64{field: "\"candle\".\"Close\""},
Volume: whereHelperfloat64{field: "\"candle\".\"Volume\""},
Asset: whereHelperstring{field: "\"candle\".\"Asset\""},
}
// CandleRels is where relationship names are stored.
var CandleRels = struct {
ExchangeName string
}{
ExchangeName: "ExchangeName",
}
// candleR is where relationships are stored.
type candleR struct {
ExchangeName *Exchange
}
// NewStruct creates a new relationship struct
func (*candleR) NewStruct() *candleR {
return &candleR{}
}
// candleL is where Load methods for each relationship are stored.
type candleL struct{}
var (
candleAllColumns = []string{"id", "exchange_name_id", "Base", "Quote", "Interval", "Timestamp", "Open", "High", "Low", "Close", "Volume", "Asset"}
candleColumnsWithoutDefault = []string{"id", "exchange_name_id", "Base", "Quote", "Interval", "Timestamp", "Open", "High", "Low", "Close", "Volume", "Asset"}
candleColumnsWithDefault = []string{}
candlePrimaryKeyColumns = []string{"id"}
)
type (
// CandleSlice is an alias for a slice of pointers to Candle.
// This should generally be used opposed to []Candle.
CandleSlice []*Candle
// CandleHook is the signature for custom Candle hook methods
CandleHook func(context.Context, boil.ContextExecutor, *Candle) error
candleQuery struct {
*queries.Query
}
)
// Cache for insert, update and upsert
var (
candleType = reflect.TypeOf(&Candle{})
candleMapping = queries.MakeStructMapping(candleType)
candlePrimaryKeyMapping, _ = queries.BindMapping(candleType, candleMapping, candlePrimaryKeyColumns)
candleInsertCacheMut sync.RWMutex
candleInsertCache = make(map[string]insertCache)
candleUpdateCacheMut sync.RWMutex
candleUpdateCache = make(map[string]updateCache)
candleUpsertCacheMut sync.RWMutex
candleUpsertCache = make(map[string]insertCache)
)
var (
// Force time package dependency for automated UpdatedAt/CreatedAt.
_ = time.Second
// Force qmhelper dependency for where clause generation (which doesn't
// always happen)
_ = qmhelper.Where
)
var candleBeforeInsertHooks []CandleHook
var candleBeforeUpdateHooks []CandleHook
var candleBeforeDeleteHooks []CandleHook
var candleBeforeUpsertHooks []CandleHook
var candleAfterInsertHooks []CandleHook
var candleAfterSelectHooks []CandleHook
var candleAfterUpdateHooks []CandleHook
var candleAfterDeleteHooks []CandleHook
var candleAfterUpsertHooks []CandleHook
// doBeforeInsertHooks executes all "before insert" hooks.
func (o *Candle) doBeforeInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range candleBeforeInsertHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doBeforeUpdateHooks executes all "before Update" hooks.
func (o *Candle) doBeforeUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range candleBeforeUpdateHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doBeforeDeleteHooks executes all "before Delete" hooks.
func (o *Candle) doBeforeDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range candleBeforeDeleteHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doBeforeUpsertHooks executes all "before Upsert" hooks.
func (o *Candle) doBeforeUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range candleBeforeUpsertHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doAfterInsertHooks executes all "after Insert" hooks.
func (o *Candle) doAfterInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range candleAfterInsertHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doAfterSelectHooks executes all "after Select" hooks.
func (o *Candle) doAfterSelectHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range candleAfterSelectHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doAfterUpdateHooks executes all "after Update" hooks.
func (o *Candle) doAfterUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range candleAfterUpdateHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doAfterDeleteHooks executes all "after Delete" hooks.
func (o *Candle) doAfterDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range candleAfterDeleteHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doAfterUpsertHooks executes all "after Upsert" hooks.
func (o *Candle) doAfterUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range candleAfterUpsertHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// AddCandleHook registers your hook function for all future operations.
func AddCandleHook(hookPoint boil.HookPoint, candleHook CandleHook) {
switch hookPoint {
case boil.BeforeInsertHook:
candleBeforeInsertHooks = append(candleBeforeInsertHooks, candleHook)
case boil.BeforeUpdateHook:
candleBeforeUpdateHooks = append(candleBeforeUpdateHooks, candleHook)
case boil.BeforeDeleteHook:
candleBeforeDeleteHooks = append(candleBeforeDeleteHooks, candleHook)
case boil.BeforeUpsertHook:
candleBeforeUpsertHooks = append(candleBeforeUpsertHooks, candleHook)
case boil.AfterInsertHook:
candleAfterInsertHooks = append(candleAfterInsertHooks, candleHook)
case boil.AfterSelectHook:
candleAfterSelectHooks = append(candleAfterSelectHooks, candleHook)
case boil.AfterUpdateHook:
candleAfterUpdateHooks = append(candleAfterUpdateHooks, candleHook)
case boil.AfterDeleteHook:
candleAfterDeleteHooks = append(candleAfterDeleteHooks, candleHook)
case boil.AfterUpsertHook:
candleAfterUpsertHooks = append(candleAfterUpsertHooks, candleHook)
}
}
// One returns a single candle record from the query.
func (q candleQuery) One(ctx context.Context, exec boil.ContextExecutor) (*Candle, error) {
o := &Candle{}
queries.SetLimit(q.Query, 1)
err := q.Bind(ctx, exec, o)
if err != nil {
if errors.Cause(err) == sql.ErrNoRows {
return nil, sql.ErrNoRows
}
return nil, errors.Wrap(err, "sqlite3: failed to execute a one query for candle")
}
if err := o.doAfterSelectHooks(ctx, exec); err != nil {
return o, err
}
return o, nil
}
// All returns all Candle records from the query.
func (q candleQuery) All(ctx context.Context, exec boil.ContextExecutor) (CandleSlice, error) {
var o []*Candle
err := q.Bind(ctx, exec, &o)
if err != nil {
return nil, errors.Wrap(err, "sqlite3: failed to assign all query results to Candle slice")
}
if len(candleAfterSelectHooks) != 0 {
for _, obj := range o {
if err := obj.doAfterSelectHooks(ctx, exec); err != nil {
return o, err
}
}
}
return o, nil
}
// Count returns the count of all Candle records in the query.
func (q candleQuery) Count(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
var count int64
queries.SetSelect(q.Query, nil)
queries.SetCount(q.Query)
err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
if err != nil {
return 0, errors.Wrap(err, "sqlite3: failed to count candle rows")
}
return count, nil
}
// Exists checks if the row exists in the table.
func (q candleQuery) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
var count int64
queries.SetSelect(q.Query, nil)
queries.SetCount(q.Query)
queries.SetLimit(q.Query, 1)
err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
if err != nil {
return false, errors.Wrap(err, "sqlite3: failed to check if candle exists")
}
return count > 0, nil
}
// ExchangeName pointed to by the foreign key.
func (o *Candle) ExchangeName(mods ...qm.QueryMod) exchangeQuery {
queryMods := []qm.QueryMod{
qm.Where("\"id\" = ?", o.ExchangeNameID),
}
queryMods = append(queryMods, mods...)
query := Exchanges(queryMods...)
queries.SetFrom(query.Query, "\"exchange\"")
return query
}
// LoadExchangeName allows an eager lookup of values, cached into the
// loaded structs of the objects. This is for an N-1 relationship.
func (candleL) LoadExchangeName(ctx context.Context, e boil.ContextExecutor, singular bool, maybeCandle interface{}, mods queries.Applicator) error {
var slice []*Candle
var object *Candle
if singular {
object = maybeCandle.(*Candle)
} else {
slice = *maybeCandle.(*[]*Candle)
}
args := make([]interface{}, 0, 1)
if singular {
if object.R == nil {
object.R = &candleR{}
}
args = append(args, object.ExchangeNameID)
} else {
Outer:
for _, obj := range slice {
if obj.R == nil {
obj.R = &candleR{}
}
for _, a := range args {
if a == obj.ExchangeNameID {
continue Outer
}
}
args = append(args, obj.ExchangeNameID)
}
}
if len(args) == 0 {
return nil
}
query := NewQuery(qm.From(`exchange`), qm.WhereIn(`exchange.id in ?`, args...))
if mods != nil {
mods.Apply(query)
}
results, err := query.QueryContext(ctx, e)
if err != nil {
return errors.Wrap(err, "failed to eager load Exchange")
}
var resultSlice []*Exchange
if err = queries.Bind(results, &resultSlice); err != nil {
return errors.Wrap(err, "failed to bind eager loaded slice Exchange")
}
if err = results.Close(); err != nil {
return errors.Wrap(err, "failed to close results of eager load for exchange")
}
if err = results.Err(); err != nil {
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for exchange")
}
if len(candleAfterSelectHooks) != 0 {
for _, obj := range resultSlice {
if err := obj.doAfterSelectHooks(ctx, e); err != nil {
return err
}
}
}
if len(resultSlice) == 0 {
return nil
}
if singular {
foreign := resultSlice[0]
object.R.ExchangeName = foreign
if foreign.R == nil {
foreign.R = &exchangeR{}
}
foreign.R.ExchangeNameCandle = object
return nil
}
for _, local := range slice {
for _, foreign := range resultSlice {
if local.ExchangeNameID == foreign.ID {
local.R.ExchangeName = foreign
if foreign.R == nil {
foreign.R = &exchangeR{}
}
foreign.R.ExchangeNameCandle = local
break
}
}
}
return nil
}
// SetExchangeName of the candle to the related item.
// Sets o.R.ExchangeName to related.
// Adds o to related.R.ExchangeNameCandle.
func (o *Candle) SetExchangeName(ctx context.Context, exec boil.ContextExecutor, insert bool, related *Exchange) error {
var err error
if insert {
if err = related.Insert(ctx, exec, boil.Infer()); err != nil {
return errors.Wrap(err, "failed to insert into foreign table")
}
}
updateQuery := fmt.Sprintf(
"UPDATE \"candle\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, []string{"exchange_name_id"}),
strmangle.WhereClause("\"", "\"", 0, candlePrimaryKeyColumns),
)
values := []interface{}{related.ID, o.ID}
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, updateQuery)
fmt.Fprintln(boil.DebugWriter, values)
}
if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil {
return errors.Wrap(err, "failed to update local table")
}
o.ExchangeNameID = related.ID
if o.R == nil {
o.R = &candleR{
ExchangeName: related,
}
} else {
o.R.ExchangeName = related
}
if related.R == nil {
related.R = &exchangeR{
ExchangeNameCandle: o,
}
} else {
related.R.ExchangeNameCandle = o
}
return nil
}
// Candles retrieves all the records using an executor.
func Candles(mods ...qm.QueryMod) candleQuery {
mods = append(mods, qm.From("\"candle\""))
return candleQuery{NewQuery(mods...)}
}
// FindCandle retrieves a single record by ID with an executor.
// If selectCols is empty Find will return all columns.
func FindCandle(ctx context.Context, exec boil.ContextExecutor, iD string, selectCols ...string) (*Candle, error) {
candleObj := &Candle{}
sel := "*"
if len(selectCols) > 0 {
sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
}
query := fmt.Sprintf(
"select %s from \"candle\" where \"id\"=?", sel,
)
q := queries.Raw(query, iD)
err := q.Bind(ctx, exec, candleObj)
if err != nil {
if errors.Cause(err) == sql.ErrNoRows {
return nil, sql.ErrNoRows
}
return nil, errors.Wrap(err, "sqlite3: unable to select from candle")
}
return candleObj, nil
}
// Insert a single record using an executor.
// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.
func (o *Candle) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
if o == nil {
return errors.New("sqlite3: no candle provided for insertion")
}
var err error
if err := o.doBeforeInsertHooks(ctx, exec); err != nil {
return err
}
nzDefaults := queries.NonZeroDefaultSet(candleColumnsWithDefault, o)
key := makeCacheKey(columns, nzDefaults)
candleInsertCacheMut.RLock()
cache, cached := candleInsertCache[key]
candleInsertCacheMut.RUnlock()
if !cached {
wl, returnColumns := columns.InsertColumnSet(
candleAllColumns,
candleColumnsWithDefault,
candleColumnsWithoutDefault,
nzDefaults,
)
cache.valueMapping, err = queries.BindMapping(candleType, candleMapping, wl)
if err != nil {
return err
}
cache.retMapping, err = queries.BindMapping(candleType, candleMapping, returnColumns)
if err != nil {
return err
}
if len(wl) != 0 {
cache.query = fmt.Sprintf("INSERT INTO \"candle\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
} else {
cache.query = "INSERT INTO \"candle\" () VALUES ()%s%s"
}
var queryOutput, queryReturning string
if len(cache.retMapping) != 0 {
cache.retQuery = fmt.Sprintf("SELECT \"%s\" FROM \"candle\" WHERE %s", strings.Join(returnColumns, "\",\""), strmangle.WhereClause("\"", "\"", 0, candlePrimaryKeyColumns))
}
cache.query = fmt.Sprintf(cache.query, queryOutput, queryReturning)
}
value := reflect.Indirect(reflect.ValueOf(o))
vals := queries.ValuesFromMapping(value, cache.valueMapping)
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, cache.query)
fmt.Fprintln(boil.DebugWriter, vals)
}
_, err = exec.ExecContext(ctx, cache.query, vals...)
if err != nil {
return errors.Wrap(err, "sqlite3: unable to insert into candle")
}
var identifierCols []interface{}
if len(cache.retMapping) == 0 {
goto CacheNoHooks
}
identifierCols = []interface{}{
o.ID,
}
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, cache.retQuery)
fmt.Fprintln(boil.DebugWriter, identifierCols...)
}
err = exec.QueryRowContext(ctx, cache.retQuery, identifierCols...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...)
if err != nil {
return errors.Wrap(err, "sqlite3: unable to populate default values for candle")
}
CacheNoHooks:
if !cached {
candleInsertCacheMut.Lock()
candleInsertCache[key] = cache
candleInsertCacheMut.Unlock()
}
return o.doAfterInsertHooks(ctx, exec)
}
// Update uses an executor to update the Candle.
// See boil.Columns.UpdateColumnSet documentation to understand column list inference for updates.
// Update does not automatically update the record in case of default values. Use .Reload() to refresh the records.
func (o *Candle) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error) {
var err error
if err = o.doBeforeUpdateHooks(ctx, exec); err != nil {
return 0, err
}
key := makeCacheKey(columns, nil)
candleUpdateCacheMut.RLock()
cache, cached := candleUpdateCache[key]
candleUpdateCacheMut.RUnlock()
if !cached {
wl := columns.UpdateColumnSet(
candleAllColumns,
candlePrimaryKeyColumns,
)
if len(wl) == 0 {
return 0, errors.New("sqlite3: unable to update candle, could not build whitelist")
}
cache.query = fmt.Sprintf("UPDATE \"candle\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, wl),
strmangle.WhereClause("\"", "\"", 0, candlePrimaryKeyColumns),
)
cache.valueMapping, err = queries.BindMapping(candleType, candleMapping, append(wl, candlePrimaryKeyColumns...))
if err != nil {
return 0, err
}
}
values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping)
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, cache.query)
fmt.Fprintln(boil.DebugWriter, values)
}
var result sql.Result
result, err = exec.ExecContext(ctx, cache.query, values...)
if err != nil {
return 0, errors.Wrap(err, "sqlite3: unable to update candle row")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "sqlite3: failed to get rows affected by update for candle")
}
if !cached {
candleUpdateCacheMut.Lock()
candleUpdateCache[key] = cache
candleUpdateCacheMut.Unlock()
}
return rowsAff, o.doAfterUpdateHooks(ctx, exec)
}
// UpdateAll updates all rows with the specified column values.
func (q candleQuery) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
queries.SetUpdate(q.Query, cols)
result, err := q.Query.ExecContext(ctx, exec)
if err != nil {
return 0, errors.Wrap(err, "sqlite3: unable to update all for candle")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "sqlite3: unable to retrieve rows affected for candle")
}
return rowsAff, nil
}
// UpdateAll updates all rows with the specified column values, using an executor.
func (o CandleSlice) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
ln := int64(len(o))
if ln == 0 {
return 0, nil
}
if len(cols) == 0 {
return 0, errors.New("sqlite3: update all requires at least one column argument")
}
colNames := make([]string, len(cols))
args := make([]interface{}, len(cols))
i := 0
for name, value := range cols {
colNames[i] = name
args[i] = value
i++
}
// Append all of the primary key values for each column
for _, obj := range o {
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), candlePrimaryKeyMapping)
args = append(args, pkeyArgs...)
}
sql := fmt.Sprintf("UPDATE \"candle\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, colNames),
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, candlePrimaryKeyColumns, len(o)))
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, sql)
fmt.Fprintln(boil.DebugWriter, args...)
}
result, err := exec.ExecContext(ctx, sql, args...)
if err != nil {
return 0, errors.Wrap(err, "sqlite3: unable to update all in candle slice")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "sqlite3: unable to retrieve rows affected all in update all candle")
}
return rowsAff, nil
}
// Delete deletes a single Candle record with an executor.
// Delete will match against the primary key column to find the record to delete.
func (o *Candle) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
if o == nil {
return 0, errors.New("sqlite3: no Candle provided for delete")
}
if err := o.doBeforeDeleteHooks(ctx, exec); err != nil {
return 0, err
}
args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), candlePrimaryKeyMapping)
sql := "DELETE FROM \"candle\" WHERE \"id\"=?"
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, sql)
fmt.Fprintln(boil.DebugWriter, args...)
}
result, err := exec.ExecContext(ctx, sql, args...)
if err != nil {
return 0, errors.Wrap(err, "sqlite3: unable to delete from candle")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "sqlite3: failed to get rows affected by delete for candle")
}
if err := o.doAfterDeleteHooks(ctx, exec); err != nil {
return 0, err
}
return rowsAff, nil
}
// DeleteAll deletes all matching rows.
func (q candleQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
if q.Query == nil {
return 0, errors.New("sqlite3: no candleQuery provided for delete all")
}
queries.SetDelete(q.Query)
result, err := q.Query.ExecContext(ctx, exec)
if err != nil {
return 0, errors.Wrap(err, "sqlite3: unable to delete all from candle")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "sqlite3: failed to get rows affected by deleteall for candle")
}
return rowsAff, nil
}
// DeleteAll deletes all rows in the slice, using an executor.
func (o CandleSlice) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
if len(o) == 0 {
return 0, nil
}
if len(candleBeforeDeleteHooks) != 0 {
for _, obj := range o {
if err := obj.doBeforeDeleteHooks(ctx, exec); err != nil {
return 0, err
}
}
}
var args []interface{}
for _, obj := range o {
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), candlePrimaryKeyMapping)
args = append(args, pkeyArgs...)
}
sql := "DELETE FROM \"candle\" WHERE " +
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, candlePrimaryKeyColumns, len(o))
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, sql)
fmt.Fprintln(boil.DebugWriter, args)
}
result, err := exec.ExecContext(ctx, sql, args...)
if err != nil {
return 0, errors.Wrap(err, "sqlite3: unable to delete all from candle slice")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "sqlite3: failed to get rows affected by deleteall for candle")
}
if len(candleAfterDeleteHooks) != 0 {
for _, obj := range o {
if err := obj.doAfterDeleteHooks(ctx, exec); err != nil {
return 0, err
}
}
}
return rowsAff, nil
}
// Reload refetches the object from the database
// using the primary keys with an executor.
func (o *Candle) Reload(ctx context.Context, exec boil.ContextExecutor) error {
ret, err := FindCandle(ctx, exec, o.ID)
if err != nil {
return err
}
*o = *ret
return nil
}
// ReloadAll refetches every row with matching primary key column values
// and overwrites the original object slice with the newly updated slice.
func (o *CandleSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error {
if o == nil || len(*o) == 0 {
return nil
}
slice := CandleSlice{}
var args []interface{}
for _, obj := range *o {
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), candlePrimaryKeyMapping)
args = append(args, pkeyArgs...)
}
sql := "SELECT \"candle\".* FROM \"candle\" WHERE " +
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, candlePrimaryKeyColumns, len(*o))
q := queries.Raw(sql, args...)
err := q.Bind(ctx, exec, &slice)
if err != nil {
return errors.Wrap(err, "sqlite3: unable to reload all in CandleSlice")
}
*o = slice
return nil
}
// CandleExists checks if the Candle row exists.
func CandleExists(ctx context.Context, exec boil.ContextExecutor, iD string) (bool, error) {
var exists bool
sql := "select exists(select 1 from \"candle\" where \"id\"=? limit 1)"
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, sql)
fmt.Fprintln(boil.DebugWriter, iD)
}
row := exec.QueryRowContext(ctx, sql, iD)
err := row.Scan(&exists)
if err != nil {
return false, errors.Wrap(err, "sqlite3: unable to check if candle exists")
}
return exists, nil
}

View File

@@ -0,0 +1,793 @@
// Code generated by SQLBoiler 3.5.0-gct (https://github.com/thrasher-corp/sqlboiler). DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package sqlite3
import (
"bytes"
"context"
"reflect"
"testing"
"github.com/thrasher-corp/sqlboiler/boil"
"github.com/thrasher-corp/sqlboiler/queries"
"github.com/thrasher-corp/sqlboiler/randomize"
"github.com/thrasher-corp/sqlboiler/strmangle"
)
var (
// Relationships sometimes use the reflection helper queries.Equal/queries.Assign
// so force a package dependency in case they don't.
_ = queries.Equal
)
func testCandles(t *testing.T) {
t.Parallel()
query := Candles()
if query.Query == nil {
t.Error("expected a query, got nothing")
}
}
func testCandlesDelete(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Candle{}
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if rowsAff, err := o.Delete(ctx, tx); err != nil {
t.Error(err)
} else if rowsAff != 1 {
t.Error("should only have deleted one row, but affected:", rowsAff)
}
count, err := Candles().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 0 {
t.Error("want zero records, got:", count)
}
}
func testCandlesQueryDeleteAll(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Candle{}
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if rowsAff, err := Candles().DeleteAll(ctx, tx); err != nil {
t.Error(err)
} else if rowsAff != 1 {
t.Error("should only have deleted one row, but affected:", rowsAff)
}
count, err := Candles().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 0 {
t.Error("want zero records, got:", count)
}
}
func testCandlesSliceDeleteAll(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Candle{}
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
slice := CandleSlice{o}
if rowsAff, err := slice.DeleteAll(ctx, tx); err != nil {
t.Error(err)
} else if rowsAff != 1 {
t.Error("should only have deleted one row, but affected:", rowsAff)
}
count, err := Candles().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 0 {
t.Error("want zero records, got:", count)
}
}
func testCandlesExists(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Candle{}
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
e, err := CandleExists(ctx, tx, o.ID)
if err != nil {
t.Errorf("Unable to check if Candle exists: %s", err)
}
if !e {
t.Errorf("Expected CandleExists to return true, but got false.")
}
}
func testCandlesFind(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Candle{}
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
candleFound, err := FindCandle(ctx, tx, o.ID)
if err != nil {
t.Error(err)
}
if candleFound == nil {
t.Error("want a record, got nil")
}
}
func testCandlesBind(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Candle{}
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if err = Candles().Bind(ctx, tx, o); err != nil {
t.Error(err)
}
}
func testCandlesOne(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Candle{}
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if x, err := Candles().One(ctx, tx); err != nil {
t.Error(err)
} else if x == nil {
t.Error("expected to get a non nil record")
}
}
func testCandlesAll(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
candleOne := &Candle{}
candleTwo := &Candle{}
if err = randomize.Struct(seed, candleOne, candleDBTypes, false, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
if err = randomize.Struct(seed, candleTwo, candleDBTypes, false, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = candleOne.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if err = candleTwo.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
slice, err := Candles().All(ctx, tx)
if err != nil {
t.Error(err)
}
if len(slice) != 2 {
t.Error("want 2 records, got:", len(slice))
}
}
func testCandlesCount(t *testing.T) {
t.Parallel()
var err error
seed := randomize.NewSeed()
candleOne := &Candle{}
candleTwo := &Candle{}
if err = randomize.Struct(seed, candleOne, candleDBTypes, false, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
if err = randomize.Struct(seed, candleTwo, candleDBTypes, false, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = candleOne.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if err = candleTwo.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
count, err := Candles().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 2 {
t.Error("want 2 records, got:", count)
}
}
func candleBeforeInsertHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
*o = Candle{}
return nil
}
func candleAfterInsertHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
*o = Candle{}
return nil
}
func candleAfterSelectHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
*o = Candle{}
return nil
}
func candleBeforeUpdateHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
*o = Candle{}
return nil
}
func candleAfterUpdateHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
*o = Candle{}
return nil
}
func candleBeforeDeleteHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
*o = Candle{}
return nil
}
func candleAfterDeleteHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
*o = Candle{}
return nil
}
func candleBeforeUpsertHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
*o = Candle{}
return nil
}
func candleAfterUpsertHook(ctx context.Context, e boil.ContextExecutor, o *Candle) error {
*o = Candle{}
return nil
}
func testCandlesHooks(t *testing.T) {
t.Parallel()
var err error
ctx := context.Background()
empty := &Candle{}
o := &Candle{}
seed := randomize.NewSeed()
if err = randomize.Struct(seed, o, candleDBTypes, false); err != nil {
t.Errorf("Unable to randomize Candle object: %s", err)
}
AddCandleHook(boil.BeforeInsertHook, candleBeforeInsertHook)
if err = o.doBeforeInsertHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doBeforeInsertHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected BeforeInsertHook function to empty object, but got: %#v", o)
}
candleBeforeInsertHooks = []CandleHook{}
AddCandleHook(boil.AfterInsertHook, candleAfterInsertHook)
if err = o.doAfterInsertHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doAfterInsertHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected AfterInsertHook function to empty object, but got: %#v", o)
}
candleAfterInsertHooks = []CandleHook{}
AddCandleHook(boil.AfterSelectHook, candleAfterSelectHook)
if err = o.doAfterSelectHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doAfterSelectHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected AfterSelectHook function to empty object, but got: %#v", o)
}
candleAfterSelectHooks = []CandleHook{}
AddCandleHook(boil.BeforeUpdateHook, candleBeforeUpdateHook)
if err = o.doBeforeUpdateHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doBeforeUpdateHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected BeforeUpdateHook function to empty object, but got: %#v", o)
}
candleBeforeUpdateHooks = []CandleHook{}
AddCandleHook(boil.AfterUpdateHook, candleAfterUpdateHook)
if err = o.doAfterUpdateHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doAfterUpdateHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected AfterUpdateHook function to empty object, but got: %#v", o)
}
candleAfterUpdateHooks = []CandleHook{}
AddCandleHook(boil.BeforeDeleteHook, candleBeforeDeleteHook)
if err = o.doBeforeDeleteHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doBeforeDeleteHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected BeforeDeleteHook function to empty object, but got: %#v", o)
}
candleBeforeDeleteHooks = []CandleHook{}
AddCandleHook(boil.AfterDeleteHook, candleAfterDeleteHook)
if err = o.doAfterDeleteHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doAfterDeleteHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected AfterDeleteHook function to empty object, but got: %#v", o)
}
candleAfterDeleteHooks = []CandleHook{}
AddCandleHook(boil.BeforeUpsertHook, candleBeforeUpsertHook)
if err = o.doBeforeUpsertHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doBeforeUpsertHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected BeforeUpsertHook function to empty object, but got: %#v", o)
}
candleBeforeUpsertHooks = []CandleHook{}
AddCandleHook(boil.AfterUpsertHook, candleAfterUpsertHook)
if err = o.doAfterUpsertHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doAfterUpsertHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected AfterUpsertHook function to empty object, but got: %#v", o)
}
candleAfterUpsertHooks = []CandleHook{}
}
func testCandlesInsert(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Candle{}
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
count, err := Candles().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 1 {
t.Error("want one record, got:", count)
}
}
func testCandlesInsertWhitelist(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Candle{}
if err = randomize.Struct(seed, o, candleDBTypes, true); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Whitelist(candleColumnsWithoutDefault...)); err != nil {
t.Error(err)
}
count, err := Candles().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 1 {
t.Error("want one record, got:", count)
}
}
func testCandleToOneExchangeUsingExchangeName(t *testing.T) {
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
var local Candle
var foreign Exchange
seed := randomize.NewSeed()
if err := randomize.Struct(seed, &local, candleDBTypes, false, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
if err := randomize.Struct(seed, &foreign, exchangeDBTypes, false, exchangeColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Exchange struct: %s", err)
}
if err := foreign.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
local.ExchangeNameID = foreign.ID
if err := local.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
check, err := local.ExchangeName().One(ctx, tx)
if err != nil {
t.Fatal(err)
}
if check.ID != foreign.ID {
t.Errorf("want: %v, got %v", foreign.ID, check.ID)
}
slice := CandleSlice{&local}
if err = local.L.LoadExchangeName(ctx, tx, false, (*[]*Candle)(&slice), nil); err != nil {
t.Fatal(err)
}
if local.R.ExchangeName == nil {
t.Error("struct should have been eager loaded")
}
local.R.ExchangeName = nil
if err = local.L.LoadExchangeName(ctx, tx, true, &local, nil); err != nil {
t.Fatal(err)
}
if local.R.ExchangeName == nil {
t.Error("struct should have been eager loaded")
}
}
func testCandleToOneSetOpExchangeUsingExchangeName(t *testing.T) {
var err error
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
var a Candle
var b, c Exchange
seed := randomize.NewSeed()
if err = randomize.Struct(seed, &a, candleDBTypes, false, strmangle.SetComplement(candlePrimaryKeyColumns, candleColumnsWithoutDefault)...); err != nil {
t.Fatal(err)
}
if err = randomize.Struct(seed, &b, exchangeDBTypes, false, strmangle.SetComplement(exchangePrimaryKeyColumns, exchangeColumnsWithoutDefault)...); err != nil {
t.Fatal(err)
}
if err = randomize.Struct(seed, &c, exchangeDBTypes, false, strmangle.SetComplement(exchangePrimaryKeyColumns, exchangeColumnsWithoutDefault)...); err != nil {
t.Fatal(err)
}
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
for i, x := range []*Exchange{&b, &c} {
err = a.SetExchangeName(ctx, tx, i != 0, x)
if err != nil {
t.Fatal(err)
}
if a.R.ExchangeName != x {
t.Error("relationship struct not set to correct value")
}
if x.R.ExchangeNameCandle != &a {
t.Error("failed to append to foreign relationship struct")
}
if a.ExchangeNameID != x.ID {
t.Error("foreign key was wrong value", a.ExchangeNameID)
}
zero := reflect.Zero(reflect.TypeOf(a.ExchangeNameID))
reflect.Indirect(reflect.ValueOf(&a.ExchangeNameID)).Set(zero)
if err = a.Reload(ctx, tx); err != nil {
t.Fatal("failed to reload", err)
}
if a.ExchangeNameID != x.ID {
t.Error("foreign key was wrong value", a.ExchangeNameID, x.ID)
}
}
}
func testCandlesReload(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Candle{}
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if err = o.Reload(ctx, tx); err != nil {
t.Error(err)
}
}
func testCandlesReloadAll(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Candle{}
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
slice := CandleSlice{o}
if err = slice.ReloadAll(ctx, tx); err != nil {
t.Error(err)
}
}
func testCandlesSelect(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Candle{}
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
slice, err := Candles().All(ctx, tx)
if err != nil {
t.Error(err)
}
if len(slice) != 1 {
t.Error("want one record, got:", len(slice))
}
}
var (
candleDBTypes = map[string]string{`ID`: `TEXT`, `ExchangeNameID`: `UUID`, `Base`: `TEXT`, `Quote`: `TEXT`, `Interval`: `TEXT`, `Timestamp`: `TIMESTAMP`, `Open`: `REAL`, `High`: `REAL`, `Low`: `REAL`, `Close`: `REAL`, `Volume`: `REAL`, `Asset`: `TEXT`}
_ = bytes.MinRead
)
func testCandlesUpdate(t *testing.T) {
t.Parallel()
if 0 == len(candlePrimaryKeyColumns) {
t.Skip("Skipping table with no primary key columns")
}
if len(candleAllColumns) == len(candlePrimaryKeyColumns) {
t.Skip("Skipping table with only primary key columns")
}
seed := randomize.NewSeed()
var err error
o := &Candle{}
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
count, err := Candles().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 1 {
t.Error("want one record, got:", count)
}
if err = randomize.Struct(seed, o, candleDBTypes, true, candlePrimaryKeyColumns...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
if rowsAff, err := o.Update(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
} else if rowsAff != 1 {
t.Error("should only affect one row but affected", rowsAff)
}
}
func testCandlesSliceUpdateAll(t *testing.T) {
t.Parallel()
if len(candleAllColumns) == len(candlePrimaryKeyColumns) {
t.Skip("Skipping table with only primary key columns")
}
seed := randomize.NewSeed()
var err error
o := &Candle{}
if err = randomize.Struct(seed, o, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
count, err := Candles().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 1 {
t.Error("want one record, got:", count)
}
if err = randomize.Struct(seed, o, candleDBTypes, true, candlePrimaryKeyColumns...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
// Remove Primary keys and unique columns from what we plan to update
var fields []string
if strmangle.StringSliceMatch(candleAllColumns, candlePrimaryKeyColumns) {
fields = candleAllColumns
} else {
fields = strmangle.SetComplement(
candleAllColumns,
candlePrimaryKeyColumns,
)
}
value := reflect.Indirect(reflect.ValueOf(o))
typ := reflect.TypeOf(o).Elem()
n := typ.NumField()
updateMap := M{}
for _, col := range fields {
for i := 0; i < n; i++ {
f := typ.Field(i)
if f.Tag.Get("boil") == col {
updateMap[col] = value.Field(i).Interface()
}
}
}
slice := CandleSlice{o}
if rowsAff, err := slice.UpdateAll(ctx, tx, updateMap); err != nil {
t.Error(err)
} else if rowsAff != 1 {
t.Error("wanted one record updated but got", rowsAff)
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,951 @@
// Code generated by SQLBoiler 3.5.0-gct (https://github.com/thrasher-corp/sqlboiler). DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package sqlite3
import (
"bytes"
"context"
"reflect"
"testing"
"github.com/thrasher-corp/sqlboiler/boil"
"github.com/thrasher-corp/sqlboiler/queries"
"github.com/thrasher-corp/sqlboiler/randomize"
"github.com/thrasher-corp/sqlboiler/strmangle"
)
var (
// Relationships sometimes use the reflection helper queries.Equal/queries.Assign
// so force a package dependency in case they don't.
_ = queries.Equal
)
func testExchanges(t *testing.T) {
t.Parallel()
query := Exchanges()
if query.Query == nil {
t.Error("expected a query, got nothing")
}
}
func testExchangesDelete(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Exchange{}
if err = randomize.Struct(seed, o, exchangeDBTypes, true, exchangeColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Exchange struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if rowsAff, err := o.Delete(ctx, tx); err != nil {
t.Error(err)
} else if rowsAff != 1 {
t.Error("should only have deleted one row, but affected:", rowsAff)
}
count, err := Exchanges().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 0 {
t.Error("want zero records, got:", count)
}
}
func testExchangesQueryDeleteAll(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Exchange{}
if err = randomize.Struct(seed, o, exchangeDBTypes, true, exchangeColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Exchange struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if rowsAff, err := Exchanges().DeleteAll(ctx, tx); err != nil {
t.Error(err)
} else if rowsAff != 1 {
t.Error("should only have deleted one row, but affected:", rowsAff)
}
count, err := Exchanges().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 0 {
t.Error("want zero records, got:", count)
}
}
func testExchangesSliceDeleteAll(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Exchange{}
if err = randomize.Struct(seed, o, exchangeDBTypes, true, exchangeColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Exchange struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
slice := ExchangeSlice{o}
if rowsAff, err := slice.DeleteAll(ctx, tx); err != nil {
t.Error(err)
} else if rowsAff != 1 {
t.Error("should only have deleted one row, but affected:", rowsAff)
}
count, err := Exchanges().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 0 {
t.Error("want zero records, got:", count)
}
}
func testExchangesExists(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Exchange{}
if err = randomize.Struct(seed, o, exchangeDBTypes, true, exchangeColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Exchange struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
e, err := ExchangeExists(ctx, tx, o.ID)
if err != nil {
t.Errorf("Unable to check if Exchange exists: %s", err)
}
if !e {
t.Errorf("Expected ExchangeExists to return true, but got false.")
}
}
func testExchangesFind(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Exchange{}
if err = randomize.Struct(seed, o, exchangeDBTypes, true, exchangeColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Exchange struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
exchangeFound, err := FindExchange(ctx, tx, o.ID)
if err != nil {
t.Error(err)
}
if exchangeFound == nil {
t.Error("want a record, got nil")
}
}
func testExchangesBind(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Exchange{}
if err = randomize.Struct(seed, o, exchangeDBTypes, true, exchangeColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Exchange struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if err = Exchanges().Bind(ctx, tx, o); err != nil {
t.Error(err)
}
}
func testExchangesOne(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Exchange{}
if err = randomize.Struct(seed, o, exchangeDBTypes, true, exchangeColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Exchange struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if x, err := Exchanges().One(ctx, tx); err != nil {
t.Error(err)
} else if x == nil {
t.Error("expected to get a non nil record")
}
}
func testExchangesAll(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
exchangeOne := &Exchange{}
exchangeTwo := &Exchange{}
if err = randomize.Struct(seed, exchangeOne, exchangeDBTypes, false, exchangeColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Exchange struct: %s", err)
}
if err = randomize.Struct(seed, exchangeTwo, exchangeDBTypes, false, exchangeColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Exchange struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = exchangeOne.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if err = exchangeTwo.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
slice, err := Exchanges().All(ctx, tx)
if err != nil {
t.Error(err)
}
if len(slice) != 2 {
t.Error("want 2 records, got:", len(slice))
}
}
func testExchangesCount(t *testing.T) {
t.Parallel()
var err error
seed := randomize.NewSeed()
exchangeOne := &Exchange{}
exchangeTwo := &Exchange{}
if err = randomize.Struct(seed, exchangeOne, exchangeDBTypes, false, exchangeColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Exchange struct: %s", err)
}
if err = randomize.Struct(seed, exchangeTwo, exchangeDBTypes, false, exchangeColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Exchange struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = exchangeOne.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if err = exchangeTwo.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
count, err := Exchanges().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 2 {
t.Error("want 2 records, got:", count)
}
}
func exchangeBeforeInsertHook(ctx context.Context, e boil.ContextExecutor, o *Exchange) error {
*o = Exchange{}
return nil
}
func exchangeAfterInsertHook(ctx context.Context, e boil.ContextExecutor, o *Exchange) error {
*o = Exchange{}
return nil
}
func exchangeAfterSelectHook(ctx context.Context, e boil.ContextExecutor, o *Exchange) error {
*o = Exchange{}
return nil
}
func exchangeBeforeUpdateHook(ctx context.Context, e boil.ContextExecutor, o *Exchange) error {
*o = Exchange{}
return nil
}
func exchangeAfterUpdateHook(ctx context.Context, e boil.ContextExecutor, o *Exchange) error {
*o = Exchange{}
return nil
}
func exchangeBeforeDeleteHook(ctx context.Context, e boil.ContextExecutor, o *Exchange) error {
*o = Exchange{}
return nil
}
func exchangeAfterDeleteHook(ctx context.Context, e boil.ContextExecutor, o *Exchange) error {
*o = Exchange{}
return nil
}
func exchangeBeforeUpsertHook(ctx context.Context, e boil.ContextExecutor, o *Exchange) error {
*o = Exchange{}
return nil
}
func exchangeAfterUpsertHook(ctx context.Context, e boil.ContextExecutor, o *Exchange) error {
*o = Exchange{}
return nil
}
func testExchangesHooks(t *testing.T) {
t.Parallel()
var err error
ctx := context.Background()
empty := &Exchange{}
o := &Exchange{}
seed := randomize.NewSeed()
if err = randomize.Struct(seed, o, exchangeDBTypes, false); err != nil {
t.Errorf("Unable to randomize Exchange object: %s", err)
}
AddExchangeHook(boil.BeforeInsertHook, exchangeBeforeInsertHook)
if err = o.doBeforeInsertHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doBeforeInsertHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected BeforeInsertHook function to empty object, but got: %#v", o)
}
exchangeBeforeInsertHooks = []ExchangeHook{}
AddExchangeHook(boil.AfterInsertHook, exchangeAfterInsertHook)
if err = o.doAfterInsertHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doAfterInsertHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected AfterInsertHook function to empty object, but got: %#v", o)
}
exchangeAfterInsertHooks = []ExchangeHook{}
AddExchangeHook(boil.AfterSelectHook, exchangeAfterSelectHook)
if err = o.doAfterSelectHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doAfterSelectHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected AfterSelectHook function to empty object, but got: %#v", o)
}
exchangeAfterSelectHooks = []ExchangeHook{}
AddExchangeHook(boil.BeforeUpdateHook, exchangeBeforeUpdateHook)
if err = o.doBeforeUpdateHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doBeforeUpdateHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected BeforeUpdateHook function to empty object, but got: %#v", o)
}
exchangeBeforeUpdateHooks = []ExchangeHook{}
AddExchangeHook(boil.AfterUpdateHook, exchangeAfterUpdateHook)
if err = o.doAfterUpdateHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doAfterUpdateHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected AfterUpdateHook function to empty object, but got: %#v", o)
}
exchangeAfterUpdateHooks = []ExchangeHook{}
AddExchangeHook(boil.BeforeDeleteHook, exchangeBeforeDeleteHook)
if err = o.doBeforeDeleteHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doBeforeDeleteHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected BeforeDeleteHook function to empty object, but got: %#v", o)
}
exchangeBeforeDeleteHooks = []ExchangeHook{}
AddExchangeHook(boil.AfterDeleteHook, exchangeAfterDeleteHook)
if err = o.doAfterDeleteHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doAfterDeleteHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected AfterDeleteHook function to empty object, but got: %#v", o)
}
exchangeAfterDeleteHooks = []ExchangeHook{}
AddExchangeHook(boil.BeforeUpsertHook, exchangeBeforeUpsertHook)
if err = o.doBeforeUpsertHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doBeforeUpsertHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected BeforeUpsertHook function to empty object, but got: %#v", o)
}
exchangeBeforeUpsertHooks = []ExchangeHook{}
AddExchangeHook(boil.AfterUpsertHook, exchangeAfterUpsertHook)
if err = o.doAfterUpsertHooks(ctx, nil); err != nil {
t.Errorf("Unable to execute doAfterUpsertHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected AfterUpsertHook function to empty object, but got: %#v", o)
}
exchangeAfterUpsertHooks = []ExchangeHook{}
}
func testExchangesInsert(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Exchange{}
if err = randomize.Struct(seed, o, exchangeDBTypes, true, exchangeColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Exchange struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
count, err := Exchanges().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 1 {
t.Error("want one record, got:", count)
}
}
func testExchangesInsertWhitelist(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Exchange{}
if err = randomize.Struct(seed, o, exchangeDBTypes, true); err != nil {
t.Errorf("Unable to randomize Exchange struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Whitelist(exchangeColumnsWithoutDefault...)); err != nil {
t.Error(err)
}
count, err := Exchanges().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 1 {
t.Error("want one record, got:", count)
}
}
func testExchangeOneToOneCandleUsingExchangeNameCandle(t *testing.T) {
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
var foreign Candle
var local Exchange
seed := randomize.NewSeed()
if err := randomize.Struct(seed, &foreign, candleDBTypes, true, candleColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Candle struct: %s", err)
}
if err := randomize.Struct(seed, &local, exchangeDBTypes, true, exchangeColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Exchange struct: %s", err)
}
if err := local.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
foreign.ExchangeNameID = local.ID
if err := foreign.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
check, err := local.ExchangeNameCandle().One(ctx, tx)
if err != nil {
t.Fatal(err)
}
if check.ExchangeNameID != foreign.ExchangeNameID {
t.Errorf("want: %v, got %v", foreign.ExchangeNameID, check.ExchangeNameID)
}
slice := ExchangeSlice{&local}
if err = local.L.LoadExchangeNameCandle(ctx, tx, false, (*[]*Exchange)(&slice), nil); err != nil {
t.Fatal(err)
}
if local.R.ExchangeNameCandle == nil {
t.Error("struct should have been eager loaded")
}
local.R.ExchangeNameCandle = nil
if err = local.L.LoadExchangeNameCandle(ctx, tx, true, &local, nil); err != nil {
t.Fatal(err)
}
if local.R.ExchangeNameCandle == nil {
t.Error("struct should have been eager loaded")
}
}
func testExchangeOneToOneSetOpCandleUsingExchangeNameCandle(t *testing.T) {
var err error
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
var a Exchange
var b, c Candle
seed := randomize.NewSeed()
if err = randomize.Struct(seed, &a, exchangeDBTypes, false, strmangle.SetComplement(exchangePrimaryKeyColumns, exchangeColumnsWithoutDefault)...); err != nil {
t.Fatal(err)
}
if err = randomize.Struct(seed, &b, candleDBTypes, false, strmangle.SetComplement(candlePrimaryKeyColumns, candleColumnsWithoutDefault)...); err != nil {
t.Fatal(err)
}
if err = randomize.Struct(seed, &c, candleDBTypes, false, strmangle.SetComplement(candlePrimaryKeyColumns, candleColumnsWithoutDefault)...); err != nil {
t.Fatal(err)
}
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
for i, x := range []*Candle{&b, &c} {
err = a.SetExchangeNameCandle(ctx, tx, i != 0, x)
if err != nil {
t.Fatal(err)
}
if a.R.ExchangeNameCandle != x {
t.Error("relationship struct not set to correct value")
}
if x.R.ExchangeName != &a {
t.Error("failed to append to foreign relationship struct")
}
if a.ID != x.ExchangeNameID {
t.Error("foreign key was wrong value", a.ID)
}
zero := reflect.Zero(reflect.TypeOf(x.ExchangeNameID))
reflect.Indirect(reflect.ValueOf(&x.ExchangeNameID)).Set(zero)
if err = x.Reload(ctx, tx); err != nil {
t.Fatal("failed to reload", err)
}
if a.ID != x.ExchangeNameID {
t.Error("foreign key was wrong value", a.ID, x.ExchangeNameID)
}
if _, err = x.Delete(ctx, tx); err != nil {
t.Fatal("failed to delete x", err)
}
}
}
func testExchangeToManyExchangeNameWithdrawalHistories(t *testing.T) {
var err error
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
var a Exchange
var b, c WithdrawalHistory
seed := randomize.NewSeed()
if err = randomize.Struct(seed, &a, exchangeDBTypes, true, exchangeColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Exchange struct: %s", err)
}
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
if err = randomize.Struct(seed, &b, withdrawalHistoryDBTypes, false, withdrawalHistoryColumnsWithDefault...); err != nil {
t.Fatal(err)
}
if err = randomize.Struct(seed, &c, withdrawalHistoryDBTypes, false, withdrawalHistoryColumnsWithDefault...); err != nil {
t.Fatal(err)
}
b.ExchangeNameID = a.ID
c.ExchangeNameID = a.ID
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
if err = c.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
check, err := a.ExchangeNameWithdrawalHistories().All(ctx, tx)
if err != nil {
t.Fatal(err)
}
bFound, cFound := false, false
for _, v := range check {
if v.ExchangeNameID == b.ExchangeNameID {
bFound = true
}
if v.ExchangeNameID == c.ExchangeNameID {
cFound = true
}
}
if !bFound {
t.Error("expected to find b")
}
if !cFound {
t.Error("expected to find c")
}
slice := ExchangeSlice{&a}
if err = a.L.LoadExchangeNameWithdrawalHistories(ctx, tx, false, (*[]*Exchange)(&slice), nil); err != nil {
t.Fatal(err)
}
if got := len(a.R.ExchangeNameWithdrawalHistories); got != 2 {
t.Error("number of eager loaded records wrong, got:", got)
}
a.R.ExchangeNameWithdrawalHistories = nil
if err = a.L.LoadExchangeNameWithdrawalHistories(ctx, tx, true, &a, nil); err != nil {
t.Fatal(err)
}
if got := len(a.R.ExchangeNameWithdrawalHistories); got != 2 {
t.Error("number of eager loaded records wrong, got:", got)
}
if t.Failed() {
t.Logf("%#v", check)
}
}
func testExchangeToManyAddOpExchangeNameWithdrawalHistories(t *testing.T) {
var err error
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
var a Exchange
var b, c, d, e WithdrawalHistory
seed := randomize.NewSeed()
if err = randomize.Struct(seed, &a, exchangeDBTypes, false, strmangle.SetComplement(exchangePrimaryKeyColumns, exchangeColumnsWithoutDefault)...); err != nil {
t.Fatal(err)
}
foreigners := []*WithdrawalHistory{&b, &c, &d, &e}
for _, x := range foreigners {
if err = randomize.Struct(seed, x, withdrawalHistoryDBTypes, false, strmangle.SetComplement(withdrawalHistoryPrimaryKeyColumns, withdrawalHistoryColumnsWithoutDefault)...); err != nil {
t.Fatal(err)
}
}
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
if err = c.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
foreignersSplitByInsertion := [][]*WithdrawalHistory{
{&b, &c},
{&d, &e},
}
for i, x := range foreignersSplitByInsertion {
err = a.AddExchangeNameWithdrawalHistories(ctx, tx, i != 0, x...)
if err != nil {
t.Fatal(err)
}
first := x[0]
second := x[1]
if a.ID != first.ExchangeNameID {
t.Error("foreign key was wrong value", a.ID, first.ExchangeNameID)
}
if a.ID != second.ExchangeNameID {
t.Error("foreign key was wrong value", a.ID, second.ExchangeNameID)
}
if first.R.ExchangeName != &a {
t.Error("relationship was not added properly to the foreign slice")
}
if second.R.ExchangeName != &a {
t.Error("relationship was not added properly to the foreign slice")
}
if a.R.ExchangeNameWithdrawalHistories[i*2] != first {
t.Error("relationship struct slice not set to correct value")
}
if a.R.ExchangeNameWithdrawalHistories[i*2+1] != second {
t.Error("relationship struct slice not set to correct value")
}
count, err := a.ExchangeNameWithdrawalHistories().Count(ctx, tx)
if err != nil {
t.Fatal(err)
}
if want := int64((i + 1) * 2); count != want {
t.Error("want", want, "got", count)
}
}
}
func testExchangesReload(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Exchange{}
if err = randomize.Struct(seed, o, exchangeDBTypes, true, exchangeColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Exchange struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
if err = o.Reload(ctx, tx); err != nil {
t.Error(err)
}
}
func testExchangesReloadAll(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Exchange{}
if err = randomize.Struct(seed, o, exchangeDBTypes, true, exchangeColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Exchange struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
slice := ExchangeSlice{o}
if err = slice.ReloadAll(ctx, tx); err != nil {
t.Error(err)
}
}
func testExchangesSelect(t *testing.T) {
t.Parallel()
seed := randomize.NewSeed()
var err error
o := &Exchange{}
if err = randomize.Struct(seed, o, exchangeDBTypes, true, exchangeColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Exchange struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
slice, err := Exchanges().All(ctx, tx)
if err != nil {
t.Error(err)
}
if len(slice) != 1 {
t.Error("want one record, got:", len(slice))
}
}
var (
exchangeDBTypes = map[string]string{`ID`: `TEXT`, `Name`: `TEXT`}
_ = bytes.MinRead
)
func testExchangesUpdate(t *testing.T) {
t.Parallel()
if 0 == len(exchangePrimaryKeyColumns) {
t.Skip("Skipping table with no primary key columns")
}
if len(exchangeAllColumns) == len(exchangePrimaryKeyColumns) {
t.Skip("Skipping table with only primary key columns")
}
seed := randomize.NewSeed()
var err error
o := &Exchange{}
if err = randomize.Struct(seed, o, exchangeDBTypes, true, exchangeColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Exchange struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
count, err := Exchanges().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 1 {
t.Error("want one record, got:", count)
}
if err = randomize.Struct(seed, o, exchangeDBTypes, true, exchangePrimaryKeyColumns...); err != nil {
t.Errorf("Unable to randomize Exchange struct: %s", err)
}
if rowsAff, err := o.Update(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
} else if rowsAff != 1 {
t.Error("should only affect one row but affected", rowsAff)
}
}
func testExchangesSliceUpdateAll(t *testing.T) {
t.Parallel()
if len(exchangeAllColumns) == len(exchangePrimaryKeyColumns) {
t.Skip("Skipping table with only primary key columns")
}
seed := randomize.NewSeed()
var err error
o := &Exchange{}
if err = randomize.Struct(seed, o, exchangeDBTypes, true, exchangeColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Exchange struct: %s", err)
}
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
t.Error(err)
}
count, err := Exchanges().Count(ctx, tx)
if err != nil {
t.Error(err)
}
if count != 1 {
t.Error("want one record, got:", count)
}
if err = randomize.Struct(seed, o, exchangeDBTypes, true, exchangePrimaryKeyColumns...); err != nil {
t.Errorf("Unable to randomize Exchange struct: %s", err)
}
// Remove Primary keys and unique columns from what we plan to update
var fields []string
if strmangle.StringSliceMatch(exchangeAllColumns, exchangePrimaryKeyColumns) {
fields = exchangeAllColumns
} else {
fields = strmangle.SetComplement(
exchangeAllColumns,
exchangePrimaryKeyColumns,
)
}
value := reflect.Indirect(reflect.ValueOf(o))
typ := reflect.TypeOf(o).Elem()
n := typ.NumField()
updateMap := M{}
for _, col := range fields {
for i := 0; i < n; i++ {
f := typ.Field(i)
if f.Tag.Get("boil") == col {
updateMap[col] = value.Field(i).Interface()
}
}
}
slice := ExchangeSlice{o}
if rowsAff, err := slice.UpdateAll(ctx, tx, updateMap); err != nil {
t.Error(err)
} else if rowsAff != 1 {
t.Error("wanted one record updated but got", rowsAff)
}
}

View File

@@ -72,21 +72,6 @@ func (w whereHelpernull_String) GTE(x null.String) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.GTE, x)
}
type whereHelperfloat64 struct{ field string }
func (w whereHelperfloat64) EQ(x float64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) }
func (w whereHelperfloat64) NEQ(x float64) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.NEQ, x)
}
func (w whereHelperfloat64) LT(x float64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) }
func (w whereHelperfloat64) LTE(x float64) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.LTE, x)
}
func (w whereHelperfloat64) GT(x float64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) }
func (w whereHelperfloat64) GTE(x float64) qm.QueryMod {
return qmhelper.Where(w.field, qmhelper.GTE, x)
}
var WithdrawalCryptoWhere = struct {
ID whereHelperint64
Address whereHelperstring

View File

@@ -109,8 +109,8 @@ type withdrawalFiatL struct{}
var (
withdrawalFiatAllColumns = []string{"id", "bank_name", "bank_address", "bank_account_name", "bank_account_number", "bsb", "swift_code", "iban", "bank_code", "withdrawal_history_id"}
withdrawalFiatColumnsWithoutDefault = []string{"bank_name", "bank_address", "bank_account_name", "bank_account_number", "bsb", "swift_code", "iban", "bank_code", "withdrawal_history_id"}
withdrawalFiatColumnsWithDefault = []string{"id"}
withdrawalFiatColumnsWithoutDefault = []string{"bank_name", "bank_address", "bank_account_name", "bank_account_number", "bank_code", "withdrawal_history_id"}
withdrawalFiatColumnsWithDefault = []string{"id", "bsb", "swift_code", "iban"}
withdrawalFiatPrimaryKeyColumns = []string{"id"}
)

View File

@@ -23,82 +23,85 @@ import (
// WithdrawalHistory is an object representing the database table.
type WithdrawalHistory struct {
ID string `boil:"id" json:"id" toml:"id" yaml:"id"`
Exchange string `boil:"exchange" json:"exchange" toml:"exchange" yaml:"exchange"`
ExchangeID string `boil:"exchange_id" json:"exchange_id" toml:"exchange_id" yaml:"exchange_id"`
Status string `boil:"status" json:"status" toml:"status" yaml:"status"`
Currency string `boil:"currency" json:"currency" toml:"currency" yaml:"currency"`
Amount float64 `boil:"amount" json:"amount" toml:"amount" yaml:"amount"`
Description null.String `boil:"description" json:"description,omitempty" toml:"description" yaml:"description,omitempty"`
WithdrawType int64 `boil:"withdraw_type" json:"withdraw_type" toml:"withdraw_type" yaml:"withdraw_type"`
CreatedAt string `boil:"created_at" json:"created_at" toml:"created_at" yaml:"created_at"`
UpdatedAt string `boil:"updated_at" json:"updated_at" toml:"updated_at" yaml:"updated_at"`
ID string `boil:"id" json:"id" toml:"id" yaml:"id"`
ExchangeNameID string `boil:"exchange_name_id" json:"exchange_name_id" toml:"exchange_name_id" yaml:"exchange_name_id"`
ExchangeID string `boil:"exchange_id" json:"exchange_id" toml:"exchange_id" yaml:"exchange_id"`
Status string `boil:"status" json:"status" toml:"status" yaml:"status"`
Currency string `boil:"currency" json:"currency" toml:"currency" yaml:"currency"`
Amount float64 `boil:"amount" json:"amount" toml:"amount" yaml:"amount"`
Description null.String `boil:"description" json:"description,omitempty" toml:"description" yaml:"description,omitempty"`
WithdrawType int64 `boil:"withdraw_type" json:"withdraw_type" toml:"withdraw_type" yaml:"withdraw_type"`
CreatedAt string `boil:"created_at" json:"created_at" toml:"created_at" yaml:"created_at"`
UpdatedAt string `boil:"updated_at" json:"updated_at" toml:"updated_at" yaml:"updated_at"`
R *withdrawalHistoryR `boil:"-" json:"-" toml:"-" yaml:"-"`
L withdrawalHistoryL `boil:"-" json:"-" toml:"-" yaml:"-"`
}
var WithdrawalHistoryColumns = struct {
ID string
Exchange string
ExchangeID string
Status string
Currency string
Amount string
Description string
WithdrawType string
CreatedAt string
UpdatedAt string
ID string
ExchangeNameID string
ExchangeID string
Status string
Currency string
Amount string
Description string
WithdrawType string
CreatedAt string
UpdatedAt string
}{
ID: "id",
Exchange: "exchange",
ExchangeID: "exchange_id",
Status: "status",
Currency: "currency",
Amount: "amount",
Description: "description",
WithdrawType: "withdraw_type",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
ID: "id",
ExchangeNameID: "exchange_name_id",
ExchangeID: "exchange_id",
Status: "status",
Currency: "currency",
Amount: "amount",
Description: "description",
WithdrawType: "withdraw_type",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
}
// Generated where
var WithdrawalHistoryWhere = struct {
ID whereHelperstring
Exchange whereHelperstring
ExchangeID whereHelperstring
Status whereHelperstring
Currency whereHelperstring
Amount whereHelperfloat64
Description whereHelpernull_String
WithdrawType whereHelperint64
CreatedAt whereHelperstring
UpdatedAt whereHelperstring
ID whereHelperstring
ExchangeNameID whereHelperstring
ExchangeID whereHelperstring
Status whereHelperstring
Currency whereHelperstring
Amount whereHelperfloat64
Description whereHelpernull_String
WithdrawType whereHelperint64
CreatedAt whereHelperstring
UpdatedAt whereHelperstring
}{
ID: whereHelperstring{field: "\"withdrawal_history\".\"id\""},
Exchange: whereHelperstring{field: "\"withdrawal_history\".\"exchange\""},
ExchangeID: whereHelperstring{field: "\"withdrawal_history\".\"exchange_id\""},
Status: whereHelperstring{field: "\"withdrawal_history\".\"status\""},
Currency: whereHelperstring{field: "\"withdrawal_history\".\"currency\""},
Amount: whereHelperfloat64{field: "\"withdrawal_history\".\"amount\""},
Description: whereHelpernull_String{field: "\"withdrawal_history\".\"description\""},
WithdrawType: whereHelperint64{field: "\"withdrawal_history\".\"withdraw_type\""},
CreatedAt: whereHelperstring{field: "\"withdrawal_history\".\"created_at\""},
UpdatedAt: whereHelperstring{field: "\"withdrawal_history\".\"updated_at\""},
ID: whereHelperstring{field: "\"withdrawal_history\".\"id\""},
ExchangeNameID: whereHelperstring{field: "\"withdrawal_history\".\"exchange_name_id\""},
ExchangeID: whereHelperstring{field: "\"withdrawal_history\".\"exchange_id\""},
Status: whereHelperstring{field: "\"withdrawal_history\".\"status\""},
Currency: whereHelperstring{field: "\"withdrawal_history\".\"currency\""},
Amount: whereHelperfloat64{field: "\"withdrawal_history\".\"amount\""},
Description: whereHelpernull_String{field: "\"withdrawal_history\".\"description\""},
WithdrawType: whereHelperint64{field: "\"withdrawal_history\".\"withdraw_type\""},
CreatedAt: whereHelperstring{field: "\"withdrawal_history\".\"created_at\""},
UpdatedAt: whereHelperstring{field: "\"withdrawal_history\".\"updated_at\""},
}
// WithdrawalHistoryRels is where relationship names are stored.
var WithdrawalHistoryRels = struct {
ExchangeName string
WithdrawalCryptos string
WithdrawalFiats string
}{
ExchangeName: "ExchangeName",
WithdrawalCryptos: "WithdrawalCryptos",
WithdrawalFiats: "WithdrawalFiats",
}
// withdrawalHistoryR is where relationships are stored.
type withdrawalHistoryR struct {
ExchangeName *Exchange
WithdrawalCryptos WithdrawalCryptoSlice
WithdrawalFiats WithdrawalFiatSlice
}
@@ -112,8 +115,8 @@ func (*withdrawalHistoryR) NewStruct() *withdrawalHistoryR {
type withdrawalHistoryL struct{}
var (
withdrawalHistoryAllColumns = []string{"id", "exchange", "exchange_id", "status", "currency", "amount", "description", "withdraw_type", "created_at", "updated_at"}
withdrawalHistoryColumnsWithoutDefault = []string{"id", "exchange", "exchange_id", "status", "currency", "amount", "description", "withdraw_type"}
withdrawalHistoryAllColumns = []string{"id", "exchange_name_id", "exchange_id", "status", "currency", "amount", "description", "withdraw_type", "created_at", "updated_at"}
withdrawalHistoryColumnsWithoutDefault = []string{"id", "exchange_name_id", "exchange_id", "status", "currency", "amount", "description", "withdraw_type"}
withdrawalHistoryColumnsWithDefault = []string{"created_at", "updated_at"}
withdrawalHistoryPrimaryKeyColumns = []string{"id"}
)
@@ -393,6 +396,20 @@ func (q withdrawalHistoryQuery) Exists(ctx context.Context, exec boil.ContextExe
return count > 0, nil
}
// ExchangeName pointed to by the foreign key.
func (o *WithdrawalHistory) ExchangeName(mods ...qm.QueryMod) exchangeQuery {
queryMods := []qm.QueryMod{
qm.Where("\"id\" = ?", o.ExchangeNameID),
}
queryMods = append(queryMods, mods...)
query := Exchanges(queryMods...)
queries.SetFrom(query.Query, "\"exchange\"")
return query
}
// WithdrawalCryptos retrieves all the withdrawal_crypto's WithdrawalCryptos with an executor.
func (o *WithdrawalHistory) WithdrawalCryptos(mods ...qm.QueryMod) withdrawalCryptoQuery {
var queryMods []qm.QueryMod
@@ -435,6 +452,107 @@ func (o *WithdrawalHistory) WithdrawalFiats(mods ...qm.QueryMod) withdrawalFiatQ
return query
}
// LoadExchangeName allows an eager lookup of values, cached into the
// loaded structs of the objects. This is for an N-1 relationship.
func (withdrawalHistoryL) LoadExchangeName(ctx context.Context, e boil.ContextExecutor, singular bool, maybeWithdrawalHistory interface{}, mods queries.Applicator) error {
var slice []*WithdrawalHistory
var object *WithdrawalHistory
if singular {
object = maybeWithdrawalHistory.(*WithdrawalHistory)
} else {
slice = *maybeWithdrawalHistory.(*[]*WithdrawalHistory)
}
args := make([]interface{}, 0, 1)
if singular {
if object.R == nil {
object.R = &withdrawalHistoryR{}
}
args = append(args, object.ExchangeNameID)
} else {
Outer:
for _, obj := range slice {
if obj.R == nil {
obj.R = &withdrawalHistoryR{}
}
for _, a := range args {
if a == obj.ExchangeNameID {
continue Outer
}
}
args = append(args, obj.ExchangeNameID)
}
}
if len(args) == 0 {
return nil
}
query := NewQuery(qm.From(`exchange`), qm.WhereIn(`exchange.id in ?`, args...))
if mods != nil {
mods.Apply(query)
}
results, err := query.QueryContext(ctx, e)
if err != nil {
return errors.Wrap(err, "failed to eager load Exchange")
}
var resultSlice []*Exchange
if err = queries.Bind(results, &resultSlice); err != nil {
return errors.Wrap(err, "failed to bind eager loaded slice Exchange")
}
if err = results.Close(); err != nil {
return errors.Wrap(err, "failed to close results of eager load for exchange")
}
if err = results.Err(); err != nil {
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for exchange")
}
if len(withdrawalHistoryAfterSelectHooks) != 0 {
for _, obj := range resultSlice {
if err := obj.doAfterSelectHooks(ctx, e); err != nil {
return err
}
}
}
if len(resultSlice) == 0 {
return nil
}
if singular {
foreign := resultSlice[0]
object.R.ExchangeName = foreign
if foreign.R == nil {
foreign.R = &exchangeR{}
}
foreign.R.ExchangeNameWithdrawalHistories = append(foreign.R.ExchangeNameWithdrawalHistories, object)
return nil
}
for _, local := range slice {
for _, foreign := range resultSlice {
if local.ExchangeNameID == foreign.ID {
local.R.ExchangeName = foreign
if foreign.R == nil {
foreign.R = &exchangeR{}
}
foreign.R.ExchangeNameWithdrawalHistories = append(foreign.R.ExchangeNameWithdrawalHistories, local)
break
}
}
}
return nil
}
// LoadWithdrawalCryptos allows an eager lookup of values, cached into the
// loaded structs of the objects. This is for a 1-M or N-M relationship.
func (withdrawalHistoryL) LoadWithdrawalCryptos(ctx context.Context, e boil.ContextExecutor, singular bool, maybeWithdrawalHistory interface{}, mods queries.Applicator) error {
@@ -625,6 +743,53 @@ func (withdrawalHistoryL) LoadWithdrawalFiats(ctx context.Context, e boil.Contex
return nil
}
// SetExchangeName of the withdrawalHistory to the related item.
// Sets o.R.ExchangeName to related.
// Adds o to related.R.ExchangeNameWithdrawalHistories.
func (o *WithdrawalHistory) SetExchangeName(ctx context.Context, exec boil.ContextExecutor, insert bool, related *Exchange) error {
var err error
if insert {
if err = related.Insert(ctx, exec, boil.Infer()); err != nil {
return errors.Wrap(err, "failed to insert into foreign table")
}
}
updateQuery := fmt.Sprintf(
"UPDATE \"withdrawal_history\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, []string{"exchange_name_id"}),
strmangle.WhereClause("\"", "\"", 0, withdrawalHistoryPrimaryKeyColumns),
)
values := []interface{}{related.ID, o.ID}
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, updateQuery)
fmt.Fprintln(boil.DebugWriter, values)
}
if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil {
return errors.Wrap(err, "failed to update local table")
}
o.ExchangeNameID = related.ID
if o.R == nil {
o.R = &withdrawalHistoryR{
ExchangeName: related,
}
} else {
o.R.ExchangeName = related
}
if related.R == nil {
related.R = &exchangeR{
ExchangeNameWithdrawalHistories: WithdrawalHistorySlice{o},
}
} else {
related.R.ExchangeNameWithdrawalHistories = append(related.R.ExchangeNameWithdrawalHistories, o)
}
return nil
}
// AddWithdrawalCryptos adds the given related objects to the existing relationships
// of the withdrawal_history, optionally inserting them as new records.
// Appends related to o.R.WithdrawalCryptos.

View File

@@ -800,6 +800,114 @@ func testWithdrawalHistoryToManyAddOpWithdrawalFiats(t *testing.T) {
}
}
}
func testWithdrawalHistoryToOneExchangeUsingExchangeName(t *testing.T) {
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
var local WithdrawalHistory
var foreign Exchange
seed := randomize.NewSeed()
if err := randomize.Struct(seed, &local, withdrawalHistoryDBTypes, false, withdrawalHistoryColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
}
if err := randomize.Struct(seed, &foreign, exchangeDBTypes, false, exchangeColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize Exchange struct: %s", err)
}
if err := foreign.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
local.ExchangeNameID = foreign.ID
if err := local.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
check, err := local.ExchangeName().One(ctx, tx)
if err != nil {
t.Fatal(err)
}
if check.ID != foreign.ID {
t.Errorf("want: %v, got %v", foreign.ID, check.ID)
}
slice := WithdrawalHistorySlice{&local}
if err = local.L.LoadExchangeName(ctx, tx, false, (*[]*WithdrawalHistory)(&slice), nil); err != nil {
t.Fatal(err)
}
if local.R.ExchangeName == nil {
t.Error("struct should have been eager loaded")
}
local.R.ExchangeName = nil
if err = local.L.LoadExchangeName(ctx, tx, true, &local, nil); err != nil {
t.Fatal(err)
}
if local.R.ExchangeName == nil {
t.Error("struct should have been eager loaded")
}
}
func testWithdrawalHistoryToOneSetOpExchangeUsingExchangeName(t *testing.T) {
var err error
ctx := context.Background()
tx := MustTx(boil.BeginTx(ctx, nil))
defer func() { _ = tx.Rollback() }()
var a WithdrawalHistory
var b, c Exchange
seed := randomize.NewSeed()
if err = randomize.Struct(seed, &a, withdrawalHistoryDBTypes, false, strmangle.SetComplement(withdrawalHistoryPrimaryKeyColumns, withdrawalHistoryColumnsWithoutDefault)...); err != nil {
t.Fatal(err)
}
if err = randomize.Struct(seed, &b, exchangeDBTypes, false, strmangle.SetComplement(exchangePrimaryKeyColumns, exchangeColumnsWithoutDefault)...); err != nil {
t.Fatal(err)
}
if err = randomize.Struct(seed, &c, exchangeDBTypes, false, strmangle.SetComplement(exchangePrimaryKeyColumns, exchangeColumnsWithoutDefault)...); err != nil {
t.Fatal(err)
}
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
t.Fatal(err)
}
for i, x := range []*Exchange{&b, &c} {
err = a.SetExchangeName(ctx, tx, i != 0, x)
if err != nil {
t.Fatal(err)
}
if a.R.ExchangeName != x {
t.Error("relationship struct not set to correct value")
}
if x.R.ExchangeNameWithdrawalHistories[0] != &a {
t.Error("failed to append to foreign relationship struct")
}
if a.ExchangeNameID != x.ID {
t.Error("foreign key was wrong value", a.ExchangeNameID)
}
zero := reflect.Zero(reflect.TypeOf(a.ExchangeNameID))
reflect.Indirect(reflect.ValueOf(&a.ExchangeNameID)).Set(zero)
if err = a.Reload(ctx, tx); err != nil {
t.Fatal("failed to reload", err)
}
if a.ExchangeNameID != x.ID {
t.Error("foreign key was wrong value", a.ExchangeNameID, x.ID)
}
}
}
func testWithdrawalHistoriesReload(t *testing.T) {
t.Parallel()
@@ -875,7 +983,7 @@ func testWithdrawalHistoriesSelect(t *testing.T) {
}
var (
withdrawalHistoryDBTypes = map[string]string{`ID`: `TEXT`, `Exchange`: `TEXT`, `ExchangeID`: `TEXT`, `Status`: `TEXT`, `Currency`: `TEXT`, `Amount`: `REAL`, `Description`: `TEXT`, `WithdrawType`: `INTEGER`, `CreatedAt`: `TIMESTAMP`, `UpdatedAt`: `TIMESTAMP`}
withdrawalHistoryDBTypes = map[string]string{`ID`: `TEXT`, `ExchangeNameID`: `TEXT`, `ExchangeID`: `TEXT`, `Status`: `TEXT`, `Currency`: `TEXT`, `Amount`: `REAL`, `Description`: `TEXT`, `WithdrawType`: `INTEGER`, `CreatedAt`: `TIMESTAMP`, `UpdatedAt`: `TIMESTAMP`}
_ = bytes.MinRead
)

View File

@@ -56,10 +56,6 @@ func Event(id, msgtype, message string) {
err = tx.Commit()
if err != nil {
log.Errorf(log.Global, "Event Transaction commit failed: %v", err)
err = tx.Rollback()
if err != nil {
log.Errorf(log.Global, "Event Transaction rollback failed: %v", err)
}
return
}
}

View File

@@ -4,16 +4,13 @@ import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"sync"
"testing"
"time"
"github.com/thrasher-corp/gocryptotrader/database"
"github.com/thrasher-corp/gocryptotrader/database/drivers"
"github.com/thrasher-corp/gocryptotrader/database/repository"
"github.com/thrasher-corp/gocryptotrader/database/testhelpers"
"github.com/thrasher-corp/goose"
)
func TestMain(m *testing.M) {
@@ -26,7 +23,6 @@ func TestMain(m *testing.M) {
}
t := m.Run()
err = os.RemoveAll(testhelpers.TempDir)
if err != nil {
fmt.Printf("Failed to remove temp db file: %v", err)
@@ -93,12 +89,6 @@ func TestAudit(t *testing.T) {
t.Fatal(err)
}
path := filepath.Join("..", "..", "migrations")
err = goose.Run("up", dbConn.SQL, repository.GetSQLDialect(), path, "")
if err != nil {
t.Fatalf("failed to run migrations %v", err)
}
if test.runner != nil {
test.runner(t)
}

View File

@@ -0,0 +1,270 @@
package candle
import (
"context"
"database/sql"
"encoding/csv"
"fmt"
"io"
"math"
"os"
"strconv"
"strings"
"time"
"github.com/gofrs/uuid"
"github.com/thrasher-corp/gocryptotrader/database"
modelPSQL "github.com/thrasher-corp/gocryptotrader/database/models/postgres"
modelSQLite "github.com/thrasher-corp/gocryptotrader/database/models/sqlite3"
"github.com/thrasher-corp/gocryptotrader/database/repository"
"github.com/thrasher-corp/gocryptotrader/database/repository/exchange"
"github.com/thrasher-corp/gocryptotrader/log"
"github.com/thrasher-corp/sqlboiler/boil"
"github.com/thrasher-corp/sqlboiler/queries/qm"
)
// Series returns candle data
func Series(exchangeName, base, quote string, interval int64, asset string, start, end time.Time) (out Item, err error) {
if exchangeName == "" || base == "" || quote == "" || asset == "" || interval <= 0 {
return out, errInvalidInput
}
queries := []qm.QueryMod{
qm.Where("base = ?", strings.ToUpper(base)),
qm.Where("quote = ?", strings.ToUpper(quote)),
qm.Where("interval = ?", interval),
qm.Where("asset = ?", asset),
qm.Where("timestamp between ? and ?", start.UTC(), end.UTC()),
}
exchangeUUID, errS := exchange.UUIDByName(exchangeName)
if errS != nil {
return out, errS
}
queries = append(queries, qm.Where("exchange_name_id = ?", exchangeUUID.String()))
if repository.GetSQLDialect() == database.DBSQLite3 {
retCandle, errC := modelSQLite.Candles(queries...).All(context.Background(), database.DB.SQL)
if errC != nil {
return out, errC
}
for x := range retCandle {
t, errT := time.Parse(time.RFC3339, retCandle[x].Timestamp)
if errT != nil {
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,
})
}
} else {
retCandle, errC := modelPSQL.Candles(queries...).All(context.Background(), database.DB.SQL)
if errC != nil {
return out, errC
}
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,
})
}
}
if len(out.Candles) < 1 {
return out, fmt.Errorf(errNoCandleDataFound, exchangeName, base, quote, interval, asset)
}
out.ExchangeID = exchangeName
out.Interval = interval
out.Base = base
out.Quote = quote
out.Asset = asset
return out, err
}
// Insert series of candles
func Insert(in *Item) (uint64, error) {
if database.DB.SQL == nil {
return 0, database.ErrDatabaseSupportDisabled
}
if len(in.Candles) < 1 {
return 0, errNoCandleData
}
ctx := context.Background()
tx, err := database.DB.SQL.BeginTx(ctx, nil)
if err != nil {
return 0, err
}
var totalInserted uint64
if repository.GetSQLDialect() == database.DBSQLite3 {
totalInserted, err = insertSQLite(ctx, tx, in)
} else {
totalInserted, err = insertPostgresSQL(ctx, tx, in)
}
if err != nil {
errRB := tx.Rollback()
if errRB != nil {
log.Errorln(log.DatabaseMgr, errRB)
}
return 0, err
}
err = tx.Commit()
if err != nil {
return 0, err
}
return totalInserted, nil
}
func insertSQLite(ctx context.Context, tx *sql.Tx, in *Item) (uint64, error) {
var totalInserted uint64
for x := range in.Candles {
var tempCandle = modelSQLite.Candle{
ExchangeNameID: in.ExchangeID,
Base: strings.ToUpper(in.Base),
Quote: strings.ToUpper(in.Quote),
Interval: strconv.FormatInt(in.Interval, 10),
Asset: in.Asset,
Timestamp: in.Candles[x].Timestamp.UTC().Format(time.RFC3339),
Open: in.Candles[x].Open,
High: in.Candles[x].High,
Low: in.Candles[x].Low,
Close: in.Candles[x].Close,
Volume: in.Candles[x].Volume,
}
tempUUID, err := uuid.NewV4()
if err != nil {
return 0, err
}
tempCandle.ID = tempUUID.String()
err = tempCandle.Insert(ctx, tx, boil.Infer())
if err != nil {
return 0, err
}
if totalInserted < math.MaxUint64 {
totalInserted++
}
}
return totalInserted, nil
}
func insertPostgresSQL(ctx context.Context, tx *sql.Tx, in *Item) (uint64, error) {
var totalInserted uint64
for x := range in.Candles {
var tempCandle = modelPSQL.Candle{
ExchangeNameID: in.ExchangeID,
Base: strings.ToUpper(in.Base),
Quote: strings.ToUpper(in.Quote),
Interval: in.Interval,
Asset: in.Asset,
Timestamp: in.Candles[x].Timestamp,
Open: in.Candles[x].Open,
High: in.Candles[x].High,
Low: in.Candles[x].Low,
Close: in.Candles[x].Close,
Volume: in.Candles[x].Volume,
}
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
}
if totalInserted < math.MaxUint64 {
totalInserted++
}
}
return totalInserted, nil
}
// InsertFromCSV load a CSV list of candle data and insert into database
func InsertFromCSV(exchangeName, base, quote string, interval int64, asset, file string) (uint64, error) {
csvFile, err := os.Open(file)
if err != nil {
return 0, err
}
defer func() {
err = csvFile.Close()
if err != nil {
log.Errorln(log.Global, err)
}
}()
csvData := csv.NewReader(csvFile)
exchangeUUID, err := exchange.UUIDByName(exchangeName)
if err != nil {
return 0, err
}
tempCandle := &Item{
ExchangeID: exchangeUUID.String(),
Base: base,
Quote: quote,
Interval: interval,
Asset: asset,
}
for {
row, errCSV := csvData.Read()
if errCSV != nil {
if errCSV == io.EOF {
break
}
return 0, errCSV
}
tempTick := Candle{}
v, errParse := strconv.ParseInt(row[0], 10, 32)
if errParse != nil {
return 0, errParse
}
tempTick.Timestamp = time.Unix(v, 0).UTC()
if tempTick.Timestamp.IsZero() {
err = fmt.Errorf("invalid timestamp received on row %v", row)
break
}
tempTick.Volume, err = strconv.ParseFloat(row[1], 64)
if err != nil {
break
}
tempTick.Open, err = strconv.ParseFloat(row[2], 64)
if err != nil {
break
}
tempTick.High, err = strconv.ParseFloat(row[3], 64)
if err != nil {
break
}
tempTick.Low, err = strconv.ParseFloat(row[4], 64)
if err != nil {
break
}
tempTick.Close, err = strconv.ParseFloat(row[5], 64)
if err != nil {
break
}
tempCandle.Candles = append(tempCandle.Candles, tempTick)
}
if err != nil {
return 0, err
}
return Insert(tempCandle)
}

View File

@@ -0,0 +1,306 @@
package candle
import (
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
"time"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/database"
"github.com/thrasher-corp/gocryptotrader/database/drivers"
"github.com/thrasher-corp/gocryptotrader/database/repository/exchange"
"github.com/thrasher-corp/gocryptotrader/database/testhelpers"
)
var (
verbose = false
testExchanges = []exchange.Details{
{
Name: "one",
},
{
Name: "two",
},
}
)
func TestMain(m *testing.M) {
if verbose {
testhelpers.EnableVerboseTestOutput()
}
var err error
testhelpers.PostgresTestDatabase = testhelpers.GetConnectionDetails()
testhelpers.TempDir, err = ioutil.TempDir("", "gct-temp")
if err != nil {
fmt.Printf("failed to create temp file: %v", err)
os.Exit(1)
}
t := m.Run()
err = os.RemoveAll(testhelpers.TempDir)
if err != nil {
fmt.Printf("Failed to remove temp db file: %v", err)
}
os.Exit(t)
}
func TestInsert(t *testing.T) {
testCases := []struct {
name string
config *database.Config
seedDB func(includeOHLCVData bool) error
runner func(t *testing.T)
closer func(dbConn *database.Instance) error
}{
{
name: "postgresql",
config: testhelpers.PostgresTestDatabase,
seedDB: seedDB,
},
{
name: "SQLite",
config: &database.Config{
Driver: database.DBSQLite3,
ConnectionDetails: drivers.ConnectionDetails{Database: "./testdb"},
},
seedDB: seedDB,
},
}
for x := range testCases {
test := testCases[x]
t.Run(test.name, func(t *testing.T) {
if !testhelpers.CheckValidConfig(&test.config.ConnectionDetails) {
t.Skip("database not configured skipping test")
}
dbConn, err := testhelpers.ConnectToDatabase(test.config)
if err != nil {
t.Fatal(err)
}
if test.seedDB != nil {
err = test.seedDB(false)
if err != nil {
t.Fatal(err)
}
}
data, err := genOHCLVData()
if err != nil {
t.Fatal(err)
}
r, err := Insert(&data)
if err != nil {
t.Fatal(err)
}
if r != 365 {
t.Fatalf("unexpected number inserted: %v", r)
}
err = testhelpers.CloseDatabase(dbConn)
if err != nil {
t.Error(err)
}
})
}
}
func TestInsertFromCSV(t *testing.T) {
testCases := []struct {
name string
config *database.Config
seedDB func(includeOHLCVData bool) error
runner func(t *testing.T)
closer func(dbConn *database.Instance) error
}{
{
name: "postgresql",
config: testhelpers.PostgresTestDatabase,
seedDB: seedDB,
},
{
name: "SQLite",
config: &database.Config{
Driver: database.DBSQLite3,
ConnectionDetails: drivers.ConnectionDetails{Database: "./testdb"},
},
seedDB: seedDB,
},
}
for x := range testCases {
test := testCases[x]
t.Run(test.name, func(t *testing.T) {
if !testhelpers.CheckValidConfig(&test.config.ConnectionDetails) {
t.Skip("database not configured skipping test")
}
dbConn, err := testhelpers.ConnectToDatabase(test.config)
if err != nil {
t.Fatal(err)
}
if test.seedDB != nil {
err = test.seedDB(false)
if err != nil {
t.Fatal(err)
}
}
exchange.ResetExchangeCache()
testFile := filepath.Join("..", "..", "..", "testdata", "binance_BTCUSDT_24h_2019_01_01_2020_01_01.csv")
count, err := InsertFromCSV(testExchanges[0].Name, "BTC", "USDT", 86400, "spot", testFile)
if err != nil {
t.Fatal(err)
}
if count != 365 {
t.Fatalf("expected 365 results to be inserted received: %v", count)
}
err = testhelpers.CloseDatabase(dbConn)
if err != nil {
t.Error(err)
}
})
}
}
func TestSeries(t *testing.T) {
testCases := []struct {
name string
config *database.Config
seedDB func(includeOHLCVData bool) error
runner func(t *testing.T)
closer func(dbConn *database.Instance) error
}{
{
name: "postgresql",
config: testhelpers.PostgresTestDatabase,
seedDB: seedDB,
},
{
name: "SQLite",
config: &database.Config{
Driver: database.DBSQLite3,
ConnectionDetails: drivers.ConnectionDetails{Database: "./testdb"},
},
seedDB: seedDB,
},
}
for x := range testCases {
test := testCases[x]
t.Run(test.name, func(t *testing.T) {
if !testhelpers.CheckValidConfig(&test.config.ConnectionDetails) {
t.Skip("database not configured skipping test")
}
dbConn, err := testhelpers.ConnectToDatabase(test.config)
if err != nil {
t.Fatal(err)
}
if test.seedDB != nil {
err = test.seedDB(true)
if err != nil {
t.Fatal(err)
}
}
start := time.Date(2019, 1, 1, 0, 0, 0, 0, time.UTC)
end := time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)
ret, err := Series(testExchanges[0].Name,
"BTC", "USDT",
86400, "spot",
start, end)
if err != nil {
t.Fatal(err)
}
if len(ret.Candles) != 365 {
t.Errorf("unexpected number of results received: %v", len(ret.Candles))
}
ret, err = Series("", "", "", 0, "", start, end)
if err != nil {
if !errors.Is(err, errInvalidInput) {
t.Fatal(err)
}
}
ret, err = Series(testExchanges[0].Name,
"BTC", "MOON",
864000, "spot",
start, end)
if err != nil {
if !errors.Is(err, errInvalidInput) {
if err.Error() != fmt.Errorf(errNoCandleDataFound, testExchanges[0].Name,
"BTC", "MOON",
"864000", "spot").Error() {
t.Fatal(err)
}
}
}
err = testhelpers.CloseDatabase(dbConn)
if err != nil {
t.Error(err)
}
})
}
}
func seedDB(includeOHLCVData bool) error {
err := exchange.InsertMany(testExchanges)
if err != nil {
return err
}
if includeOHLCVData {
exchange.ResetExchangeCache()
data, err := genOHCLVData()
if err != nil {
return err
}
_, err = Insert(&data)
return err
}
return nil
}
func genOHCLVData() (out Item, err error) {
exchangeUUID, err := exchange.UUIDByName(testExchanges[0].Name)
if err != nil {
return
}
out.ExchangeID = exchangeUUID.String()
out.Base = currency.BTC.String()
out.Quote = currency.USDT.String()
out.Interval = 86400
out.Asset = "spot"
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,
})
}
return out, nil
}

View File

@@ -0,0 +1,36 @@
package candle
import (
"errors"
"time"
)
const (
errNoCandleDataFound = "no candle data found: %v %v %v %v %v"
)
var (
errInvalidInput = errors.New("exchange, base , quote, asset, interval, start & end cannot be empty")
errNoCandleData = errors.New("no candle data provided")
)
// Item generic candle holder for modelPSQL & modelSQLite
type Item struct {
ID string
ExchangeID string
Base string
Quote string
Interval int64
Asset string
Candles []Candle
}
// Candle holds each interval
type Candle struct {
Timestamp time.Time
Open float64
High float64
Low float64
Close float64
Volume float64
}

View File

@@ -0,0 +1,229 @@
package exchange
import (
"context"
"database/sql"
"encoding/csv"
"io"
"os"
"strings"
"github.com/gofrs/uuid"
"github.com/thrasher-corp/gocryptotrader/common/cache"
"github.com/thrasher-corp/gocryptotrader/database"
modelPSQL "github.com/thrasher-corp/gocryptotrader/database/models/postgres"
modelSQLite "github.com/thrasher-corp/gocryptotrader/database/models/sqlite3"
"github.com/thrasher-corp/gocryptotrader/database/repository"
"github.com/thrasher-corp/gocryptotrader/log"
"github.com/thrasher-corp/sqlboiler/boil"
"github.com/thrasher-corp/sqlboiler/queries/qm"
)
// One returns one exchange by Name
func One(in string) (Details, error) {
return one(in, "name")
}
// OneByUUID returns one exchange by UUID
func OneByUUID(in uuid.UUID) (Details, error) {
return one(in.String(), "id")
}
// one returns one exchange by clause
func one(in, clause string) (out Details, err error) {
if database.DB.SQL == nil {
return out, database.ErrDatabaseSupportDisabled
}
whereQM := qm.Where(clause+"= ?", in)
if repository.GetSQLDialect() == database.DBSQLite3 {
ret, errS := modelSQLite.Exchanges(whereQM).One(context.Background(), database.DB.SQL)
if errS != nil {
return out, errS
}
out.Name = ret.Name
out.UUID, errS = uuid.FromString(ret.ID)
if errS != nil {
return out, errS
}
} else {
ret, errS := modelPSQL.Exchanges(whereQM).One(context.Background(), database.DB.SQL)
if errS != nil {
return out, errS
}
out.Name = ret.Name
out.UUID, errS = uuid.FromString(ret.ID)
if errS != nil {
return out, errS
}
}
return out, err
}
// Insert writes a single entry into database
func Insert(in Details) error {
if database.DB.SQL == nil {
return database.ErrDatabaseSupportDisabled
}
ctx := context.Background()
tx, err := database.DB.SQL.BeginTx(ctx, nil)
if err != nil {
return err
}
if repository.GetSQLDialect() == database.DBSQLite3 {
err = insertSQLite(ctx, tx, []Details{in})
} else {
err = insertPostgresql(ctx, tx, []Details{in})
}
if err != nil {
errRB := tx.Rollback()
if errRB != nil {
log.Errorln(log.DatabaseMgr, errRB)
}
return err
}
err = tx.Commit()
if err != nil {
return err
}
return nil
}
// InsertMany writes multiple entries into database
func InsertMany(in []Details) error {
if database.DB.SQL == nil {
return database.ErrDatabaseSupportDisabled
}
ctx := context.Background()
tx, err := database.DB.SQL.BeginTx(ctx, nil)
if err != nil {
return err
}
if repository.GetSQLDialect() == database.DBSQLite3 {
err = insertSQLite(ctx, tx, in)
} else {
err = insertPostgresql(ctx, tx, in)
}
if err != nil {
errRB := tx.Rollback()
if errRB != nil {
log.Errorln(log.DatabaseMgr, errRB)
}
return err
}
err = tx.Commit()
if err != nil {
errRB := tx.Rollback()
if errRB != nil {
log.Errorln(log.DatabaseMgr, errRB)
}
return err
}
return nil
}
func insertSQLite(ctx context.Context, tx *sql.Tx, in []Details) (err error) {
for x := range in {
tempUUID, errUUID := uuid.NewV4()
if errUUID != nil {
return errUUID
}
var tempInsert = modelSQLite.Exchange{
Name: in[x].Name,
ID: tempUUID.String(),
}
err = tempInsert.Insert(ctx, tx, boil.Infer())
if err != nil {
errRB := tx.Rollback()
if errRB != nil {
log.Errorln(log.DatabaseMgr, errRB)
}
return err
}
}
return nil
}
func insertPostgresql(ctx context.Context, tx *sql.Tx, in []Details) (err error) {
for x := range in {
var tempInsert = modelPSQL.Exchange{
Name: in[x].Name,
}
err = tempInsert.Upsert(ctx, tx, true, []string{"name"}, boil.Infer(), boil.Infer())
if err != nil {
errRB := tx.Rollback()
if errRB != nil {
log.Errorln(log.DatabaseMgr, errRB)
}
return
}
}
return nil
}
// UUIDByName returns UUID of exchange
func UUIDByName(exchange string) (uuid.UUID, error) {
exchange = strings.ToLower(exchange)
v := exchangeCache.Get(exchange)
if v != nil {
return v.(uuid.UUID), nil
}
ret, err := One(exchange)
if err != nil {
if err != sql.ErrNoRows {
return uuid.UUID{}, err
}
return uuid.UUID{}, ErrNoExchangeFound
}
exchangeCache.Add(exchange, ret.UUID)
return ret.UUID, nil
}
// ResetExchangeCache reinitialise cache to blank state used to clear cache for testing
func ResetExchangeCache() {
exchangeCache = cache.New(10)
}
// LoadCSV loads & parses a CSV list of exchanges
func LoadCSV(file string) (out []Details, err error) {
csvFile, err := os.Open(file)
if err != nil {
return out, err
}
defer func() {
err = csvFile.Close()
if err != nil {
log.Errorln(log.Global, err)
}
}()
csvData := csv.NewReader(csvFile)
for {
row, errCSV := csvData.Read()
if errCSV != nil {
if errCSV == io.EOF {
return out, err
}
return out, errCSV
}
out = append(out, Details{
Name: row[0],
})
}
}

View File

@@ -0,0 +1,184 @@
package exchange
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/thrasher-corp/gocryptotrader/database"
"github.com/thrasher-corp/gocryptotrader/database/drivers"
"github.com/thrasher-corp/gocryptotrader/database/testhelpers"
)
var (
verbose = false
testExchanges = []Details{
{
Name: "one",
},
{
Name: "two",
},
{
Name: "three",
},
}
)
func TestMain(m *testing.M) {
if verbose {
testhelpers.EnableVerboseTestOutput()
}
var err error
testhelpers.PostgresTestDatabase = testhelpers.GetConnectionDetails()
testhelpers.TempDir, err = ioutil.TempDir("", "gct-temp")
if err != nil {
fmt.Printf("failed to create temp file: %v", err)
os.Exit(1)
}
t := m.Run()
err = os.RemoveAll(testhelpers.TempDir)
if err != nil {
fmt.Printf("Failed to remove temp db file: %v", err)
}
os.Exit(t)
}
func TestInsertMany(t *testing.T) {
testCases := []struct {
name string
config *database.Config
seedDB func() error
runner func(t *testing.T)
closer func(dbConn *database.Instance) error
}{
{
name: "postgresql",
config: testhelpers.PostgresTestDatabase,
seedDB: seed,
},
{
name: "SQLite",
config: &database.Config{
Driver: database.DBSQLite3,
ConnectionDetails: drivers.ConnectionDetails{Database: "./testdb"},
},
seedDB: seed,
},
}
for x := range testCases {
test := testCases[x]
t.Run(test.name, func(t *testing.T) {
if !testhelpers.CheckValidConfig(&test.config.ConnectionDetails) {
t.Skip("database not configured skipping test")
}
dbConn, err := testhelpers.ConnectToDatabase(test.config)
if err != nil {
t.Fatal(err)
}
if test.seedDB != nil {
err = test.seedDB()
if err != nil {
t.Error(err)
}
}
err = InsertMany(testExchanges)
if err != nil {
t.Fatal(err)
}
err = testhelpers.CloseDatabase(dbConn)
if err != nil {
t.Error(err)
}
})
}
}
func TestOneAndOneByUUID(t *testing.T) {
testCases := []struct {
name string
config *database.Config
seedDB func() error
runner func(t *testing.T)
closer func(dbConn *database.Instance) error
}{
{
name: "postgresql",
config: testhelpers.PostgresTestDatabase,
seedDB: seed,
},
{
name: "SQLite",
config: &database.Config{
Driver: database.DBSQLite3,
ConnectionDetails: drivers.ConnectionDetails{Database: "./testdb"},
},
seedDB: seed,
},
}
for x := range testCases {
test := testCases[x]
t.Run(test.name, func(t *testing.T) {
if !testhelpers.CheckValidConfig(&test.config.ConnectionDetails) {
t.Skip("database not configured skipping test")
}
dbConn, err := testhelpers.ConnectToDatabase(test.config)
if err != nil {
t.Fatal(err)
}
if test.seedDB != nil {
err = test.seedDB()
if err != nil {
t.Error(err)
}
}
ret, err := One("one")
if err != nil {
t.Fatal(err)
}
ret2, err := OneByUUID(ret.UUID)
if err != nil {
t.Fatal(err)
}
if ret.Name != ret2.Name {
t.Fatalf("unexpected value received: %v", ret2.Name)
}
err = testhelpers.CloseDatabase(dbConn)
if err != nil {
t.Error(err)
}
})
}
}
func seed() error {
return InsertMany(testExchanges)
}
func TestLoadCSV(t *testing.T) {
testData := filepath.Join("..", "..", "..", "testdata", "exchangelist.csv")
_, err := LoadCSV(testData)
if err != nil {
t.Fatal(err)
}
}

View File

@@ -0,0 +1,19 @@
package exchange
import (
"errors"
"github.com/gofrs/uuid"
"github.com/thrasher-corp/gocryptotrader/common/cache"
)
var (
exchangeCache = cache.New(10)
ErrNoExchangeFound = errors.New("exchange not found")
)
// Details holds exchange information such as Name
type Details struct {
UUID uuid.UUID
Name string
}

View File

@@ -0,0 +1,44 @@
package repository
import (
"testing"
"github.com/thrasher-corp/gocryptotrader/database"
)
func TestGetSQLDialect(t *testing.T) {
testCases := []struct {
driver string
expectedReturn string
}{
{
"postgresql",
database.DBPostgreSQL,
},
{
"sqlite",
database.DBSQLite3,
},
{
"sqlite3",
database.DBSQLite3,
},
{
"invalid",
database.DBInvalidDriver,
},
}
for x := range testCases {
test := testCases[x]
t.Run(test.driver, func(t *testing.T) {
database.DB.Config = &database.Config{
Driver: test.driver,
}
ret := GetSQLDialect()
if ret != test.expectedReturn {
t.Fatalf("unexpected return: %v", ret)
}
})
}
}

View File

@@ -118,9 +118,5 @@ func Event(id, name, path string, data null.Bytes, executionType, status string,
err = tx.Commit()
if err != nil {
log.Errorf(log.DatabaseMgr, "Event Transaction commit failed: %v", err)
err = tx.Rollback()
if err != nil {
log.Errorf(log.DatabaseMgr, "Event Transaction rollback failed: %v", err)
}
}
}

View File

@@ -4,19 +4,20 @@ import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"sync"
"testing"
"time"
"github.com/thrasher-corp/gocryptotrader/database"
"github.com/thrasher-corp/gocryptotrader/database/drivers"
"github.com/thrasher-corp/gocryptotrader/database/repository"
"github.com/thrasher-corp/gocryptotrader/database/testhelpers"
"github.com/thrasher-corp/goose"
"github.com/volatiletech/null"
)
var (
verbose = false
)
func TestMain(m *testing.M) {
var err error
testhelpers.PostgresTestDatabase = testhelpers.GetConnectionDetails()
@@ -26,6 +27,10 @@ func TestMain(m *testing.M) {
os.Exit(1)
}
if verbose {
testhelpers.EnableVerboseTestOutput()
}
t := m.Run()
err = os.RemoveAll(testhelpers.TempDir)
@@ -63,8 +68,8 @@ func TestScript(t *testing.T) {
},
}
for _, tests := range testCases {
test := tests
for x := range testCases {
test := testCases[x]
t.Run(test.name, func(t *testing.T) {
if !testhelpers.CheckValidConfig(&test.config.ConnectionDetails) {
t.Skip("database not configured skipping test")
@@ -75,12 +80,6 @@ func TestScript(t *testing.T) {
t.Fatal(err)
}
path := filepath.Join("..", "..", "migrations")
err = goose.Run("up", dbConn.SQL, repository.GetSQLDialect(), path, "")
if err != nil {
t.Fatalf("failed to run migrations %v", err)
}
if test.runner != nil {
test.runner()
}

View File

@@ -12,6 +12,7 @@ import (
modelPSQL "github.com/thrasher-corp/gocryptotrader/database/models/postgres"
modelSQLite "github.com/thrasher-corp/gocryptotrader/database/models/sqlite3"
"github.com/thrasher-corp/gocryptotrader/database/repository"
exchangeDB "github.com/thrasher-corp/gocryptotrader/database/repository/exchange"
"github.com/thrasher-corp/gocryptotrader/log"
"github.com/thrasher-corp/gocryptotrader/portfolio/banking"
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
@@ -33,6 +34,13 @@ func Event(res *withdraw.Response) {
ctx := context.Background()
ctx = boil.SkipTimestamps(ctx)
exchangeUUID, err := exchangeDB.UUIDByName(res.Exchange.Name)
if err != nil {
log.Error(log.DatabaseMgr, err)
return
}
res.Exchange.Name = exchangeUUID.String()
tx, err := database.DB.SQL.BeginTx(ctx, nil)
if err != nil {
log.Errorf(log.DatabaseMgr, "Event transaction being failed: %v", err)
@@ -56,22 +64,18 @@ func Event(res *withdraw.Response) {
err = tx.Commit()
if err != nil {
log.Errorf(log.DatabaseMgr, "Event Transaction commit failed: %v", err)
err = tx.Rollback()
if err != nil {
log.Errorf(log.DatabaseMgr, "Event Transaction rollback failed: %v", err)
}
return
}
}
func addPSQLEvent(ctx context.Context, tx *sql.Tx, res *withdraw.Response) (err error) {
var tempEvent = modelPSQL.WithdrawalHistory{
Exchange: res.Exchange.Name,
ExchangeID: res.Exchange.ID,
Status: res.Exchange.Status,
Currency: res.RequestDetails.Currency.String(),
Amount: res.RequestDetails.Amount,
WithdrawType: int(res.RequestDetails.Type),
ExchangeNameID: res.Exchange.Name,
ExchangeID: res.Exchange.ID,
Status: res.Exchange.Status,
Currency: res.RequestDetails.Currency.String(),
Amount: res.RequestDetails.Amount,
WithdrawType: int(res.RequestDetails.Type),
}
if res.RequestDetails.Description != "" {
@@ -146,13 +150,13 @@ func addSQLiteEvent(ctx context.Context, tx *sql.Tx, res *withdraw.Response) (er
}
var tempEvent = modelSQLite.WithdrawalHistory{
ID: newUUID.String(),
Exchange: res.Exchange.Name,
ExchangeID: res.Exchange.ID,
Status: res.Exchange.Status,
Currency: res.RequestDetails.Currency.String(),
Amount: res.RequestDetails.Amount,
WithdrawType: int64(res.RequestDetails.Type),
ID: newUUID.String(),
ExchangeNameID: res.Exchange.Name,
ExchangeID: res.Exchange.ID,
Status: res.Exchange.Status,
Currency: res.RequestDetails.Currency.String(),
Amount: res.RequestDetails.Amount,
WithdrawType: int64(res.RequestDetails.Type),
}
if res.RequestDetails.Description != "" {
@@ -227,12 +231,22 @@ func GetEventByUUID(id string) (*withdraw.Response, error) {
// GetEventsByExchange returns all withdrawal requests by exchange
func GetEventsByExchange(exchange string, limit int) ([]*withdraw.Response, error) {
return getByColumns(generateWhereQuery([]string{"exchange"}, []string{exchange}, limit))
exch, err := exchangeDB.UUIDByName(exchange)
if err != nil {
log.Error(log.DatabaseMgr, err)
return nil, err
}
return getByColumns(generateWhereQuery([]string{"exchange_name_id"}, []string{exch.String()}, limit))
}
// GetEventByExchangeID return requested withdraw information by Exchange ID
func GetEventByExchangeID(exchange, id string) (*withdraw.Response, error) {
resp, err := getByColumns(generateWhereQuery([]string{"exchange", "exchange_id"}, []string{exchange, id}, 1))
exch, err := exchangeDB.UUIDByName(exchange)
if err != nil {
log.Error(log.DatabaseMgr, err)
return nil, err
}
resp, err := getByColumns(generateWhereQuery([]string{"exchange_name_id", "exchange_id"}, []string{exch.String(), id}, 1))
if err != nil {
return nil, err
}
@@ -245,7 +259,12 @@ func GetEventsByDate(exchange string, start, end time.Time, limit int) ([]*withd
if exchange == "" {
return getByColumns(betweenQuery)
}
return getByColumns(append(generateWhereQuery([]string{"exchange"}, []string{exchange}, 0), betweenQuery...))
exch, err := exchangeDB.UUIDByName(exchange)
if err != nil {
log.Error(log.DatabaseMgr, err)
return nil, err
}
return getByColumns(append(generateWhereQuery([]string{"exchange_name_id"}, []string{exch.String()}, 0), betweenQuery...))
}
func generateWhereQuery(columns, id []string, limit int) []qm.QueryMod {
@@ -284,7 +303,6 @@ func getByColumns(q []qm.QueryMod) ([]*withdraw.Response, error) {
tempResp.ID = newUUID
tempResp.Exchange = new(withdraw.ExchangeResponse)
tempResp.Exchange.ID = v[x].ExchangeID
tempResp.Exchange.Name = v[x].Exchange
tempResp.Exchange.Status = v[x].Status
tempResp.RequestDetails = new(withdraw.Request)
tempResp.RequestDetails = &withdraw.Request{
@@ -294,6 +312,19 @@ func getByColumns(q []qm.QueryMod) ([]*withdraw.Response, error) {
Type: withdraw.RequestType(v[x].WithdrawType),
}
exchangeName, err := v[x].ExchangeName().One(ctx, database.DB.SQL)
if err != nil {
log.Errorf(log.DatabaseMgr, "Unable to get exchange name")
tempUUID, errUUID := uuid.FromString(v[x].ExchangeNameID)
if errUUID != nil {
log.Errorf(log.DatabaseMgr, "invalid exchange name UUID for record %v", v[x].ID)
} else {
tempResp.Exchange.UUID = tempUUID
}
} else {
tempResp.Exchange.Name = exchangeName.Name
}
createdAtTime, err := time.Parse(time.RFC3339, v[x].CreatedAt)
if err != nil {
log.Errorf(log.DatabaseMgr, "record: %v has an incorrect time format ( %v ) - defaulting to empty time: %v", tempResp.ID, v[x].CreatedAt, err)
@@ -346,7 +377,6 @@ func getByColumns(q []qm.QueryMod) ([]*withdraw.Response, error) {
tempResp.ID = newUUID
tempResp.Exchange = new(withdraw.ExchangeResponse)
tempResp.Exchange.ID = v[x].ExchangeID
tempResp.Exchange.Name = v[x].Exchange
tempResp.Exchange.Status = v[x].Status
tempResp.RequestDetails = new(withdraw.Request)
tempResp.RequestDetails = &withdraw.Request{
@@ -358,6 +388,19 @@ func getByColumns(q []qm.QueryMod) ([]*withdraw.Response, error) {
tempResp.CreatedAt = v[x].CreatedAt
tempResp.UpdatedAt = v[x].UpdatedAt
exchangeName, err := v[x].ExchangeName().One(ctx, database.DB.SQL)
if err != nil {
log.Errorf(log.DatabaseMgr, "Unable to get exchange name")
tempUUID, errUUID := uuid.FromString(v[x].ExchangeNameID)
if errUUID != nil {
log.Errorf(log.DatabaseMgr, "invalid exchange name UUID for record %v", v[x].ID)
} else {
tempResp.Exchange.UUID = tempUUID
}
} else {
tempResp.Exchange.Name = exchangeName.Name
}
if withdraw.RequestType(v[x].WithdrawType) == withdraw.Crypto {
tempResp.RequestDetails.Crypto = new(withdraw.CryptoRequest)
x, err := v[x].WithdrawalCryptoWithdrawalCryptos().One(ctx, database.DB.SQL)

View File

@@ -6,22 +6,32 @@ import (
"io/ioutil"
"math/rand"
"os"
"path/filepath"
"sync"
"testing"
"time"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/database"
"github.com/thrasher-corp/gocryptotrader/database/drivers"
"github.com/thrasher-corp/gocryptotrader/database/repository"
"github.com/thrasher-corp/gocryptotrader/database/repository/exchange"
"github.com/thrasher-corp/gocryptotrader/database/testhelpers"
"github.com/thrasher-corp/gocryptotrader/portfolio/banking"
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
"github.com/thrasher-corp/goose"
)
var (
verbose = false
testExchanges = []exchange.Details{
{
Name: "one",
},
}
)
func TestMain(m *testing.M) {
if verbose {
testhelpers.EnableVerboseTestOutput()
}
var err error
testhelpers.PostgresTestDatabase = testhelpers.GetConnectionDetails()
testhelpers.TempDir, err = ioutil.TempDir("", "gct-temp")
@@ -79,10 +89,9 @@ func TestWithdraw(t *testing.T) {
t.Fatal(err)
}
path := filepath.Join("..", "..", "migrations")
err = goose.Run("up", dbConn.SQL, repository.GetSQLDialect(), path, "")
err = exchange.InsertMany(testExchanges)
if err != nil {
t.Fatalf("failed to run migrations %v", err)
t.Fatal(err)
}
if test.runner != nil {
@@ -99,45 +108,42 @@ func TestWithdraw(t *testing.T) {
}
}
func withdrawHelper(t *testing.T) {
t.Helper()
var wg sync.WaitGroup
func seedWithdrawData() {
for x := 0; x < 20; x++ {
wg.Add(1)
go func(x int) {
defer wg.Done()
test := fmt.Sprintf("test-%v", x)
resp := &withdraw.Response{
Exchange: &withdraw.ExchangeResponse{
Name: test,
ID: test,
Status: test,
},
RequestDetails: &withdraw.Request{
Exchange: test,
Description: test,
Amount: 1.0,
},
}
rnd := rand.Intn(2)
if rnd == 0 {
resp.RequestDetails.Currency = currency.AUD
resp.RequestDetails.Type = 1
resp.RequestDetails.Fiat = new(withdraw.FiatRequest)
resp.RequestDetails.Fiat.Bank = new(banking.Account)
} else {
resp.RequestDetails.Currency = currency.BTC
resp.RequestDetails.Type = 0
resp.RequestDetails.Crypto = new(withdraw.CryptoRequest)
resp.RequestDetails.Crypto.Address = test
resp.RequestDetails.Crypto.FeeAmount = 0
resp.RequestDetails.Crypto.AddressTag = test
}
Event(resp)
}(x)
test := fmt.Sprintf("test-%v", x)
resp := &withdraw.Response{
Exchange: &withdraw.ExchangeResponse{
Name: testExchanges[0].Name,
ID: test,
Status: test,
},
RequestDetails: &withdraw.Request{
Exchange: testExchanges[0].Name,
Description: test,
Amount: 1.0,
},
}
rnd := rand.Intn(2)
if rnd == 0 {
resp.RequestDetails.Currency = currency.AUD
resp.RequestDetails.Type = 1
resp.RequestDetails.Fiat = new(withdraw.FiatRequest)
resp.RequestDetails.Fiat.Bank = new(banking.Account)
} else {
resp.RequestDetails.Currency = currency.BTC
resp.RequestDetails.Type = 0
resp.RequestDetails.Crypto = new(withdraw.CryptoRequest)
resp.RequestDetails.Crypto.Address = test
resp.RequestDetails.Crypto.FeeAmount = 0
resp.RequestDetails.Crypto.AddressTag = test
}
exchange.ResetExchangeCache()
Event(resp)
}
}
func withdrawHelper(t *testing.T) {
seedWithdrawData()
wg.Wait()
_, err := GetEventByUUID(withdraw.DryRunID.String())
if err != nil {
if !errors.Is(err, ErrNoResults) {
@@ -145,27 +151,31 @@ func withdrawHelper(t *testing.T) {
}
}
v, err := GetEventsByExchange("test-1", 10)
v, err := GetEventsByExchange(testExchanges[0].Name, 10)
if err != nil {
t.Fatal(err)
t.Error(err)
}
_, err = GetEventByExchangeID("test-1", "test-1")
if v[0].Exchange.Name != testExchanges[0].Name {
t.Fatalf("expected name to be translated to valid string instead received: %v", v[0].Exchange.Name)
}
_, err = GetEventByExchangeID(testExchanges[0].Name, "test-1")
if err != nil {
t.Fatal(err)
t.Error(err)
}
if len(v) > 0 {
_, err = GetEventByUUID(v[0].ID.String())
if err != nil {
if !errors.Is(err, ErrNoResults) {
t.Fatal(err)
t.Error(err)
}
}
}
_, err = GetEventsByDate("test-1", time.Now().UTC().Add(-time.Minute), time.Now().UTC(), 5)
_, err = GetEventsByDate(testExchanges[0].Name, time.Now().UTC().Add(-time.Minute), time.Now().UTC(), 5)
if err != nil {
t.Fatal(err)
t.Error(err)
}
}

View File

@@ -1,13 +1,19 @@
package testhelpers
import (
"database/sql"
"os"
"path/filepath"
"reflect"
"github.com/thrasher-corp/gocryptotrader/database"
"github.com/thrasher-corp/gocryptotrader/database/drivers"
psqlConn "github.com/thrasher-corp/gocryptotrader/database/drivers/postgres"
sqliteConn "github.com/thrasher-corp/gocryptotrader/database/drivers/sqlite3"
"github.com/thrasher-corp/gocryptotrader/database/repository"
"github.com/thrasher-corp/gocryptotrader/log"
"github.com/thrasher-corp/goose"
"github.com/thrasher-corp/sqlboiler/boil"
)
var (
@@ -15,6 +21,8 @@ var (
TempDir string
// PostgresTestDatabase postgresql database config details
PostgresTestDatabase *database.Config
// MigrationDir default folder for migration's
MigrationDir = filepath.Join("..", "..", "migrations")
)
// GetConnectionDetails returns connection details for CI or test db instances
@@ -68,7 +76,6 @@ func GetConnectionDetails() *database.Config {
// ConnectToDatabase opens connection to database and returns pointer to instance of database.DB
func ConnectToDatabase(conn *database.Config) (dbConn *database.Instance, err error) {
database.DB.Config = conn
if conn.Driver == database.DBPostgreSQL {
dbConn, err = psqlConn.Connect()
if err != nil {
@@ -77,12 +84,16 @@ func ConnectToDatabase(conn *database.Config) (dbConn *database.Instance, err er
} else if conn.Driver == database.DBSQLite3 || conn.Driver == database.DBSQLite {
database.DB.DataPath = TempDir
dbConn, err = sqliteConn.Connect()
if err != nil {
return nil, err
}
}
database.DB.Connected = true
err = migrateDB(database.DB.SQL)
if err != nil {
return nil, err
}
return
}
@@ -98,3 +109,18 @@ func CloseDatabase(conn *database.Instance) (err error) {
func CheckValidConfig(config *drivers.ConnectionDetails) bool {
return !reflect.DeepEqual(drivers.ConnectionDetails{}, *config)
}
func migrateDB(db *sql.DB) error {
return goose.Run("up", db, repository.GetSQLDialect(), MigrationDir, "")
}
// EnableVerboseTestOutput enables debug output for SQL queries
func EnableVerboseTestOutput() {
c := log.GenDefaultSettings()
log.GlobalLogConfig = &c
log.SetupGlobalLogger()
DBLogger := database.Logger{}
boil.DebugMode = true
boil.DebugWriter = DBLogger
}

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/thrasher-corp/gocryptotrader/database"
@@ -19,6 +20,7 @@ func TestMain(m *testing.M) {
os.Exit(1)
}
MigrationDir = filepath.Join("..", "migrations")
t := m.Run()
err = os.RemoveAll(TempDir)
@@ -63,8 +65,8 @@ func TestDatabaseConnect(t *testing.T) {
},
}
for _, tests := range testCases {
test := tests
for x := range testCases {
test := testCases[x]
t.Run(test.name, func(t *testing.T) {
if !CheckValidConfig(&test.config.ConnectionDetails) {
t.Skip("database not configured skipping test")