Skip to content

Commit

Permalink
fix when string are uppercase
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Lefebvre committed Oct 31, 2023
1 parent d771fb7 commit d78b94f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions src/queries.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
const chain = "eth";
const address = "dac17f958d2ee523a2206206994597c13d831ec7";
const limit = "1";
const symbol = "USDT";
const name = "Tether USD";
const symbol = "usdt";
const name = "tether usd";
const greater_or_equals_by_timestamp = "1697587200";
const less_or_equals_by_timestamp = "1697587100";
const transaction_id =
Expand Down Expand Up @@ -65,7 +65,7 @@ test("getContracts with options", () => {
});
expect(formatSQL(getContracts(parameter))).toContain(
formatSQL(
`WHERE(chain == '${chain}' AND address == '${address}' AND symbol == '${symbol}' AND name == '${name}' AND toUnixTimestamp(timestamp) >= ${greater_or_equals_by_timestamp} AND toUnixTimestamp(timestamp) <= ${less_or_equals_by_timestamp})`
`WHERE(chain == '${chain}' AND address == '${address}' AND LOWER(symbol) == '${symbol}' AND LOWER(name) == '${name}' AND toUnixTimestamp(timestamp) >= ${greater_or_equals_by_timestamp} AND toUnixTimestamp(timestamp) <= ${less_or_equals_by_timestamp})`
)
);
});
Expand Down Expand Up @@ -140,7 +140,7 @@ test("getTotalSupply with options", () => {
});
expect(formatSQL(getTotalSupply(parameters))).toContain(
formatSQL(
`WHERE(TotalSupply.chain == '${chain}' AND TotalSupply.address == '${address}' AND toUnixTimestamp(timestamp) >= ${greater_or_equals_by_timestamp} AND toUnixTimestamp(timestamp) <= ${less_or_equals_by_timestamp} AND symbol == '${symbol}' AND name == '${name}')`
`WHERE(TotalSupply.chain == '${chain}' AND TotalSupply.address == '${address}' AND toUnixTimestamp(timestamp) >= ${greater_or_equals_by_timestamp} AND toUnixTimestamp(timestamp) <= ${less_or_equals_by_timestamp} AND LOWER(symbol) == '${symbol}' AND LOWER(name) == '${name}')`
)
);
});
Expand Down
26 changes: 13 additions & 13 deletions src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export function addTimestampBlockFilter(searchParams: URLSearchParams, where: an

export function getTotalSupply(searchParams: URLSearchParams, example?: boolean) {
// Params
const address = getAddress(searchParams, "address", false);
const address = getAddress(searchParams, "address", false)?.toLowerCase();
const chain = searchParams.get("chain");
const symbol = searchParams.get("symbol");
const name = searchParams.get("name");
const symbol = searchParams.get("symbol")?.toLowerCase();
const name = searchParams.get("name")?.toLowerCase();

// Query
const table = 'TotalSupply'
Expand Down Expand Up @@ -56,8 +56,8 @@ export function getTotalSupply(searchParams: URLSearchParams, example?: boolean)
// timestamp and block filter
addTimestampBlockFilter(searchParams, where);

if (symbol) where.push(`symbol == '${symbol}'`);
if (name) where.push(`name == '${name}'`);
if (symbol) where.push(`LOWER(symbol) == '${symbol}'`);
if (name) where.push(`LOWER(name) == '${name}'`);


// Join WHERE statements with AND
Expand All @@ -77,9 +77,9 @@ export function getTotalSupply(searchParams: URLSearchParams, example?: boolean)
export function getContracts(searchParams: URLSearchParams, example?: boolean) {
// Params
const chain = searchParams.get("chain");
const address = getAddress(searchParams, "address", false);
const symbol = searchParams.get("symbol");
const name = searchParams.get("name");
const address = getAddress(searchParams, "address", false)?.toLowerCase();
const symbol = searchParams.get("symbol")?.toLowerCase();
const name = searchParams.get("name")?.toLowerCase();

// Query
const table = 'Contracts'
Expand All @@ -93,8 +93,8 @@ export function getContracts(searchParams: URLSearchParams, example?: boolean) {
const where = [];
if (chain) where.push(`chain == '${chain}'`);
if (address) where.push(`address == '${address}'`);
if (symbol) where.push(`symbol == '${symbol}'`);
if (name) where.push(`name == '${name}'`);
if (symbol) where.push(`LOWER(symbol) == '${symbol}'`);
if (name) where.push(`LOWER(name) == '${name}'`);

// timestamp and block filter
addTimestampBlockFilter(searchParams, where);
Expand All @@ -114,9 +114,9 @@ export function getContracts(searchParams: URLSearchParams, example?: boolean) {

export function getBalanceChanges(searchParams: URLSearchParams, example?: boolean) {
const chain = searchParams.get("chain");
const contract = getAddress(searchParams, "contract", false);
const owner = getAddress(searchParams, "owner", false);
const transaction_id = searchParams.get("transaction_id");
const contract = getAddress(searchParams, "contract", false)?.toLowerCase();
const owner = getAddress(searchParams, "owner", false)?.toLowerCase();
const transaction_id = searchParams.get("transaction_id")?.toLowerCase();
// SQL Query
const table = 'balance_changes'
const contractTable = 'Contracts';
Expand Down

0 comments on commit d78b94f

Please sign in to comment.