add "underlyings" materialized view

master
Avraham Sakal 2 years ago
parent 9bc54ea24f
commit 339e7aaabf

@ -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<{

@ -161,4 +161,5 @@ export async function ingestOptions(sourceDataDir:string):Promise<void>{
};
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";`;
}
Loading…
Cancel
Save