I'm having trouble creating a table with dynamically amount of columns.
I have an Object, where i don't know the amount of keys exactly:
var obj = {
data_1: 123,
data_2: 456,
data_3: 789,
(...)
};
Each key of this Object should become a column in the new table. Fortunately, the column datatype is always a double.
I need something like this:
"CREATE TABLE 'Data' (
FOREIGN KEY (id) REFERENCES other_table(id), // this is fixed
data_0 int, // this is fixed
Object.keys(obj) double
)"
Is this even possible? I could find nothing that looks similar to this.
I'd be really glad, if someone could help me out with this one.
Object.keys(data).map(k=>k+" int,\n").data_entries, and you need to be able to query the data stored fordata_then you need to have a table in the formother_table(id), key, valueand eachdata_is an own row in the table. If you have a maximum number of keys per entry, then you can think about columns than can be NULL."CREATE TABLE new_table (ID int, FOREIGN KEY (ID) REFERENCES other_table (ID), data_0 int, "+ Object.keys(obj).map(k=>k+" double")+")"