mirror of
https://github.com/cf-sonr/radar.git
synced 2026-01-12 02:59:13 +00:00
1641 lines
41 KiB
Go
1641 lines
41 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.28.0
|
|
// source: query.sql
|
|
|
|
package activity
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"time"
|
|
)
|
|
|
|
const getActivityByID = `-- name: GetActivityByID :one
|
|
SELECT id, created_at, updated_at, deleted_at, account_id, tx_hash, tx_type, status, amount, fee, gas_used, gas_wanted, memo, block_height, timestamp, raw_log, error FROM activities
|
|
WHERE id = ? AND deleted_at IS NULL
|
|
LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetActivityByID(ctx context.Context, id string) (Activity, error) {
|
|
row := q.db.QueryRowContext(ctx, getActivityByID, id)
|
|
var i Activity
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.AccountID,
|
|
&i.TxHash,
|
|
&i.TxType,
|
|
&i.Status,
|
|
&i.Amount,
|
|
&i.Fee,
|
|
&i.GasUsed,
|
|
&i.GasWanted,
|
|
&i.Memo,
|
|
&i.BlockHeight,
|
|
&i.Timestamp,
|
|
&i.RawLog,
|
|
&i.Error,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getActivityByTxHash = `-- name: GetActivityByTxHash :one
|
|
SELECT id, created_at, updated_at, deleted_at, account_id, tx_hash, tx_type, status, amount, fee, gas_used, gas_wanted, memo, block_height, timestamp, raw_log, error FROM activities
|
|
WHERE tx_hash = ? AND deleted_at IS NULL
|
|
LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetActivityByTxHash(ctx context.Context, txHash sql.NullString) (Activity, error) {
|
|
row := q.db.QueryRowContext(ctx, getActivityByTxHash, txHash)
|
|
var i Activity
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.AccountID,
|
|
&i.TxHash,
|
|
&i.TxType,
|
|
&i.Status,
|
|
&i.Amount,
|
|
&i.Fee,
|
|
&i.GasUsed,
|
|
&i.GasWanted,
|
|
&i.Memo,
|
|
&i.BlockHeight,
|
|
&i.Timestamp,
|
|
&i.RawLog,
|
|
&i.Error,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getCryptoListingByApiID = `-- name: GetCryptoListingByApiID :one
|
|
SELECT id, created_at, updated_at, deleted_at, api_id, name, symbol, website_slug FROM crypto_listings
|
|
WHERE api_id = ? AND deleted_at IS NULL
|
|
LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetCryptoListingByApiID(ctx context.Context, apiID string) (CryptoListing, error) {
|
|
row := q.db.QueryRowContext(ctx, getCryptoListingByApiID, apiID)
|
|
var i CryptoListing
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.ApiID,
|
|
&i.Name,
|
|
&i.Symbol,
|
|
&i.WebsiteSlug,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getCryptoListingByID = `-- name: GetCryptoListingByID :one
|
|
SELECT id, created_at, updated_at, deleted_at, api_id, name, symbol, website_slug FROM crypto_listings
|
|
WHERE id = ? AND deleted_at IS NULL
|
|
LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetCryptoListingByID(ctx context.Context, id string) (CryptoListing, error) {
|
|
row := q.db.QueryRowContext(ctx, getCryptoListingByID, id)
|
|
var i CryptoListing
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.ApiID,
|
|
&i.Name,
|
|
&i.Symbol,
|
|
&i.WebsiteSlug,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getCryptoListingBySymbol = `-- name: GetCryptoListingBySymbol :one
|
|
SELECT id, created_at, updated_at, deleted_at, api_id, name, symbol, website_slug FROM crypto_listings
|
|
WHERE symbol = ? AND deleted_at IS NULL
|
|
LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetCryptoListingBySymbol(ctx context.Context, symbol string) (CryptoListing, error) {
|
|
row := q.db.QueryRowContext(ctx, getCryptoListingBySymbol, symbol)
|
|
var i CryptoListing
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.ApiID,
|
|
&i.Name,
|
|
&i.Symbol,
|
|
&i.WebsiteSlug,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getCryptoListingByWebsiteSlug = `-- name: GetCryptoListingByWebsiteSlug :one
|
|
SELECT id, created_at, updated_at, deleted_at, api_id, name, symbol, website_slug FROM crypto_listings
|
|
WHERE website_slug = ? AND deleted_at IS NULL
|
|
LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetCryptoListingByWebsiteSlug(ctx context.Context, websiteSlug string) (CryptoListing, error) {
|
|
row := q.db.QueryRowContext(ctx, getCryptoListingByWebsiteSlug, websiteSlug)
|
|
var i CryptoListing
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.ApiID,
|
|
&i.Name,
|
|
&i.Symbol,
|
|
&i.WebsiteSlug,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getFearGreedIndexByID = `-- name: GetFearGreedIndexByID :one
|
|
SELECT id, created_at, updated_at, deleted_at, value, value_classification, timestamp, time_until_update FROM fear_greed_index
|
|
WHERE id = ? AND deleted_at IS NULL
|
|
LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetFearGreedIndexByID(ctx context.Context, id string) (FearGreedIndex, error) {
|
|
row := q.db.QueryRowContext(ctx, getFearGreedIndexByID, id)
|
|
var i FearGreedIndex
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.Value,
|
|
&i.ValueClassification,
|
|
&i.Timestamp,
|
|
&i.TimeUntilUpdate,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getGlobalMarketByID = `-- name: GetGlobalMarketByID :one
|
|
SELECT id, created_at, updated_at, deleted_at, total_market_cap_usd, total_24h_volume_usd, bitcoin_percentage_of_market_cap, active_currencies, active_assets, active_markets, last_updated FROM global_market
|
|
WHERE id = ? AND deleted_at IS NULL
|
|
LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetGlobalMarketByID(ctx context.Context, id string) (GlobalMarket, error) {
|
|
row := q.db.QueryRowContext(ctx, getGlobalMarketByID, id)
|
|
var i GlobalMarket
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.TotalMarketCapUsd,
|
|
&i.Total24hVolumeUsd,
|
|
&i.BitcoinPercentageOfMarketCap,
|
|
&i.ActiveCurrencies,
|
|
&i.ActiveAssets,
|
|
&i.ActiveMarkets,
|
|
&i.LastUpdated,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getHealthByEndpoint = `-- name: GetHealthByEndpoint :one
|
|
SELECT id, created_at, updated_at, deleted_at, endpoint_url, endpoint_type, chain_id, status, response_time_ms, last_checked, next_check, failure_count, success_count, response_data, error_message FROM health
|
|
WHERE endpoint_url = ? AND deleted_at IS NULL
|
|
ORDER BY last_checked DESC
|
|
LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetHealthByEndpoint(ctx context.Context, endpointUrl string) (Health, error) {
|
|
row := q.db.QueryRowContext(ctx, getHealthByEndpoint, endpointUrl)
|
|
var i Health
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.EndpointUrl,
|
|
&i.EndpointType,
|
|
&i.ChainID,
|
|
&i.Status,
|
|
&i.ResponseTimeMs,
|
|
&i.LastChecked,
|
|
&i.NextCheck,
|
|
&i.FailureCount,
|
|
&i.SuccessCount,
|
|
&i.ResponseData,
|
|
&i.ErrorMessage,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getHealthByID = `-- name: GetHealthByID :one
|
|
SELECT id, created_at, updated_at, deleted_at, endpoint_url, endpoint_type, chain_id, status, response_time_ms, last_checked, next_check, failure_count, success_count, response_data, error_message FROM health
|
|
WHERE id = ? AND deleted_at IS NULL
|
|
LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetHealthByID(ctx context.Context, id string) (Health, error) {
|
|
row := q.db.QueryRowContext(ctx, getHealthByID, id)
|
|
var i Health
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.EndpointUrl,
|
|
&i.EndpointType,
|
|
&i.ChainID,
|
|
&i.Status,
|
|
&i.ResponseTimeMs,
|
|
&i.LastChecked,
|
|
&i.NextCheck,
|
|
&i.FailureCount,
|
|
&i.SuccessCount,
|
|
&i.ResponseData,
|
|
&i.ErrorMessage,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getLatestFearGreedIndex = `-- name: GetLatestFearGreedIndex :one
|
|
SELECT id, created_at, updated_at, deleted_at, value, value_classification, timestamp, time_until_update FROM fear_greed_index
|
|
WHERE deleted_at IS NULL
|
|
ORDER BY timestamp DESC
|
|
LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetLatestFearGreedIndex(ctx context.Context) (FearGreedIndex, error) {
|
|
row := q.db.QueryRowContext(ctx, getLatestFearGreedIndex)
|
|
var i FearGreedIndex
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.Value,
|
|
&i.ValueClassification,
|
|
&i.Timestamp,
|
|
&i.TimeUntilUpdate,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getLatestGlobalMarket = `-- name: GetLatestGlobalMarket :one
|
|
SELECT id, created_at, updated_at, deleted_at, total_market_cap_usd, total_24h_volume_usd, bitcoin_percentage_of_market_cap, active_currencies, active_assets, active_markets, last_updated FROM global_market
|
|
WHERE deleted_at IS NULL
|
|
ORDER BY last_updated DESC
|
|
LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetLatestGlobalMarket(ctx context.Context) (GlobalMarket, error) {
|
|
row := q.db.QueryRowContext(ctx, getLatestGlobalMarket)
|
|
var i GlobalMarket
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.TotalMarketCapUsd,
|
|
&i.Total24hVolumeUsd,
|
|
&i.BitcoinPercentageOfMarketCap,
|
|
&i.ActiveCurrencies,
|
|
&i.ActiveAssets,
|
|
&i.ActiveMarkets,
|
|
&i.LastUpdated,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getServiceByAddress = `-- name: GetServiceByAddress :one
|
|
SELECT id, created_at, updated_at, deleted_at, name, description, chain_id, address, owner_address, metadata, status, block_height FROM services
|
|
WHERE address = ? AND deleted_at IS NULL
|
|
LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetServiceByAddress(ctx context.Context, address string) (Service, error) {
|
|
row := q.db.QueryRowContext(ctx, getServiceByAddress, address)
|
|
var i Service
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.ChainID,
|
|
&i.Address,
|
|
&i.OwnerAddress,
|
|
&i.Metadata,
|
|
&i.Status,
|
|
&i.BlockHeight,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getServiceByChainAndAddress = `-- name: GetServiceByChainAndAddress :one
|
|
SELECT id, created_at, updated_at, deleted_at, name, description, chain_id, address, owner_address, metadata, status, block_height FROM services
|
|
WHERE chain_id = ? AND address = ? AND deleted_at IS NULL
|
|
LIMIT 1
|
|
`
|
|
|
|
type GetServiceByChainAndAddressParams struct {
|
|
ChainID string `json:"chain_id"`
|
|
Address string `json:"address"`
|
|
}
|
|
|
|
func (q *Queries) GetServiceByChainAndAddress(ctx context.Context, arg GetServiceByChainAndAddressParams) (Service, error) {
|
|
row := q.db.QueryRowContext(ctx, getServiceByChainAndAddress, arg.ChainID, arg.Address)
|
|
var i Service
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.ChainID,
|
|
&i.Address,
|
|
&i.OwnerAddress,
|
|
&i.Metadata,
|
|
&i.Status,
|
|
&i.BlockHeight,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getServiceByID = `-- name: GetServiceByID :one
|
|
SELECT id, created_at, updated_at, deleted_at, name, description, chain_id, address, owner_address, metadata, status, block_height FROM services
|
|
WHERE id = ? AND deleted_at IS NULL
|
|
LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetServiceByID(ctx context.Context, id string) (Service, error) {
|
|
row := q.db.QueryRowContext(ctx, getServiceByID, id)
|
|
var i Service
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.ChainID,
|
|
&i.Address,
|
|
&i.OwnerAddress,
|
|
&i.Metadata,
|
|
&i.Status,
|
|
&i.BlockHeight,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const insertActivity = `-- name: InsertActivity :one
|
|
INSERT INTO activities (
|
|
account_id,
|
|
tx_hash,
|
|
tx_type,
|
|
status,
|
|
amount,
|
|
fee,
|
|
gas_used,
|
|
gas_wanted,
|
|
memo,
|
|
block_height,
|
|
timestamp,
|
|
raw_log,
|
|
error
|
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
RETURNING id, created_at, updated_at, deleted_at, account_id, tx_hash, tx_type, status, amount, fee, gas_used, gas_wanted, memo, block_height, timestamp, raw_log, error
|
|
`
|
|
|
|
type InsertActivityParams struct {
|
|
AccountID string `json:"account_id"`
|
|
TxHash sql.NullString `json:"tx_hash"`
|
|
TxType string `json:"tx_type"`
|
|
Status string `json:"status"`
|
|
Amount sql.NullString `json:"amount"`
|
|
Fee sql.NullString `json:"fee"`
|
|
GasUsed sql.NullInt64 `json:"gas_used"`
|
|
GasWanted sql.NullInt64 `json:"gas_wanted"`
|
|
Memo sql.NullString `json:"memo"`
|
|
BlockHeight sql.NullInt64 `json:"block_height"`
|
|
Timestamp time.Time `json:"timestamp"`
|
|
RawLog sql.NullString `json:"raw_log"`
|
|
Error sql.NullString `json:"error"`
|
|
}
|
|
|
|
// ACTIVITY QUERIES
|
|
func (q *Queries) InsertActivity(ctx context.Context, arg InsertActivityParams) (Activity, error) {
|
|
row := q.db.QueryRowContext(ctx, insertActivity,
|
|
arg.AccountID,
|
|
arg.TxHash,
|
|
arg.TxType,
|
|
arg.Status,
|
|
arg.Amount,
|
|
arg.Fee,
|
|
arg.GasUsed,
|
|
arg.GasWanted,
|
|
arg.Memo,
|
|
arg.BlockHeight,
|
|
arg.Timestamp,
|
|
arg.RawLog,
|
|
arg.Error,
|
|
)
|
|
var i Activity
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.AccountID,
|
|
&i.TxHash,
|
|
&i.TxType,
|
|
&i.Status,
|
|
&i.Amount,
|
|
&i.Fee,
|
|
&i.GasUsed,
|
|
&i.GasWanted,
|
|
&i.Memo,
|
|
&i.BlockHeight,
|
|
&i.Timestamp,
|
|
&i.RawLog,
|
|
&i.Error,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const insertCryptoListing = `-- name: InsertCryptoListing :one
|
|
INSERT INTO crypto_listings (
|
|
api_id,
|
|
name,
|
|
symbol,
|
|
website_slug
|
|
) VALUES (?, ?, ?, ?)
|
|
RETURNING id, created_at, updated_at, deleted_at, api_id, name, symbol, website_slug
|
|
`
|
|
|
|
type InsertCryptoListingParams struct {
|
|
ApiID string `json:"api_id"`
|
|
Name string `json:"name"`
|
|
Symbol string `json:"symbol"`
|
|
WebsiteSlug string `json:"website_slug"`
|
|
}
|
|
|
|
// CRYPTO LISTINGS QUERIES (NEW)
|
|
func (q *Queries) InsertCryptoListing(ctx context.Context, arg InsertCryptoListingParams) (CryptoListing, error) {
|
|
row := q.db.QueryRowContext(ctx, insertCryptoListing,
|
|
arg.ApiID,
|
|
arg.Name,
|
|
arg.Symbol,
|
|
arg.WebsiteSlug,
|
|
)
|
|
var i CryptoListing
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.ApiID,
|
|
&i.Name,
|
|
&i.Symbol,
|
|
&i.WebsiteSlug,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const insertFearGreedIndex = `-- name: InsertFearGreedIndex :one
|
|
INSERT INTO fear_greed_index (
|
|
value,
|
|
value_classification,
|
|
timestamp,
|
|
time_until_update
|
|
) VALUES (?, ?, ?, ?)
|
|
RETURNING id, created_at, updated_at, deleted_at, value, value_classification, timestamp, time_until_update
|
|
`
|
|
|
|
type InsertFearGreedIndexParams struct {
|
|
Value int64 `json:"value"`
|
|
ValueClassification string `json:"value_classification"`
|
|
Timestamp time.Time `json:"timestamp"`
|
|
TimeUntilUpdate sql.NullString `json:"time_until_update"`
|
|
}
|
|
|
|
// FEAR AND GREED INDEX QUERIES (NEW)
|
|
func (q *Queries) InsertFearGreedIndex(ctx context.Context, arg InsertFearGreedIndexParams) (FearGreedIndex, error) {
|
|
row := q.db.QueryRowContext(ctx, insertFearGreedIndex,
|
|
arg.Value,
|
|
arg.ValueClassification,
|
|
arg.Timestamp,
|
|
arg.TimeUntilUpdate,
|
|
)
|
|
var i FearGreedIndex
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.Value,
|
|
&i.ValueClassification,
|
|
&i.Timestamp,
|
|
&i.TimeUntilUpdate,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const insertGlobalMarket = `-- name: InsertGlobalMarket :one
|
|
INSERT INTO global_market (
|
|
total_market_cap_usd,
|
|
total_24h_volume_usd,
|
|
bitcoin_percentage_of_market_cap,
|
|
active_currencies,
|
|
active_assets,
|
|
active_markets,
|
|
last_updated
|
|
) VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
RETURNING id, created_at, updated_at, deleted_at, total_market_cap_usd, total_24h_volume_usd, bitcoin_percentage_of_market_cap, active_currencies, active_assets, active_markets, last_updated
|
|
`
|
|
|
|
type InsertGlobalMarketParams struct {
|
|
TotalMarketCapUsd sql.NullFloat64 `json:"total_market_cap_usd"`
|
|
Total24hVolumeUsd sql.NullFloat64 `json:"total_24h_volume_usd"`
|
|
BitcoinPercentageOfMarketCap sql.NullFloat64 `json:"bitcoin_percentage_of_market_cap"`
|
|
ActiveCurrencies sql.NullInt64 `json:"active_currencies"`
|
|
ActiveAssets sql.NullInt64 `json:"active_assets"`
|
|
ActiveMarkets sql.NullInt64 `json:"active_markets"`
|
|
LastUpdated time.Time `json:"last_updated"`
|
|
}
|
|
|
|
func (q *Queries) InsertGlobalMarket(ctx context.Context, arg InsertGlobalMarketParams) (GlobalMarket, error) {
|
|
row := q.db.QueryRowContext(ctx, insertGlobalMarket,
|
|
arg.TotalMarketCapUsd,
|
|
arg.Total24hVolumeUsd,
|
|
arg.BitcoinPercentageOfMarketCap,
|
|
arg.ActiveCurrencies,
|
|
arg.ActiveAssets,
|
|
arg.ActiveMarkets,
|
|
arg.LastUpdated,
|
|
)
|
|
var i GlobalMarket
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.TotalMarketCapUsd,
|
|
&i.Total24hVolumeUsd,
|
|
&i.BitcoinPercentageOfMarketCap,
|
|
&i.ActiveCurrencies,
|
|
&i.ActiveAssets,
|
|
&i.ActiveMarkets,
|
|
&i.LastUpdated,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const insertHealth = `-- name: InsertHealth :one
|
|
INSERT INTO health (
|
|
endpoint_url,
|
|
endpoint_type,
|
|
chain_id,
|
|
status,
|
|
response_time_ms,
|
|
last_checked,
|
|
next_check,
|
|
failure_count,
|
|
success_count,
|
|
response_data,
|
|
error_message
|
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
RETURNING id, created_at, updated_at, deleted_at, endpoint_url, endpoint_type, chain_id, status, response_time_ms, last_checked, next_check, failure_count, success_count, response_data, error_message
|
|
`
|
|
|
|
type InsertHealthParams struct {
|
|
EndpointUrl string `json:"endpoint_url"`
|
|
EndpointType string `json:"endpoint_type"`
|
|
ChainID sql.NullString `json:"chain_id"`
|
|
Status string `json:"status"`
|
|
ResponseTimeMs sql.NullInt64 `json:"response_time_ms"`
|
|
LastChecked time.Time `json:"last_checked"`
|
|
NextCheck sql.NullTime `json:"next_check"`
|
|
FailureCount int64 `json:"failure_count"`
|
|
SuccessCount int64 `json:"success_count"`
|
|
ResponseData sql.NullString `json:"response_data"`
|
|
ErrorMessage sql.NullString `json:"error_message"`
|
|
}
|
|
|
|
// HEALTH QUERIES
|
|
func (q *Queries) InsertHealth(ctx context.Context, arg InsertHealthParams) (Health, error) {
|
|
row := q.db.QueryRowContext(ctx, insertHealth,
|
|
arg.EndpointUrl,
|
|
arg.EndpointType,
|
|
arg.ChainID,
|
|
arg.Status,
|
|
arg.ResponseTimeMs,
|
|
arg.LastChecked,
|
|
arg.NextCheck,
|
|
arg.FailureCount,
|
|
arg.SuccessCount,
|
|
arg.ResponseData,
|
|
arg.ErrorMessage,
|
|
)
|
|
var i Health
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.EndpointUrl,
|
|
&i.EndpointType,
|
|
&i.ChainID,
|
|
&i.Status,
|
|
&i.ResponseTimeMs,
|
|
&i.LastChecked,
|
|
&i.NextCheck,
|
|
&i.FailureCount,
|
|
&i.SuccessCount,
|
|
&i.ResponseData,
|
|
&i.ErrorMessage,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const insertService = `-- name: InsertService :one
|
|
INSERT INTO services (
|
|
name,
|
|
description,
|
|
chain_id,
|
|
address,
|
|
owner_address,
|
|
metadata,
|
|
status,
|
|
block_height
|
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
RETURNING id, created_at, updated_at, deleted_at, name, description, chain_id, address, owner_address, metadata, status, block_height
|
|
`
|
|
|
|
type InsertServiceParams struct {
|
|
Name string `json:"name"`
|
|
Description sql.NullString `json:"description"`
|
|
ChainID string `json:"chain_id"`
|
|
Address string `json:"address"`
|
|
OwnerAddress string `json:"owner_address"`
|
|
Metadata sql.NullString `json:"metadata"`
|
|
Status string `json:"status"`
|
|
BlockHeight int64 `json:"block_height"`
|
|
}
|
|
|
|
func (q *Queries) InsertService(ctx context.Context, arg InsertServiceParams) (Service, error) {
|
|
row := q.db.QueryRowContext(ctx, insertService,
|
|
arg.Name,
|
|
arg.Description,
|
|
arg.ChainID,
|
|
arg.Address,
|
|
arg.OwnerAddress,
|
|
arg.Metadata,
|
|
arg.Status,
|
|
arg.BlockHeight,
|
|
)
|
|
var i Service
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.ChainID,
|
|
&i.Address,
|
|
&i.OwnerAddress,
|
|
&i.Metadata,
|
|
&i.Status,
|
|
&i.BlockHeight,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listActivitiesByAccount = `-- name: ListActivitiesByAccount :many
|
|
SELECT id, created_at, updated_at, deleted_at, account_id, tx_hash, tx_type, status, amount, fee, gas_used, gas_wanted, memo, block_height, timestamp, raw_log, error FROM activities
|
|
WHERE account_id = ? AND deleted_at IS NULL
|
|
ORDER BY timestamp DESC
|
|
LIMIT ? OFFSET ?
|
|
`
|
|
|
|
type ListActivitiesByAccountParams struct {
|
|
AccountID string `json:"account_id"`
|
|
Limit int64 `json:"limit"`
|
|
Offset int64 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) ListActivitiesByAccount(ctx context.Context, arg ListActivitiesByAccountParams) ([]Activity, error) {
|
|
rows, err := q.db.QueryContext(ctx, listActivitiesByAccount, arg.AccountID, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Activity
|
|
for rows.Next() {
|
|
var i Activity
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.AccountID,
|
|
&i.TxHash,
|
|
&i.TxType,
|
|
&i.Status,
|
|
&i.Amount,
|
|
&i.Fee,
|
|
&i.GasUsed,
|
|
&i.GasWanted,
|
|
&i.Memo,
|
|
&i.BlockHeight,
|
|
&i.Timestamp,
|
|
&i.RawLog,
|
|
&i.Error,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listActivitiesByStatus = `-- name: ListActivitiesByStatus :many
|
|
SELECT id, created_at, updated_at, deleted_at, account_id, tx_hash, tx_type, status, amount, fee, gas_used, gas_wanted, memo, block_height, timestamp, raw_log, error FROM activities
|
|
WHERE status = ? AND deleted_at IS NULL
|
|
ORDER BY timestamp DESC
|
|
LIMIT ? OFFSET ?
|
|
`
|
|
|
|
type ListActivitiesByStatusParams struct {
|
|
Status string `json:"status"`
|
|
Limit int64 `json:"limit"`
|
|
Offset int64 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) ListActivitiesByStatus(ctx context.Context, arg ListActivitiesByStatusParams) ([]Activity, error) {
|
|
rows, err := q.db.QueryContext(ctx, listActivitiesByStatus, arg.Status, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Activity
|
|
for rows.Next() {
|
|
var i Activity
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.AccountID,
|
|
&i.TxHash,
|
|
&i.TxType,
|
|
&i.Status,
|
|
&i.Amount,
|
|
&i.Fee,
|
|
&i.GasUsed,
|
|
&i.GasWanted,
|
|
&i.Memo,
|
|
&i.BlockHeight,
|
|
&i.Timestamp,
|
|
&i.RawLog,
|
|
&i.Error,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listActivitiesByType = `-- name: ListActivitiesByType :many
|
|
SELECT id, created_at, updated_at, deleted_at, account_id, tx_hash, tx_type, status, amount, fee, gas_used, gas_wanted, memo, block_height, timestamp, raw_log, error FROM activities
|
|
WHERE tx_type = ? AND deleted_at IS NULL
|
|
ORDER BY timestamp DESC
|
|
LIMIT ? OFFSET ?
|
|
`
|
|
|
|
type ListActivitiesByTypeParams struct {
|
|
TxType string `json:"tx_type"`
|
|
Limit int64 `json:"limit"`
|
|
Offset int64 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) ListActivitiesByType(ctx context.Context, arg ListActivitiesByTypeParams) ([]Activity, error) {
|
|
rows, err := q.db.QueryContext(ctx, listActivitiesByType, arg.TxType, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Activity
|
|
for rows.Next() {
|
|
var i Activity
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.AccountID,
|
|
&i.TxHash,
|
|
&i.TxType,
|
|
&i.Status,
|
|
&i.Amount,
|
|
&i.Fee,
|
|
&i.GasUsed,
|
|
&i.GasWanted,
|
|
&i.Memo,
|
|
&i.BlockHeight,
|
|
&i.Timestamp,
|
|
&i.RawLog,
|
|
&i.Error,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listCryptoListings = `-- name: ListCryptoListings :many
|
|
SELECT id, created_at, updated_at, deleted_at, api_id, name, symbol, website_slug FROM crypto_listings
|
|
WHERE deleted_at IS NULL
|
|
ORDER BY name ASC
|
|
LIMIT ? OFFSET ?
|
|
`
|
|
|
|
type ListCryptoListingsParams struct {
|
|
Limit int64 `json:"limit"`
|
|
Offset int64 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) ListCryptoListings(ctx context.Context, arg ListCryptoListingsParams) ([]CryptoListing, error) {
|
|
rows, err := q.db.QueryContext(ctx, listCryptoListings, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []CryptoListing
|
|
for rows.Next() {
|
|
var i CryptoListing
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.ApiID,
|
|
&i.Name,
|
|
&i.Symbol,
|
|
&i.WebsiteSlug,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listFearGreedIndexHistory = `-- name: ListFearGreedIndexHistory :many
|
|
SELECT id, created_at, updated_at, deleted_at, value, value_classification, timestamp, time_until_update FROM fear_greed_index
|
|
WHERE deleted_at IS NULL
|
|
ORDER BY timestamp DESC
|
|
LIMIT ? OFFSET ?
|
|
`
|
|
|
|
type ListFearGreedIndexHistoryParams struct {
|
|
Limit int64 `json:"limit"`
|
|
Offset int64 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) ListFearGreedIndexHistory(ctx context.Context, arg ListFearGreedIndexHistoryParams) ([]FearGreedIndex, error) {
|
|
rows, err := q.db.QueryContext(ctx, listFearGreedIndexHistory, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []FearGreedIndex
|
|
for rows.Next() {
|
|
var i FearGreedIndex
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.Value,
|
|
&i.ValueClassification,
|
|
&i.Timestamp,
|
|
&i.TimeUntilUpdate,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listGlobalMarketHistory = `-- name: ListGlobalMarketHistory :many
|
|
SELECT id, created_at, updated_at, deleted_at, total_market_cap_usd, total_24h_volume_usd, bitcoin_percentage_of_market_cap, active_currencies, active_assets, active_markets, last_updated FROM global_market
|
|
WHERE deleted_at IS NULL
|
|
ORDER BY last_updated DESC
|
|
LIMIT ? OFFSET ?
|
|
`
|
|
|
|
type ListGlobalMarketHistoryParams struct {
|
|
Limit int64 `json:"limit"`
|
|
Offset int64 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) ListGlobalMarketHistory(ctx context.Context, arg ListGlobalMarketHistoryParams) ([]GlobalMarket, error) {
|
|
rows, err := q.db.QueryContext(ctx, listGlobalMarketHistory, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GlobalMarket
|
|
for rows.Next() {
|
|
var i GlobalMarket
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.TotalMarketCapUsd,
|
|
&i.Total24hVolumeUsd,
|
|
&i.BitcoinPercentageOfMarketCap,
|
|
&i.ActiveCurrencies,
|
|
&i.ActiveAssets,
|
|
&i.ActiveMarkets,
|
|
&i.LastUpdated,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listHealthByChain = `-- name: ListHealthByChain :many
|
|
SELECT id, created_at, updated_at, deleted_at, endpoint_url, endpoint_type, chain_id, status, response_time_ms, last_checked, next_check, failure_count, success_count, response_data, error_message FROM health
|
|
WHERE chain_id = ? AND deleted_at IS NULL
|
|
ORDER BY last_checked DESC
|
|
LIMIT ? OFFSET ?
|
|
`
|
|
|
|
type ListHealthByChainParams struct {
|
|
ChainID sql.NullString `json:"chain_id"`
|
|
Limit int64 `json:"limit"`
|
|
Offset int64 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) ListHealthByChain(ctx context.Context, arg ListHealthByChainParams) ([]Health, error) {
|
|
rows, err := q.db.QueryContext(ctx, listHealthByChain, arg.ChainID, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Health
|
|
for rows.Next() {
|
|
var i Health
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.EndpointUrl,
|
|
&i.EndpointType,
|
|
&i.ChainID,
|
|
&i.Status,
|
|
&i.ResponseTimeMs,
|
|
&i.LastChecked,
|
|
&i.NextCheck,
|
|
&i.FailureCount,
|
|
&i.SuccessCount,
|
|
&i.ResponseData,
|
|
&i.ErrorMessage,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listHealthByStatus = `-- name: ListHealthByStatus :many
|
|
SELECT id, created_at, updated_at, deleted_at, endpoint_url, endpoint_type, chain_id, status, response_time_ms, last_checked, next_check, failure_count, success_count, response_data, error_message FROM health
|
|
WHERE status = ? AND deleted_at IS NULL
|
|
ORDER BY last_checked DESC
|
|
LIMIT ? OFFSET ?
|
|
`
|
|
|
|
type ListHealthByStatusParams struct {
|
|
Status string `json:"status"`
|
|
Limit int64 `json:"limit"`
|
|
Offset int64 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) ListHealthByStatus(ctx context.Context, arg ListHealthByStatusParams) ([]Health, error) {
|
|
rows, err := q.db.QueryContext(ctx, listHealthByStatus, arg.Status, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Health
|
|
for rows.Next() {
|
|
var i Health
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.EndpointUrl,
|
|
&i.EndpointType,
|
|
&i.ChainID,
|
|
&i.Status,
|
|
&i.ResponseTimeMs,
|
|
&i.LastChecked,
|
|
&i.NextCheck,
|
|
&i.FailureCount,
|
|
&i.SuccessCount,
|
|
&i.ResponseData,
|
|
&i.ErrorMessage,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listHealthChecksNeedingUpdate = `-- name: ListHealthChecksNeedingUpdate :many
|
|
SELECT id, created_at, updated_at, deleted_at, endpoint_url, endpoint_type, chain_id, status, response_time_ms, last_checked, next_check, failure_count, success_count, response_data, error_message FROM health
|
|
WHERE next_check <= CURRENT_TIMESTAMP AND deleted_at IS NULL
|
|
ORDER BY next_check ASC
|
|
LIMIT ?
|
|
`
|
|
|
|
func (q *Queries) ListHealthChecksNeedingUpdate(ctx context.Context, limit int64) ([]Health, error) {
|
|
rows, err := q.db.QueryContext(ctx, listHealthChecksNeedingUpdate, limit)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Health
|
|
for rows.Next() {
|
|
var i Health
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.EndpointUrl,
|
|
&i.EndpointType,
|
|
&i.ChainID,
|
|
&i.Status,
|
|
&i.ResponseTimeMs,
|
|
&i.LastChecked,
|
|
&i.NextCheck,
|
|
&i.FailureCount,
|
|
&i.SuccessCount,
|
|
&i.ResponseData,
|
|
&i.ErrorMessage,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listServicesByChain = `-- name: ListServicesByChain :many
|
|
SELECT id, created_at, updated_at, deleted_at, name, description, chain_id, address, owner_address, metadata, status, block_height FROM services
|
|
WHERE chain_id = ? AND deleted_at IS NULL
|
|
ORDER BY name ASC
|
|
LIMIT ? OFFSET ?
|
|
`
|
|
|
|
type ListServicesByChainParams struct {
|
|
ChainID string `json:"chain_id"`
|
|
Limit int64 `json:"limit"`
|
|
Offset int64 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) ListServicesByChain(ctx context.Context, arg ListServicesByChainParams) ([]Service, error) {
|
|
rows, err := q.db.QueryContext(ctx, listServicesByChain, arg.ChainID, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Service
|
|
for rows.Next() {
|
|
var i Service
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.ChainID,
|
|
&i.Address,
|
|
&i.OwnerAddress,
|
|
&i.Metadata,
|
|
&i.Status,
|
|
&i.BlockHeight,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listServicesByOwner = `-- name: ListServicesByOwner :many
|
|
SELECT id, created_at, updated_at, deleted_at, name, description, chain_id, address, owner_address, metadata, status, block_height FROM services
|
|
WHERE owner_address = ? AND deleted_at IS NULL
|
|
ORDER BY created_at DESC
|
|
LIMIT ? OFFSET ?
|
|
`
|
|
|
|
type ListServicesByOwnerParams struct {
|
|
OwnerAddress string `json:"owner_address"`
|
|
Limit int64 `json:"limit"`
|
|
Offset int64 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) ListServicesByOwner(ctx context.Context, arg ListServicesByOwnerParams) ([]Service, error) {
|
|
rows, err := q.db.QueryContext(ctx, listServicesByOwner, arg.OwnerAddress, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Service
|
|
for rows.Next() {
|
|
var i Service
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.ChainID,
|
|
&i.Address,
|
|
&i.OwnerAddress,
|
|
&i.Metadata,
|
|
&i.Status,
|
|
&i.BlockHeight,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const softDeleteActivity = `-- name: SoftDeleteActivity :exec
|
|
UPDATE activities
|
|
SET deleted_at = CURRENT_TIMESTAMP
|
|
WHERE id = ?
|
|
`
|
|
|
|
func (q *Queries) SoftDeleteActivity(ctx context.Context, id string) error {
|
|
_, err := q.db.ExecContext(ctx, softDeleteActivity, id)
|
|
return err
|
|
}
|
|
|
|
const softDeleteCryptoListing = `-- name: SoftDeleteCryptoListing :exec
|
|
UPDATE crypto_listings
|
|
SET deleted_at = CURRENT_TIMESTAMP
|
|
WHERE id = ?
|
|
`
|
|
|
|
func (q *Queries) SoftDeleteCryptoListing(ctx context.Context, id string) error {
|
|
_, err := q.db.ExecContext(ctx, softDeleteCryptoListing, id)
|
|
return err
|
|
}
|
|
|
|
const softDeleteFearGreedIndex = `-- name: SoftDeleteFearGreedIndex :exec
|
|
UPDATE fear_greed_index
|
|
SET deleted_at = CURRENT_TIMESTAMP
|
|
WHERE id = ?
|
|
`
|
|
|
|
func (q *Queries) SoftDeleteFearGreedIndex(ctx context.Context, id string) error {
|
|
_, err := q.db.ExecContext(ctx, softDeleteFearGreedIndex, id)
|
|
return err
|
|
}
|
|
|
|
const softDeleteGlobalMarket = `-- name: SoftDeleteGlobalMarket :exec
|
|
UPDATE global_market
|
|
SET deleted_at = CURRENT_TIMESTAMP
|
|
WHERE id = ?
|
|
`
|
|
|
|
func (q *Queries) SoftDeleteGlobalMarket(ctx context.Context, id string) error {
|
|
_, err := q.db.ExecContext(ctx, softDeleteGlobalMarket, id)
|
|
return err
|
|
}
|
|
|
|
const softDeleteHealth = `-- name: SoftDeleteHealth :exec
|
|
UPDATE health
|
|
SET deleted_at = CURRENT_TIMESTAMP
|
|
WHERE id = ?
|
|
`
|
|
|
|
func (q *Queries) SoftDeleteHealth(ctx context.Context, id string) error {
|
|
_, err := q.db.ExecContext(ctx, softDeleteHealth, id)
|
|
return err
|
|
}
|
|
|
|
const softDeleteService = `-- name: SoftDeleteService :exec
|
|
UPDATE services
|
|
SET deleted_at = CURRENT_TIMESTAMP
|
|
WHERE id = ?
|
|
`
|
|
|
|
func (q *Queries) SoftDeleteService(ctx context.Context, id string) error {
|
|
_, err := q.db.ExecContext(ctx, softDeleteService, id)
|
|
return err
|
|
}
|
|
|
|
const updateActivityStatus = `-- name: UpdateActivityStatus :one
|
|
UPDATE activities
|
|
SET
|
|
status = ?,
|
|
tx_hash = ?,
|
|
block_height = ?,
|
|
gas_used = ?,
|
|
raw_log = ?,
|
|
error = ?,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = ?
|
|
AND deleted_at IS NULL
|
|
RETURNING id, created_at, updated_at, deleted_at, account_id, tx_hash, tx_type, status, amount, fee, gas_used, gas_wanted, memo, block_height, timestamp, raw_log, error
|
|
`
|
|
|
|
type UpdateActivityStatusParams struct {
|
|
Status string `json:"status"`
|
|
TxHash sql.NullString `json:"tx_hash"`
|
|
BlockHeight sql.NullInt64 `json:"block_height"`
|
|
GasUsed sql.NullInt64 `json:"gas_used"`
|
|
RawLog sql.NullString `json:"raw_log"`
|
|
Error sql.NullString `json:"error"`
|
|
ID string `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateActivityStatus(ctx context.Context, arg UpdateActivityStatusParams) (Activity, error) {
|
|
row := q.db.QueryRowContext(ctx, updateActivityStatus,
|
|
arg.Status,
|
|
arg.TxHash,
|
|
arg.BlockHeight,
|
|
arg.GasUsed,
|
|
arg.RawLog,
|
|
arg.Error,
|
|
arg.ID,
|
|
)
|
|
var i Activity
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.AccountID,
|
|
&i.TxHash,
|
|
&i.TxType,
|
|
&i.Status,
|
|
&i.Amount,
|
|
&i.Fee,
|
|
&i.GasUsed,
|
|
&i.GasWanted,
|
|
&i.Memo,
|
|
&i.BlockHeight,
|
|
&i.Timestamp,
|
|
&i.RawLog,
|
|
&i.Error,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const updateCryptoListing = `-- name: UpdateCryptoListing :one
|
|
UPDATE crypto_listings
|
|
SET
|
|
name = ?,
|
|
symbol = ?,
|
|
website_slug = ?,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = ?
|
|
AND deleted_at IS NULL
|
|
RETURNING id, created_at, updated_at, deleted_at, api_id, name, symbol, website_slug
|
|
`
|
|
|
|
type UpdateCryptoListingParams struct {
|
|
Name string `json:"name"`
|
|
Symbol string `json:"symbol"`
|
|
WebsiteSlug string `json:"website_slug"`
|
|
ID string `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateCryptoListing(ctx context.Context, arg UpdateCryptoListingParams) (CryptoListing, error) {
|
|
row := q.db.QueryRowContext(ctx, updateCryptoListing,
|
|
arg.Name,
|
|
arg.Symbol,
|
|
arg.WebsiteSlug,
|
|
arg.ID,
|
|
)
|
|
var i CryptoListing
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.ApiID,
|
|
&i.Name,
|
|
&i.Symbol,
|
|
&i.WebsiteSlug,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const updateFearGreedIndex = `-- name: UpdateFearGreedIndex :one
|
|
UPDATE fear_greed_index
|
|
SET
|
|
value = ?,
|
|
value_classification = ?,
|
|
timestamp = ?,
|
|
time_until_update = ?,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = ?
|
|
AND deleted_at IS NULL
|
|
RETURNING id, created_at, updated_at, deleted_at, value, value_classification, timestamp, time_until_update
|
|
`
|
|
|
|
type UpdateFearGreedIndexParams struct {
|
|
Value int64 `json:"value"`
|
|
ValueClassification string `json:"value_classification"`
|
|
Timestamp time.Time `json:"timestamp"`
|
|
TimeUntilUpdate sql.NullString `json:"time_until_update"`
|
|
ID string `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateFearGreedIndex(ctx context.Context, arg UpdateFearGreedIndexParams) (FearGreedIndex, error) {
|
|
row := q.db.QueryRowContext(ctx, updateFearGreedIndex,
|
|
arg.Value,
|
|
arg.ValueClassification,
|
|
arg.Timestamp,
|
|
arg.TimeUntilUpdate,
|
|
arg.ID,
|
|
)
|
|
var i FearGreedIndex
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.Value,
|
|
&i.ValueClassification,
|
|
&i.Timestamp,
|
|
&i.TimeUntilUpdate,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const updateGlobalMarket = `-- name: UpdateGlobalMarket :one
|
|
UPDATE global_market
|
|
SET
|
|
total_market_cap_usd = ?,
|
|
total_24h_volume_usd = ?,
|
|
bitcoin_percentage_of_market_cap = ?,
|
|
active_currencies = ?,
|
|
active_assets = ?,
|
|
active_markets = ?,
|
|
last_updated = ?,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = ?
|
|
AND deleted_at IS NULL
|
|
RETURNING id, created_at, updated_at, deleted_at, total_market_cap_usd, total_24h_volume_usd, bitcoin_percentage_of_market_cap, active_currencies, active_assets, active_markets, last_updated
|
|
`
|
|
|
|
type UpdateGlobalMarketParams struct {
|
|
TotalMarketCapUsd sql.NullFloat64 `json:"total_market_cap_usd"`
|
|
Total24hVolumeUsd sql.NullFloat64 `json:"total_24h_volume_usd"`
|
|
BitcoinPercentageOfMarketCap sql.NullFloat64 `json:"bitcoin_percentage_of_market_cap"`
|
|
ActiveCurrencies sql.NullInt64 `json:"active_currencies"`
|
|
ActiveAssets sql.NullInt64 `json:"active_assets"`
|
|
ActiveMarkets sql.NullInt64 `json:"active_markets"`
|
|
LastUpdated time.Time `json:"last_updated"`
|
|
ID string `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateGlobalMarket(ctx context.Context, arg UpdateGlobalMarketParams) (GlobalMarket, error) {
|
|
row := q.db.QueryRowContext(ctx, updateGlobalMarket,
|
|
arg.TotalMarketCapUsd,
|
|
arg.Total24hVolumeUsd,
|
|
arg.BitcoinPercentageOfMarketCap,
|
|
arg.ActiveCurrencies,
|
|
arg.ActiveAssets,
|
|
arg.ActiveMarkets,
|
|
arg.LastUpdated,
|
|
arg.ID,
|
|
)
|
|
var i GlobalMarket
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.TotalMarketCapUsd,
|
|
&i.Total24hVolumeUsd,
|
|
&i.BitcoinPercentageOfMarketCap,
|
|
&i.ActiveCurrencies,
|
|
&i.ActiveAssets,
|
|
&i.ActiveMarkets,
|
|
&i.LastUpdated,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const updateHealthCheck = `-- name: UpdateHealthCheck :one
|
|
UPDATE health
|
|
SET
|
|
status = ?,
|
|
response_time_ms = ?,
|
|
last_checked = CURRENT_TIMESTAMP,
|
|
next_check = ?,
|
|
failure_count = CASE WHEN status = 'failed' THEN failure_count + 1 ELSE failure_count END,
|
|
success_count = CASE WHEN status = 'success' THEN success_count + 1 ELSE success_count END,
|
|
response_data = ?,
|
|
error_message = ?,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = ?
|
|
AND deleted_at IS NULL
|
|
RETURNING id, created_at, updated_at, deleted_at, endpoint_url, endpoint_type, chain_id, status, response_time_ms, last_checked, next_check, failure_count, success_count, response_data, error_message
|
|
`
|
|
|
|
type UpdateHealthCheckParams struct {
|
|
Status string `json:"status"`
|
|
ResponseTimeMs sql.NullInt64 `json:"response_time_ms"`
|
|
NextCheck sql.NullTime `json:"next_check"`
|
|
ResponseData sql.NullString `json:"response_data"`
|
|
ErrorMessage sql.NullString `json:"error_message"`
|
|
ID string `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateHealthCheck(ctx context.Context, arg UpdateHealthCheckParams) (Health, error) {
|
|
row := q.db.QueryRowContext(ctx, updateHealthCheck,
|
|
arg.Status,
|
|
arg.ResponseTimeMs,
|
|
arg.NextCheck,
|
|
arg.ResponseData,
|
|
arg.ErrorMessage,
|
|
arg.ID,
|
|
)
|
|
var i Health
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.EndpointUrl,
|
|
&i.EndpointType,
|
|
&i.ChainID,
|
|
&i.Status,
|
|
&i.ResponseTimeMs,
|
|
&i.LastChecked,
|
|
&i.NextCheck,
|
|
&i.FailureCount,
|
|
&i.SuccessCount,
|
|
&i.ResponseData,
|
|
&i.ErrorMessage,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const updateService = `-- name: UpdateService :one
|
|
UPDATE services
|
|
SET
|
|
name = ?,
|
|
description = ?,
|
|
owner_address = ?,
|
|
metadata = ?,
|
|
status = ?,
|
|
block_height = ?,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = ?
|
|
AND deleted_at IS NULL
|
|
RETURNING id, created_at, updated_at, deleted_at, name, description, chain_id, address, owner_address, metadata, status, block_height
|
|
`
|
|
|
|
type UpdateServiceParams struct {
|
|
Name string `json:"name"`
|
|
Description sql.NullString `json:"description"`
|
|
OwnerAddress string `json:"owner_address"`
|
|
Metadata sql.NullString `json:"metadata"`
|
|
Status string `json:"status"`
|
|
BlockHeight int64 `json:"block_height"`
|
|
ID string `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateService(ctx context.Context, arg UpdateServiceParams) (Service, error) {
|
|
row := q.db.QueryRowContext(ctx, updateService,
|
|
arg.Name,
|
|
arg.Description,
|
|
arg.OwnerAddress,
|
|
arg.Metadata,
|
|
arg.Status,
|
|
arg.BlockHeight,
|
|
arg.ID,
|
|
)
|
|
var i Service
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.ChainID,
|
|
&i.Address,
|
|
&i.OwnerAddress,
|
|
&i.Metadata,
|
|
&i.Status,
|
|
&i.BlockHeight,
|
|
)
|
|
return i, err
|
|
}
|