add "underlyings" materialized view

This commit is contained in:
2023-06-18 17:42:31 -04:00
parent 9bc54ea24f
commit 339e7aaabf
2 changed files with 3 additions and 2 deletions
+2 -2
View File
@@ -10,14 +10,14 @@ import fastify from 'fastify'
import cors from '@fastify/cors' import cors from '@fastify/cors'
const server = fastify() const server = fastify()
await server.register(cors, {}); await server.register(cors, {origin:true});
server.get('/ping', async (request, reply) => { server.get('/ping', async (request, reply) => {
return 'pong\n' return 'pong\n'
}) })
server.get('/option_quotes/underlyings', async (request, reply) => { 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); reply.status(200).send(underlyings);
}) })
server.get<{ server.get<{
+1
View File
@@ -161,4 +161,5 @@ export async function ingestOptions(sourceDataDir:string):Promise<void>{
}; };
console.log("creating index"); console.log("creating index");
await sql`CREATE INDEX ON "option_quote" USING btree ("underlying","expiration","type","strike","quote_date");`; 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";`;
} }