Here's the original question.
Okay, I'm using Node.js and Edge.js to insert values to an SQL database. First attempt was a straightforward insertion of hardcoded values:
var insertRow = edge.func('sql', function () {/*
INSERT INTO dbo.table (column0, column1, column2)
VALUES (value0, value1, value2)
*/});
insertRow();
This hardcoded insertion works as expected, of course. And as seen in the answer of the question before me, passing the function an object allows the SQL statement to recognize a name/value pair of the object via an @, allowing dynamic value assignment:
var rowObj = {
v0: 'value0',
v1: 'value1',
v2: 'value2'
}
var insertRow = edge.func('sql', function () {/*
INSERT INTO dbo.table (column0, column1, column2)
VALUES (@v0, @v1, @v2)
*/});
insertRow(rowObj);
Works as expected. What I would like to do is have the table and columns be variable as well, through properties provided by the same rowObj. I tried:
var rowObj = {
t: 'dbo.table',
c0: 'column0',
c1: 'column1',
c2: 'column2',
v0: 'value0',
v1: 'value1',
v2: 'value2'
}
var insertRow = edge.func('sql', function () {/*
INSERT INTO @t (@c0, @c1, @c2)
VALUES (@v0, @v1, @v2)
*/});
insertRow(rowObj);
But this doesn't work. I tried making the table dynamic on its own, and the columns on their own, and that didn't work either.
note: I don't know SQL, I don't know the limitations of Node.js/Edge.js, and I'm very new to programming in general (so if my nomenclature is inconsistent/wrong, let me know but please don't tear me apart) I was just wondering if what I'm trying to do can be done.