This repository was archived by the owner on Sep 17, 2024. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99 " ABCxFF"
1010 ],
1111 "scripts" : {
12+ "push_event" : {
13+ "public" : true
14+ }
1215 },
1316 "errors" : {},
1417 "dependencies" : {}
Original file line number Diff line number Diff line change 1+ import { ScriptContext } from "../module.gen.ts" ;
2+ import { createHypertable } from "../utils/hypertable_init.ts" ;
3+
4+ export interface Request {
5+ name : string ,
6+ metadata : any ,
7+ timestampOverride ?: string ,
8+ }
9+
10+ export interface Response {
11+ id : string ,
12+ timestamp : number ,
13+ }
14+
15+ export async function run (
16+ ctx : ScriptContext ,
17+ req : Request ,
18+ ) : Promise < Response > {
19+ createHypertable ( ctx ) ;
20+ const timestamp = req . timestampOverride ? new Date ( req . timestampOverride ) : new Date ( ) ;
21+ const event = await ctx . db . event . create ( {
22+ data : {
23+ name : req . name ,
24+ timestamp,
25+ metadata : req . metadata
26+ }
27+ } ) ;
28+
29+ return { id : event . id , timestamp : timestamp . getTime ( ) } ;
30+ }
31+
Original file line number Diff line number Diff line change 1+ import { ScriptContext } from "../module.gen.ts" ;
2+
3+ let hasDefinitelyRun = false ;
4+ export const createHypertable = async ( ctx : ScriptContext ) => {
5+ if ( hasDefinitelyRun ) return ;
6+
7+ await ctx . db . $queryRaw `SELECT create_hypertable('event', 'timestamp');` ;
8+
9+ hasDefinitelyRun = true ;
10+ }
You can’t perform that action at this time.
0 commit comments