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

Support SQL keyword as column names #131

Closed
hyouuu opened this issue Nov 6, 2016 · 1 comment
Closed

Support SQL keyword as column names #131

hyouuu opened this issue Nov 6, 2016 · 1 comment

Comments

@hyouuu
Copy link

hyouuu commented Nov 6, 2016

Feature, Enhancement, or Optimization

Name of Feature

Support SQL keyword as column names

Introduction

I was adding a model with a "var desc: String" field, then in the preparation step console shows error:

Failed to prepare [ModelName]
invalidSQL("ERROR: syntax error at or near "desc"\nLINE 1: ...RIMARY KEY NOT NULL, desc VARCH...\n ^\n")"

(more details in vapor-community/postgresql-provider#9)

Changing "desc" to "desca" fixes the problem, and apparently it's caused by "desc" as a reserved keyword in SQL, which could be worked around by adding [] around the column names (http://stackoverflow.com/questions/285775/how-to-deal-with-sql-column-names-that-look-like-sql-keywords).

Motivation

Since Fluent should be DB agnostic, it shouldn't limit what name Model var/column could have, so we should make it support any var name.

Proposed solution

Not sure if MySQL, Postgres & MongoDB share similar solution to special column names or not, but for Postgres for example, we probably could always add [] around the column names when making queries or commands to make sure they work - it could also be the job of each provider or driver, but probably we want to start with Fluent to at least provide comment/instruction about column names to the providers.

Impact

Shouldn't have any impact to existing code

Alternatives considered

Have better error output when a reserved keyword is used, which is not as ideal

Decision (For Moderator Use)

On [Date], the community decided to (TBD) this proposal. When the community makes a decision regarding this proposal, their rationale for the decision will be written here.

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