Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conflicts with column names and properties in the table data structure #36

Open
johndyoung opened this issue Feb 17, 2013 · 3 comments
Open

Comments

@johndyoung
Copy link

Because all table columns are added as closure properties, certain column names are incompatible with node-sql due to conflicting property names (table and alias, for example).

Initially, I thought that turning the columns list into an object to be used like the column name closure properties are would work, but then that would break the interface.

So, maybe making all of the non-column name attributes start with a "_" or something would work better?

I haven't pulled my sleeves up and really dug into the code yet, so I'm not sure what change would solve this with the least amount of "gotchas."

Thoughts?

@brianc
Copy link
Owner

brianc commented Feb 18, 2013

The incompatibility comes from not being able to do something like this, correct?:

var someTable = sql.define({
  name 'someTable',
  columns: ['join', 'select']
});

someTable.select(someTable.join, someTable.select).from(someTable)

Would this be a decent solution?:

var someTable = sql.define({
  name 'someTable',
  columns: ['join', 'select']
});

someTable.select(someTable.column('join'), someTable.column.select).from(someTable)

@panta82
Copy link

panta82 commented Apr 29, 2013

I'm having the same problem (managed to open a duplicate issue too :-))

Since there are just a few column names that are likely to cause collision, how about some kind of fudge where conflict column names are prefixed by some valid javascript but invalid SQL character, that is then truncated when crafting SQL?

eg:

var someTable = sql.define({
     name 'someTable',
     columns: ['join', 'abc']
 });

someTable.select(someTable.abc, someTable.$join).from(someTable);

@mscdex
Copy link

mscdex commented Oct 6, 2013

+1000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants