Skip to content

Instantly share code, notes, and snippets.

@maxdemarzi maxdemarzi/woql-woql-woql.txt Secret
Created Jan 18, 2020

Embed
What would you like to do?
Leaking woqls
const csv = WOQL.get(
WOQL.as("Start station","v:Start_Station")
.as("End station", "v:End_Station")
.as("Start date", "v:Start_Time")
.as("End date", "v:End_Time")
.as("Duration", "v:Duration")
.as("Start station number", "v:Start_ID")
.as("End station number", "v:End_ID")
.as("Bike number", "v:Bike")
.as("Member type", "v:Member_Type")
).remote("https://terminusdb.com/t/data/bike_tutorial.csv")
//Clean data for insert
const wrangles = [
WOQL.typecast("v:Duration", "xsd:integer", "v:Duration_Cast"),
WOQL.typecast("v:Bike", "xsd:string", "v:Bike_Label"),
WOQL.typecast("v:Start_Time", "xsd:dateTime", "v:ST_Cast"),
WOQL.typecast("v:End_Time", "xsd:dateTime", "v:ET_Cast"),
WOQL.typecast("v:Start_Station", "xsd:string", "v:SS_Label"),
WOQL.typecast("v:End_Station", "xsd:string", "v:ES_Label"),
WOQL.idgen("doc:Journey",["v:Start_ID","v:Start_Time","v:Bike"],"v:Journey_ID"),
WOQL.idgen("doc:Station",["v:Start_ID"],"v:Start_Station_URL"),
WOQL.idgen("doc:Station",["v:End_ID"],"v:End_Station_URL"),
WOQL.idgen("doc:Bicycle",["v:Bike_Label"],"v:Bike_URL"), WOQL.concat("v:Start_ID - v:End_ID @ v:Start_Time","v:J_Label"),
WOQL.concat("Bike v:Bike from v:Start_Station to v:End_Station at v:Start_Time until v:End_Time","v:Journey_Description")
];
//combine inputs
const inputs = WOQL.and(csv, ...wrangles)
//generate data to be inserted
const inserts = WOQL.and(
WOQL.insert("v:Journey_ID", "Journey")
.label("v:J_Label")
.description("v:Journey_Description")
.property("start_time", "v:ST_Cast")
.property("end_time", "v:ET_Cast")
.property("duration", "v:Duration_Cast")
.property("start_station", "v:Start_Station_URL")
.property("end_station", "v:End_Station_URL")
.property("journey_bicycle", "v:Bike_URL"),
WOQL.insert("v:Start_Station_URL", "Station")
.label("v:SS_Label"),
WOQL.insert("v:End_Station_URL", "Station")
.label("v:ES_Label"),
WOQL.insert("v:Bike_URL", "Bicycle")
.label("v:Bike_Label")
);
//Combine inputs and inserts with when clause
WOQL.when(inputs, inserts);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.