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
import { createClient } from "@tursodatabase/api"; | |
import { createClient as createTursoClient } from "@libsql/client" | |
import {migrate} from "drizzle-orm/libsql/migrator"; | |
import {drizzle} from "drizzle-orm/libsql"; | |
// THE SCHEMA OF THE ORG DBs (not the main one) | |
import * as schema from "../drizzle/org-schemas"; | |
import {DEFAULT_API_TOKEN, TURSO_API_TOKEN} from "./secrets"; | |
const listDBs = async () => { |
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
export class MomentoFetcher { | |
private readonly apiKey: string; | |
private readonly baseurl: string; | |
constructor(key: string, endpoint: string) { | |
this.apiKey = key; | |
if (!endpoint.startsWith('https://')) { | |
this.baseurl = `https://${endpoint}`; | |
} else { | |
this.baseurl = `${endpoint}`; | |
} |
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 component actually needs the messages from Momento, so it uses useTopic() to subscribe to the stream. | |
*/ | |
"use client"; | |
import {FC, useEffect, useState} from 'react'; | |
import { TopicItem } from '@gomomento/sdk-web'; | |
import { Subscription } from 'rxjs'; |
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
import {publishToTopic} from "../src/momento/client"; | |
const MOMENTO_CACHE_DB_TRIGGERS_API_KEY='' | |
const MOMENTO_CACHE_DB_TRIGGERS_CACHE_NAME='' | |
const MOMENTO_CACHE_DB_TRIGGERS_TOPIC_BASE_URL='' | |
const MOMENTO_CACHE_DB_TRIGGERS_TOPIC_NAME='' | |
const msg = { | |
query_type: 'test', | |
table_name: 'no-table', |
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
import {LibSQLPlugin} from "libsql-client-hooks"; | |
import {Client, InStatement, ResultSet} from '@libsql/core/api'; | |
import { | |
deepDiffPartials, | |
isUpdateForTable, | |
removeDoubleQuotes, | |
replaceAllSequencesFromQuery | |
} from "./utils"; | |
import {TableNamesTurso} from "../index"; |
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
import {LibSQLPlugin} from "libsql-client-hooks"; | |
import { InStatement, Client, ResultSet } from '@libsql/core/api'; | |
import {isUpdateForTable, removeSpaces} from "./utils"; | |
import {TableNamesTurso} from "../index"; | |
export class UpdateRowBeforeAndAfterPlugin<T> implements LibSQLPlugin { | |
private rowBefore: T | undefined; | |
constructor( |
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
export function isUpdateForTable(query: any, tableName: string): boolean { | |
const escapedTableName = tableName.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); | |
const regexp = new RegExp(`update "?${escapedTableName}"? set`, 'i'); | |
return regexp.test(typeof query === "string" ? query : query.sql); | |
} | |
export function isInsertForTable(query: any, tableName: string): boolean { | |
const escapedTableName = tableName.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); | |
const regexp = new RegExp(`insert into "?${escapedTableName}"?`, 'i'); | |
return regexp.test(typeof query === "string" ? query : query.sql); |
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
import {QueryCommand, QueryCommandInput} from "@aws-sdk/client-timestream-query"; | |
export function minDifferenceDates(d1:Date, d2:Date) { | |
const differenceMs = d1.getTime() - d2.getTime(); | |
return Math.abs(differenceMs / (1000 * 60)); | |
} | |
export function minutesAgo(agoMinutes:number) { | |
const now = new Date().getTime(); |
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
const fromRowToDictonary = (rows: any[]) => { | |
const dictonary: LastKnownCandlesDictonary = {}; | |
rows.forEach((row) => { | |
dictonary[row.symbol] = row.lastaction; | |
}); | |
return dictonary; | |
} | |
const reformatRowToObj = (res: QueryCommandOutput) => { |
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
import { OHLCV } from 'ccxt'; | |
import { getInsertRecordParameterToTimeStream, writeBatchToTimestream } from './write'; | |
import { SymbolAndCandles } from '../lambda/candle-fetcher/models'; | |
import { | |
_Record, | |
Dimension, | |
MeasureValue, | |
MeasureValueType, TimestreamWriteClient, | |
WriteRecordsCommand, WriteRecordsCommandOutput, | |
WriteRecordsRequest, |
NewerOlder