From 339e7aaabfd4a37687ffab7968bbc981d00d5a74 Mon Sep 17 00:00:00 2001 From: Avraham Sakal Date: Sun, 18 Jun 2023 17:42:31 -0400 Subject: [PATCH] add "underlyings" materialized view --- src/index.ts | 4 ++-- src/ingest.ts | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 4c551ab..477a8a0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,14 +10,14 @@ import fastify from 'fastify' import cors from '@fastify/cors' const server = fastify() -await server.register(cors, {}); +await server.register(cors, {origin:true}); server.get('/ping', async (request, reply) => { return 'pong\n' }) server.get('/option_quotes/underlyings', async (request, reply) => { - const underlyings = (await sql`SELECT DISTINCT "underlying" FROM "option_quote";`).map(x=>x.underlying); + const underlyings = (await sql`SELECT * FROM "underlyings";`).map(x=>x.underlying); reply.status(200).send(underlyings); }) server.get<{ diff --git a/src/ingest.ts b/src/ingest.ts index 153b020..7c5f08c 100644 --- a/src/ingest.ts +++ b/src/ingest.ts @@ -161,4 +161,5 @@ export async function ingestOptions(sourceDataDir:string):Promise{ }; console.log("creating index"); await sql`CREATE INDEX ON "option_quote" USING btree ("underlying","expiration","type","strike","quote_date");`; + await sql`CREATE MATERIALIZED VIEW "underlyings" AS SELECT DISTINCT "underlying" FROM "option_quote";`; } \ No newline at end of file