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

why can't I use "user" as the name of table #114

Closed
BugKun opened this issue Mar 31, 2020 · 1 comment
Closed

why can't I use "user" as the name of table #114

BugKun opened this issue Mar 31, 2020 · 1 comment

Comments

@BugKun
Copy link

BugKun commented Mar 31, 2020

sqlBricks.select().from('user').where({'id': 1}).toString()
// SELECT * FROM "user" WHERE id = 1
sqlBricks.select().from('users').where({'id': 1}).toString()
// SELECT * FROM users WHERE id = 1

why it has the quotation mark when i use "user" as the table name?
It can not run in mysql.

@prust
Copy link
Collaborator

prust commented Apr 4, 2020

@BugKun: Sorry for the delay responding. The sql-bricks library is a core library focused on the ANSI SQL specification. If you're targeting mysql, the MySQL extension will work better for you: https://github.com/tamarzil/mysql-bricks.

Or, you could copy the line from the MySQL extension that overrides the quote character, changing it from the generic " to MySQL's ` on line 9:

sql._autoQuoteChar = '`';

SQLBrick's list of reserved words is a union of the reserved words from sqlite and postgres (including user). Instead, it should default to a list of reserved words from the specification and should relegate the sqlite/postgres/mysql/etc lists to the relevant extensions (#116). That said, it looks like "user" is also a reserved word in mysql: https://dev.mysql.com/doc/refman/8.0/en/keywords.html.

@prust prust closed this as completed Apr 4, 2020
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

2 participants