-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
227 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { deleteFromDatabase, saveModelsToDatabase, selectFromDatabase } from '../database' | ||
import { AssetPriceModel } from '../types' | ||
|
||
class AssetPriceHandler { | ||
private readonly assetTableName = "asset_prices" | ||
|
||
async createOrUpdate(model: AssetPriceModel): Promise<void> { | ||
await saveModelsToDatabase(this.assetTableName, [model]) | ||
} | ||
|
||
async listPrices(): Promise<AssetPriceModel[]> { | ||
return selectFromDatabase<AssetPriceModel>(this.assetTableName, {}) | ||
} | ||
|
||
async listPricesBySymbol(symbol: string): Promise<AssetPriceModel[]> { | ||
return selectFromDatabase<AssetPriceModel>(this.assetTableName, { symbol }) | ||
} | ||
|
||
async listPricesAfterAssetCreatedAt(assetCreatedAt?: string): Promise<AssetPriceModel[]> { | ||
const plainWhere = assetCreatedAt ? 'assetCreatedAt > ?' : undefined | ||
const values = assetCreatedAt ? [assetCreatedAt] : undefined | ||
return selectFromDatabase<AssetPriceModel>(this.assetTableName, {}, undefined, undefined, plainWhere, values) | ||
} | ||
|
||
async listPricesAfterUpdatedAt(updatedAt?: string): Promise<AssetPriceModel[]> { | ||
const plainWhere = updatedAt ? 'updatedAt > ?' : undefined | ||
const values = updatedAt ? [updatedAt] : undefined | ||
return selectFromDatabase<AssetPriceModel>(this.assetTableName, {}, undefined, undefined, plainWhere, values) | ||
} | ||
|
||
async deletePricesByUUID(uuid: string) { | ||
await deleteFromDatabase(this.assetTableName, { uuid }) | ||
} | ||
|
||
async deletePricesByAssetID(assetID: number) { | ||
await deleteFromDatabase(this.assetTableName, { assetID }) | ||
} | ||
|
||
async savePrices(models: AssetPriceModel[]) { | ||
return saveModelsToDatabase(this.assetTableName, models) | ||
} | ||
} | ||
|
||
export const ASSET_PRICE_HANDLER = new AssetPriceHandler() |
Oops, something went wrong.