mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
CI: Fix golangci-lint linter issues, add prealloc linter and bump version depends for Go 1.18 (#915)
* Bump CI versions * Specifically set go version as 1.17.x bumps it to 1.18 * Another * Adjust AppVeyor * Part 1 of linter issues * Part 2 * Fix various linters and improvements * Part 3 * Finishing touches * Tests and EqualFold * Fix nitterinos plus bonus requester jobs bump for exchanges with large number of tests * Fix nitterinos and bump golangci-lint timeout for AppVeyor * Address nits, ensure all books are returned on err due to syncer regression * Fix the wiggins * Fix duplication * Fix nitterinos
This commit is contained in:
@@ -19,7 +19,7 @@ func Event(id, msgtype, message string) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := context.TODO()
|
||||
ctx = boil.SkipTimestamps(ctx)
|
||||
|
||||
tx, err := database.DB.SQL.BeginTx(ctx, nil)
|
||||
@@ -76,7 +76,7 @@ func GetEvent(startTime, endTime time.Time, order string, limit int) (interface{
|
||||
orderByQuery := qm.OrderBy(orderByQueryString)
|
||||
limitQuery := qm.Limit(limit)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := context.TODO()
|
||||
if repository.GetSQLDialect() == database.DBSQLite3 {
|
||||
return modelSQLite.AuditEvents(query, orderByQuery, limitQuery).All(ctx, database.DB.SQL)
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ func Series(exchangeName, base, quote string, interval int64, asset string, star
|
||||
queries = append(queries, qm.Where("exchange_name_id = ?", exchangeUUID.String()))
|
||||
if repository.GetSQLDialect() == database.DBSQLite3 {
|
||||
queries = append(queries, qm.Where("timestamp between ? and ?", start.UTC().Format(time.RFC3339), end.UTC().Format(time.RFC3339)))
|
||||
retCandle, errC := modelSQLite.Candles(queries...).All(context.Background(), database.DB.SQL)
|
||||
retCandle, errC := modelSQLite.Candles(queries...).All(context.TODO(), database.DB.SQL)
|
||||
if errC != nil {
|
||||
return out, errC
|
||||
}
|
||||
@@ -68,7 +68,7 @@ func Series(exchangeName, base, quote string, interval int64, asset string, star
|
||||
}
|
||||
} else {
|
||||
queries = append(queries, qm.Where("timestamp between ? and ?", start.UTC(), end.UTC()))
|
||||
retCandle, errC := modelPSQL.Candles(queries...).All(context.Background(), database.DB.SQL)
|
||||
retCandle, errC := modelPSQL.Candles(queries...).All(context.TODO(), database.DB.SQL)
|
||||
if errC != nil {
|
||||
return out, errC
|
||||
}
|
||||
@@ -108,7 +108,7 @@ func DeleteCandles(in *Item) (int64, error) {
|
||||
return 0, errNoCandleData
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := context.TODO()
|
||||
queries := []qm.QueryMod{
|
||||
qm.Where("base = ?", strings.ToUpper(in.Base)),
|
||||
qm.Where("quote = ?", strings.ToUpper(in.Quote)),
|
||||
@@ -126,7 +126,7 @@ func DeleteCandles(in *Item) (int64, error) {
|
||||
}
|
||||
|
||||
func deleteSQLite(ctx context.Context, queries []qm.QueryMod) (int64, error) {
|
||||
retCandle, err := modelSQLite.Candles(queries...).All(context.Background(), database.DB.SQL)
|
||||
retCandle, err := modelSQLite.Candles(queries...).All(ctx, database.DB.SQL)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -153,7 +153,7 @@ func deleteSQLite(ctx context.Context, queries []qm.QueryMod) (int64, error) {
|
||||
}
|
||||
|
||||
func deletePostgres(ctx context.Context, queries []qm.QueryMod) (int64, error) {
|
||||
retCandle, err := modelPSQL.Candles(queries...).All(context.Background(), database.DB.SQL)
|
||||
retCandle, err := modelPSQL.Candles(queries...).All(ctx, database.DB.SQL)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -189,7 +189,7 @@ func Insert(in *Item) (uint64, error) {
|
||||
return 0, errNoCandleData
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := context.TODO()
|
||||
tx, err := database.DB.SQL.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
||||
@@ -38,7 +38,7 @@ func Setup(db database.IDatabase) (*DBService, error) {
|
||||
|
||||
// Upsert inserts or updates jobs into the database
|
||||
func (db *DBService) Upsert(jobs ...*DataHistoryJob) error {
|
||||
ctx := context.Background()
|
||||
ctx := context.TODO()
|
||||
|
||||
tx, err := db.sql.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
@@ -156,7 +156,7 @@ func (db *DBService) GetPrerequisiteJob(nickname string) (*DataHistoryJob, error
|
||||
// SetRelationshipByID removes a relationship in the event of a changed
|
||||
// relationship during upsertion
|
||||
func (db *DBService) SetRelationshipByID(prerequisiteJobID, followingJobID string, status int64) error {
|
||||
ctx := context.Background()
|
||||
ctx := context.TODO()
|
||||
if strings.EqualFold(prerequisiteJobID, followingJobID) {
|
||||
return errCannotSetSamePrerequisite
|
||||
}
|
||||
@@ -191,7 +191,7 @@ func (db *DBService) SetRelationshipByID(prerequisiteJobID, followingJobID strin
|
||||
// SetRelationshipByNickname removes a relationship in the event of a changed
|
||||
// relationship during upsertion
|
||||
func (db *DBService) SetRelationshipByNickname(prerequisiteNickname, followingNickname string, status int64) error {
|
||||
ctx := context.Background()
|
||||
ctx := context.TODO()
|
||||
if strings.EqualFold(prerequisiteNickname, followingNickname) {
|
||||
return errCannotSetSamePrerequisite
|
||||
}
|
||||
@@ -331,7 +331,7 @@ func upsertPostgres(ctx context.Context, tx *sql.Tx, jobs ...*DataHistoryJob) er
|
||||
return nil
|
||||
}
|
||||
func (db *DBService) getByNicknameSQLite(nickname string) (*DataHistoryJob, error) {
|
||||
result, err := sqlite3.Datahistoryjobs(qm.Where("nickname = ?", strings.ToLower(nickname))).One(context.Background(), db.sql)
|
||||
result, err := sqlite3.Datahistoryjobs(qm.Where("nickname = ?", strings.ToLower(nickname))).One(context.TODO(), db.sql)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -341,7 +341,7 @@ func (db *DBService) getByNicknameSQLite(nickname string) (*DataHistoryJob, erro
|
||||
|
||||
func (db *DBService) getByNicknamePostgres(nickname string) (*DataHistoryJob, error) {
|
||||
query := postgres.Datahistoryjobs(qm.Where("nickname = ?", strings.ToLower(nickname)))
|
||||
result, err := query.One(context.Background(), db.sql)
|
||||
result, err := query.One(context.TODO(), db.sql)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -349,7 +349,7 @@ func (db *DBService) getByNicknamePostgres(nickname string) (*DataHistoryJob, er
|
||||
}
|
||||
|
||||
func (db *DBService) getByIDSQLite(id string) (*DataHistoryJob, error) {
|
||||
result, err := sqlite3.Datahistoryjobs(qm.Where("id = ?", id)).One(context.Background(), db.sql)
|
||||
result, err := sqlite3.Datahistoryjobs(qm.Where("id = ?", id)).One(context.TODO(), db.sql)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -359,7 +359,7 @@ func (db *DBService) getByIDSQLite(id string) (*DataHistoryJob, error) {
|
||||
|
||||
func (db *DBService) getByIDPostgres(id string) (*DataHistoryJob, error) {
|
||||
query := postgres.Datahistoryjobs(qm.Where("id = ?", id))
|
||||
result, err := query.One(context.Background(), db.sql)
|
||||
result, err := query.One(context.TODO(), db.sql)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -368,13 +368,13 @@ func (db *DBService) getByIDPostgres(id string) (*DataHistoryJob, error) {
|
||||
}
|
||||
|
||||
func (db *DBService) getJobsBetweenSQLite(startDate, endDate time.Time) ([]DataHistoryJob, error) {
|
||||
var jobs []DataHistoryJob
|
||||
query := sqlite3.Datahistoryjobs(qm.Where("created BETWEEN ? AND ? ", startDate.UTC().Format(time.RFC3339), endDate.UTC().Format(time.RFC3339)))
|
||||
results, err := query.All(context.Background(), db.sql)
|
||||
results, err := query.All(context.TODO(), db.sql)
|
||||
if err != nil {
|
||||
return jobs, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
jobs := make([]DataHistoryJob, 0, len(results))
|
||||
for i := range results {
|
||||
job, err := db.createSQLiteDataHistoryJobResponse(results[i])
|
||||
if err != nil {
|
||||
@@ -387,13 +387,13 @@ func (db *DBService) getJobsBetweenSQLite(startDate, endDate time.Time) ([]DataH
|
||||
}
|
||||
|
||||
func (db *DBService) getJobsBetweenPostgres(startDate, endDate time.Time) ([]DataHistoryJob, error) {
|
||||
var jobs []DataHistoryJob
|
||||
query := postgres.Datahistoryjobs(qm.Where("created BETWEEN ? AND ? ", startDate, endDate))
|
||||
results, err := query.All(context.Background(), db.sql)
|
||||
results, err := query.All(context.TODO(), db.sql)
|
||||
if err != nil {
|
||||
return jobs, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
jobs := make([]DataHistoryJob, 0, len(results))
|
||||
for i := range results {
|
||||
job, err := db.createPostgresDataHistoryJobResponse(results[i])
|
||||
if err != nil {
|
||||
@@ -410,7 +410,7 @@ func (db *DBService) getJobAndAllResultsSQLite(nickname string) (*DataHistoryJob
|
||||
qm.Load(sqlite3.DatahistoryjobRels.JobDatahistoryjobresults),
|
||||
qm.Load(sqlite3.DatahistoryjobRels.ExchangeName),
|
||||
qm.Where("nickname = ?", strings.ToLower(nickname)))
|
||||
result, err := query.One(context.Background(), db.sql)
|
||||
result, err := query.One(context.TODO(), db.sql)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -422,7 +422,7 @@ func (db *DBService) getJobAndAllResultsPostgres(nickname string) (*DataHistoryJ
|
||||
query := postgres.Datahistoryjobs(
|
||||
qm.Load(postgres.DatahistoryjobRels.JobDatahistoryjobresults),
|
||||
qm.Where("nickname = ?", strings.ToLower(nickname)))
|
||||
result, err := query.One(context.Background(), db.sql)
|
||||
result, err := query.One(context.TODO(), db.sql)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -435,12 +435,12 @@ func (db *DBService) getAllIncompleteJobsAndResultsSQLite() ([]DataHistoryJob, e
|
||||
qm.Load(sqlite3.DatahistoryjobRels.ExchangeName),
|
||||
qm.Load(sqlite3.DatahistoryjobRels.JobDatahistoryjobresults),
|
||||
qm.Where("status = ?", 0))
|
||||
results, err := query.All(context.Background(), db.sql)
|
||||
results, err := query.All(context.TODO(), db.sql)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var jobs []DataHistoryJob
|
||||
jobs := make([]DataHistoryJob, 0, len(results))
|
||||
for i := range results {
|
||||
job, err := db.createSQLiteDataHistoryJobResponse(results[i])
|
||||
if err != nil {
|
||||
@@ -457,12 +457,12 @@ func (db *DBService) getAllIncompleteJobsAndResultsPostgres() ([]DataHistoryJob,
|
||||
query := postgres.Datahistoryjobs(
|
||||
qm.Load(postgres.DatahistoryjobRels.JobDatahistoryjobresults),
|
||||
qm.Where("status = ?", 0))
|
||||
results, err := query.All(context.Background(), db.sql)
|
||||
results, err := query.All(context.TODO(), db.sql)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var jobs []DataHistoryJob
|
||||
jobs := make([]DataHistoryJob, 0, len(results))
|
||||
for i := range results {
|
||||
job, err := db.createPostgresDataHistoryJobResponse(results[i])
|
||||
if err != nil {
|
||||
@@ -475,15 +475,15 @@ func (db *DBService) getAllIncompleteJobsAndResultsPostgres() ([]DataHistoryJob,
|
||||
}
|
||||
|
||||
func (db *DBService) getRelatedUpcomingJobsSQLite(nickname string) ([]*DataHistoryJob, error) {
|
||||
job, err := sqlite3.Datahistoryjobs(qm.Where("nickname = ?", nickname)).One(context.Background(), db.sql)
|
||||
job, err := sqlite3.Datahistoryjobs(qm.Where("nickname = ?", nickname)).One(context.TODO(), db.sql)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
results, err := job.JobDatahistoryjobs().All(context.Background(), db.sql)
|
||||
results, err := job.JobDatahistoryjobs().All(context.TODO(), db.sql)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var resp []*DataHistoryJob
|
||||
resp := make([]*DataHistoryJob, 0, len(results))
|
||||
for i := range results {
|
||||
job, err := db.createSQLiteDataHistoryJobResponse(results[i])
|
||||
if err != nil {
|
||||
@@ -496,11 +496,11 @@ func (db *DBService) getRelatedUpcomingJobsSQLite(nickname string) ([]*DataHisto
|
||||
|
||||
func (db *DBService) getRelatedUpcomingJobsPostgres(nickname string) ([]*DataHistoryJob, error) {
|
||||
q := postgres.Datahistoryjobs(qm.Load(postgres.DatahistoryjobRels.JobDatahistoryjobs), qm.Where("nickname = ?", nickname))
|
||||
jobWithRelations, err := q.One(context.Background(), db.sql)
|
||||
jobWithRelations, err := q.One(context.TODO(), db.sql)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response []*DataHistoryJob
|
||||
response := make([]*DataHistoryJob, 0, len(jobWithRelations.R.JobDatahistoryjobs))
|
||||
for i := range jobWithRelations.R.JobDatahistoryjobs {
|
||||
job, err := db.getByIDPostgres(jobWithRelations.R.JobDatahistoryjobs[i].ID)
|
||||
if err != nil {
|
||||
@@ -556,11 +556,11 @@ func setRelationshipByIDPostgres(ctx context.Context, tx *sql.Tx, prerequisiteJo
|
||||
}
|
||||
|
||||
func (db *DBService) getPrerequisiteJobSQLite(nickname string) (*DataHistoryJob, error) {
|
||||
result, err := sqlite3.Datahistoryjobs(qm.Where("nickname = ?", nickname)).One(context.Background(), db.sql)
|
||||
result, err := sqlite3.Datahistoryjobs(qm.Where("nickname = ?", nickname)).One(context.TODO(), db.sql)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
job, err := result.PrerequisiteJobDatahistoryjobs().One(context.Background(), db.sql)
|
||||
job, err := result.PrerequisiteJobDatahistoryjobs().One(context.TODO(), db.sql)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -569,11 +569,11 @@ func (db *DBService) getPrerequisiteJobSQLite(nickname string) (*DataHistoryJob,
|
||||
}
|
||||
|
||||
func (db *DBService) getPrerequisiteJobPostgres(nickname string) (*DataHistoryJob, error) {
|
||||
job, err := postgres.Datahistoryjobs(qm.Where("nickname = ?", nickname)).One(context.Background(), db.sql)
|
||||
job, err := postgres.Datahistoryjobs(qm.Where("nickname = ?", nickname)).One(context.TODO(), db.sql)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result, err := job.PrerequisiteJobDatahistoryjobs().One(context.Background(), db.sql)
|
||||
result, err := job.PrerequisiteJobDatahistoryjobs().One(context.TODO(), db.sql)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -631,7 +631,7 @@ func (db *DBService) createSQLiteDataHistoryJobResponse(result *sqlite3.Datahist
|
||||
if result.R != nil && result.R.ExchangeName != nil {
|
||||
exchange = result.R.ExchangeName
|
||||
} else {
|
||||
exchange, err = result.ExchangeName().One(context.Background(), db.sql)
|
||||
exchange, err = result.ExchangeName().One(context.TODO(), db.sql)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not retrieve exchange '%v' %w", result.ExchangeNameID, err)
|
||||
}
|
||||
@@ -639,7 +639,7 @@ func (db *DBService) createSQLiteDataHistoryJobResponse(result *sqlite3.Datahist
|
||||
var secondaryExchangeName string
|
||||
if result.SecondaryExchangeID.String != "" {
|
||||
var secondaryExchangeResult *sqlite3.Exchange
|
||||
secondaryExchangeResult, err = result.SecondaryExchange().One(context.Background(), db.sql)
|
||||
secondaryExchangeResult, err = result.SecondaryExchange().One(context.TODO(), db.sql)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not retrieve secondary exchange '%v' %w", result.SecondaryExchangeID, err)
|
||||
}
|
||||
@@ -661,7 +661,7 @@ func (db *DBService) createSQLiteDataHistoryJobResponse(result *sqlite3.Datahist
|
||||
return nil, err
|
||||
}
|
||||
|
||||
prereqJob, err := result.PrerequisiteJobDatahistoryjobs().One(context.Background(), db.sql)
|
||||
prereqJob, err := result.PrerequisiteJobDatahistoryjobs().One(context.TODO(), db.sql)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
@@ -735,7 +735,7 @@ func (db *DBService) createPostgresDataHistoryJobResponse(result *postgres.Datah
|
||||
if result.R != nil && result.R.ExchangeName != nil {
|
||||
exchange = result.R.ExchangeName
|
||||
} else {
|
||||
exchange, err = result.ExchangeName().One(context.Background(), db.sql)
|
||||
exchange, err = result.ExchangeName().One(context.TODO(), db.sql)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not retrieve exchange '%v' %w", result.ExchangeNameID, err)
|
||||
}
|
||||
@@ -744,7 +744,7 @@ func (db *DBService) createPostgresDataHistoryJobResponse(result *postgres.Datah
|
||||
var secondaryExchangeName string
|
||||
if result.SecondaryExchangeID.String != "" {
|
||||
var secondaryExchangeResult *postgres.Exchange
|
||||
secondaryExchangeResult, err = result.SecondaryExchange().One(context.Background(), db.sql)
|
||||
secondaryExchangeResult, err = result.SecondaryExchange().One(context.TODO(), db.sql)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not retrieve secondary exchange '%v' %w", result.SecondaryExchangeID, err)
|
||||
}
|
||||
@@ -753,7 +753,7 @@ func (db *DBService) createPostgresDataHistoryJobResponse(result *postgres.Datah
|
||||
}
|
||||
}
|
||||
|
||||
prereqJob, err := result.PrerequisiteJobDatahistoryjobs().One(context.Background(), db.sql)
|
||||
prereqJob, err := result.PrerequisiteJobDatahistoryjobs().One(context.TODO(), db.sql)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ func (db *DBService) Upsert(jobs ...*DataHistoryJobResult) error {
|
||||
if len(jobs) == 0 {
|
||||
return nil
|
||||
}
|
||||
ctx := context.Background()
|
||||
ctx := context.TODO()
|
||||
|
||||
tx, err := db.sql.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
@@ -165,11 +165,11 @@ func upsertPostgres(ctx context.Context, tx *sql.Tx, results ...*DataHistoryJobR
|
||||
|
||||
func (db *DBService) getByJobIDSQLite(jobID string) ([]DataHistoryJobResult, error) {
|
||||
query := sqlite3.Datahistoryjobresults(qm.Where("job_id = ?", jobID))
|
||||
results, err := query.All(context.Background(), db.sql)
|
||||
results, err := query.All(context.TODO(), db.sql)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var resp []DataHistoryJobResult
|
||||
resp := make([]DataHistoryJobResult, len(results))
|
||||
for i := range results {
|
||||
var start, end, run time.Time
|
||||
start, err = time.Parse(time.RFC3339, results[i].IntervalStartTime)
|
||||
@@ -184,7 +184,7 @@ func (db *DBService) getByJobIDSQLite(jobID string) ([]DataHistoryJobResult, err
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp = append(resp, DataHistoryJobResult{
|
||||
resp[i] = DataHistoryJobResult{
|
||||
ID: results[i].ID,
|
||||
JobID: results[i].JobID,
|
||||
IntervalStartDate: start,
|
||||
@@ -192,7 +192,7 @@ func (db *DBService) getByJobIDSQLite(jobID string) ([]DataHistoryJobResult, err
|
||||
Status: int64(results[i].Status),
|
||||
Result: results[i].Result.String,
|
||||
Date: run,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
@@ -200,13 +200,13 @@ func (db *DBService) getByJobIDSQLite(jobID string) ([]DataHistoryJobResult, err
|
||||
|
||||
func (db *DBService) getByJobIDPostgres(jobID string) ([]DataHistoryJobResult, error) {
|
||||
query := postgres.Datahistoryjobresults(qm.Where("job_id = ?", jobID))
|
||||
results, err := query.All(context.Background(), db.sql)
|
||||
results, err := query.All(context.TODO(), db.sql)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var resp []DataHistoryJobResult
|
||||
resp := make([]DataHistoryJobResult, len(results))
|
||||
for i := range results {
|
||||
resp = append(resp, DataHistoryJobResult{
|
||||
resp[i] = DataHistoryJobResult{
|
||||
ID: results[i].ID,
|
||||
JobID: results[i].JobID,
|
||||
IntervalStartDate: results[i].IntervalStartTime,
|
||||
@@ -214,20 +214,20 @@ func (db *DBService) getByJobIDPostgres(jobID string) ([]DataHistoryJobResult, e
|
||||
Status: int64(results[i].Status),
|
||||
Result: results[i].Result.String,
|
||||
Date: results[i].RunTime,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (db *DBService) getJobResultsBetweenSQLite(jobID string, startDate, endDate time.Time) ([]DataHistoryJobResult, error) {
|
||||
var results []DataHistoryJobResult
|
||||
query := sqlite3.Datahistoryjobresults(qm.Where("job_id = ? AND run_time BETWEEN ? AND ? ", jobID, startDate.UTC().Format(time.RFC3339), endDate.UTC().Format(time.RFC3339)))
|
||||
resp, err := query.All(context.Background(), db.sql)
|
||||
resp, err := query.All(context.TODO(), db.sql)
|
||||
if err != nil {
|
||||
return results, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
results := make([]DataHistoryJobResult, len(resp))
|
||||
for i := range resp {
|
||||
var start, end, run time.Time
|
||||
start, err = time.Parse(time.RFC3339, resp[i].IntervalStartTime)
|
||||
@@ -242,7 +242,7 @@ func (db *DBService) getJobResultsBetweenSQLite(jobID string, startDate, endDate
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
results = append(results, DataHistoryJobResult{
|
||||
results[i] = DataHistoryJobResult{
|
||||
ID: resp[i].ID,
|
||||
JobID: resp[i].JobID,
|
||||
IntervalStartDate: start,
|
||||
@@ -250,22 +250,22 @@ func (db *DBService) getJobResultsBetweenSQLite(jobID string, startDate, endDate
|
||||
Status: int64(resp[i].Status),
|
||||
Result: resp[i].Result.String,
|
||||
Date: run,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func (db *DBService) getJobResultsBetweenPostgres(jobID string, startDate, endDate time.Time) ([]DataHistoryJobResult, error) {
|
||||
var jobs []DataHistoryJobResult
|
||||
query := postgres.Datahistoryjobresults(qm.Where("job_id = ? AND run_time BETWEEN ? AND ? ", jobID, startDate, endDate))
|
||||
results, err := query.All(context.Background(), db.sql)
|
||||
results, err := query.All(context.TODO(), db.sql)
|
||||
if err != nil {
|
||||
return jobs, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
jobs := make([]DataHistoryJobResult, len(results))
|
||||
for i := range results {
|
||||
jobs = append(jobs, DataHistoryJobResult{
|
||||
jobs[i] = DataHistoryJobResult{
|
||||
ID: results[i].ID,
|
||||
JobID: results[i].JobID,
|
||||
IntervalStartDate: results[i].IntervalStartTime,
|
||||
@@ -273,7 +273,7 @@ func (db *DBService) getJobResultsBetweenPostgres(jobID string, startDate, endDa
|
||||
Status: int64(results[i].Status),
|
||||
Result: results[i].Result.String,
|
||||
Date: results[i].RunTime,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return jobs, nil
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/csv"
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -37,7 +38,7 @@ func one(in, clause string) (out Details, err error) {
|
||||
|
||||
whereQM := qm.Where(clause+"= ?", in)
|
||||
if repository.GetSQLDialect() == database.DBSQLite3 {
|
||||
ret, errS := modelSQLite.Exchanges(whereQM).One(context.Background(), database.DB.SQL)
|
||||
ret, errS := modelSQLite.Exchanges(whereQM).One(context.TODO(), database.DB.SQL)
|
||||
if errS != nil {
|
||||
return out, errS
|
||||
}
|
||||
@@ -47,7 +48,7 @@ func one(in, clause string) (out Details, err error) {
|
||||
return out, errS
|
||||
}
|
||||
} else {
|
||||
ret, errS := modelPSQL.Exchanges(whereQM).One(context.Background(), database.DB.SQL)
|
||||
ret, errS := modelPSQL.Exchanges(whereQM).One(context.TODO(), database.DB.SQL)
|
||||
if errS != nil {
|
||||
return out, errS
|
||||
}
|
||||
@@ -67,7 +68,7 @@ func Insert(in Details) error {
|
||||
return database.ErrDatabaseSupportDisabled
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := context.TODO()
|
||||
tx, err := database.DB.SQL.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -100,7 +101,7 @@ func InsertMany(in []Details) error {
|
||||
return database.ErrDatabaseSupportDisabled
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := context.TODO()
|
||||
tx, err := database.DB.SQL.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -178,7 +179,11 @@ func UUIDByName(exchange string) (uuid.UUID, error) {
|
||||
exchange = strings.ToLower(exchange)
|
||||
v := exchangeCache.Get(exchange)
|
||||
if v != nil {
|
||||
return v.(uuid.UUID), nil
|
||||
u, ok := v.(uuid.UUID)
|
||||
if !ok {
|
||||
return uuid.UUID{}, errors.New("unable to type assert uuid")
|
||||
}
|
||||
return u, nil
|
||||
}
|
||||
ret, err := One(exchange)
|
||||
if err != nil {
|
||||
|
||||
@@ -20,7 +20,7 @@ func Event(id, name, path string, data null.Bytes, executionType, status string,
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := context.TODO()
|
||||
ctx = boil.SkipTimestamps(ctx)
|
||||
tx, err := database.DB.SQL.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
|
||||
@@ -34,7 +34,7 @@ func Insert(trades ...Data) error {
|
||||
}
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := context.TODO()
|
||||
ctx = boil.SkipTimestamps(ctx)
|
||||
|
||||
tx, err := database.DB.SQL.BeginTx(ctx, nil)
|
||||
@@ -65,7 +65,7 @@ func Insert(trades ...Data) error {
|
||||
// VerifyTradeInIntervals will query for ONE trade within each kline interval and verify if data exists
|
||||
// if it does, it will set the range holder property "HasData" to true
|
||||
func VerifyTradeInIntervals(exchangeName, assetType, base, quote string, irh *kline.IntervalRangeHolder) error {
|
||||
ctx := context.Background()
|
||||
ctx := context.TODO()
|
||||
ctx = boil.SkipTimestamps(ctx)
|
||||
|
||||
tx, err := database.DB.SQL.BeginTx(ctx, nil)
|
||||
@@ -237,7 +237,7 @@ func getByUUIDSQLite(uuid string) (Data, error) {
|
||||
var td Data
|
||||
var ts time.Time
|
||||
query := sqlite3.Trades(qm.Where("id = ?", uuid))
|
||||
result, err := query.One(context.Background(), database.DB.SQL)
|
||||
result, err := query.One(context.TODO(), database.DB.SQL)
|
||||
if err != nil {
|
||||
return td, err
|
||||
}
|
||||
@@ -265,7 +265,7 @@ func getByUUIDSQLite(uuid string) (Data, error) {
|
||||
func getByUUIDPostgres(uuid string) (td Data, err error) {
|
||||
query := postgres.Trades(qm.Where("id = ?", uuid))
|
||||
var result *postgres.Trade
|
||||
result, err = query.One(context.Background(), database.DB.SQL)
|
||||
result, err = query.One(context.TODO(), database.DB.SQL)
|
||||
if err != nil {
|
||||
return td, err
|
||||
}
|
||||
@@ -318,7 +318,7 @@ func getInRangeSQLite(exchangeName, assetType, base, quote string, startDate, en
|
||||
q := generateQuery(wheres, startDate, endDate, true)
|
||||
query := sqlite3.Trades(q...)
|
||||
var result []*sqlite3.Trade
|
||||
result, err = query.All(context.Background(), database.DB.SQL)
|
||||
result, err = query.All(context.TODO(), database.DB.SQL)
|
||||
if err != nil {
|
||||
return td, err
|
||||
}
|
||||
@@ -361,7 +361,7 @@ func getInRangePostgres(exchangeName, assetType, base, quote string, startDate,
|
||||
q := generateQuery(wheres, startDate, endDate, false)
|
||||
query := postgres.Trades(q...)
|
||||
var result []*postgres.Trade
|
||||
result, err = query.All(context.Background(), database.DB.SQL)
|
||||
result, err = query.All(context.TODO(), database.DB.SQL)
|
||||
if err != nil {
|
||||
return td, err
|
||||
}
|
||||
@@ -386,7 +386,7 @@ func getInRangePostgres(exchangeName, assetType, base, quote string, startDate,
|
||||
|
||||
// DeleteTrades will remove trades from the database using trade.Data
|
||||
func DeleteTrades(trades ...Data) error {
|
||||
ctx := context.Background()
|
||||
ctx := context.TODO()
|
||||
ctx = boil.SkipTimestamps(ctx)
|
||||
|
||||
tx, err := database.DB.SQL.BeginTx(ctx, nil)
|
||||
@@ -402,9 +402,9 @@ func DeleteTrades(trades ...Data) error {
|
||||
}
|
||||
}()
|
||||
if repository.GetSQLDialect() == database.DBSQLite3 || repository.GetSQLDialect() == database.DBSQLite {
|
||||
err = deleteTradesSQLite(context.Background(), tx, trades...)
|
||||
err = deleteTradesSQLite(context.TODO(), tx, trades...)
|
||||
} else {
|
||||
err = deleteTradesPostgres(context.Background(), tx, trades...)
|
||||
err = deleteTradesPostgres(context.TODO(), tx, trades...)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -414,9 +414,9 @@ func DeleteTrades(trades ...Data) error {
|
||||
}
|
||||
|
||||
func deleteTradesSQLite(ctx context.Context, tx *sql.Tx, trades ...Data) error {
|
||||
var tradeIDs []interface{}
|
||||
tradeIDs := make([]interface{}, len(trades))
|
||||
for i := range trades {
|
||||
tradeIDs = append(tradeIDs, trades[i].ID)
|
||||
tradeIDs[i] = trades[i].ID
|
||||
}
|
||||
query := sqlite3.Trades(qm.WhereIn(`id in ?`, tradeIDs...))
|
||||
_, err := query.DeleteAll(ctx, tx)
|
||||
@@ -424,9 +424,9 @@ func deleteTradesSQLite(ctx context.Context, tx *sql.Tx, trades ...Data) error {
|
||||
}
|
||||
|
||||
func deleteTradesPostgres(ctx context.Context, tx *sql.Tx, trades ...Data) error {
|
||||
var tradeIDs []interface{}
|
||||
tradeIDs := make([]interface{}, len(trades))
|
||||
for i := range trades {
|
||||
tradeIDs = append(tradeIDs, trades[i].ID)
|
||||
tradeIDs[i] = trades[i].ID
|
||||
}
|
||||
query := postgres.Trades(qm.WhereIn(`id in ?`, tradeIDs...))
|
||||
_, err := query.DeleteAll(ctx, tx)
|
||||
|
||||
@@ -267,7 +267,11 @@ func GetEventsByDate(exchange string, start, end time.Time, limit int) ([]*withd
|
||||
}
|
||||
|
||||
func generateWhereQuery(columns, id []string, limit int) []qm.QueryMod {
|
||||
var queries []qm.QueryMod
|
||||
x := len(columns)
|
||||
if limit > 0 {
|
||||
x++
|
||||
}
|
||||
queries := make([]qm.QueryMod, 0, x)
|
||||
if limit > 0 {
|
||||
queries = append(queries, qm.Limit(limit))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user