add "underlyings" materialized view
This commit is contained in:
+2
-2
@@ -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<{
|
||||||
|
|||||||
@@ -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";`;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user