I am attempting to extract a set of parameters for RegExp.$ (also known as JavaScript f-strings) from a JSON file.
const schema = require('../schema.json').Flights;
class flightRepo{
keys = Object.keys(schema);
create(db) {
return client.query(
"INSERT INTO flights ($1, $2, $3, $4, $5, $6) VALUES ($7, $8, $9, $10, $11, $12)",
keys[0], keys[1], keys[2], keys[3], keys[4], keys[5],
db.schema.keys[0], db.schema.keys[1], db.schema.keys[2], db.schema.keys[3], db.schema.keys[4], db.schema.keys[5]
);
}
}
ABOUT
client.query: Utilizes the Client Object from Deno's PostgreSQL Library
db: Receives a list [args[0-5] for each key] to generate a new DB entry
create: Function returns the query status obtained from PostgreSQL
JSON STRUCTURE
{
"Flights" : {
"FlightNo": "INT PRIMARY KEY",
"Airlines": "STRING 50",
"Time"": "DATETIME",
"OnTime": "BOOLEAN",
"Dep": "STRING 4",
"Arr": "STRING 4"
}
}
My goal was to eliminate the manual specification of n args (keys[0-5]) and ($1-12), and instead come up with an expression that can handle any x-item key list.
(plus, finding a way to omit the need to enter "Flights" as the JSON key in Line 1 would be beneficial)