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

Need for 'INSERT INTO TableName DEFAULT VALUES ' #87

Open
coderuid opened this issue Jul 6, 2016 · 1 comment
Open

Need for 'INSERT INTO TableName DEFAULT VALUES ' #87

coderuid opened this issue Jul 6, 2016 · 1 comment

Comments

@coderuid
Copy link

coderuid commented Jul 6, 2016

With undefined values or columns in sql.insert() expected to use database defaults. Now we have
INSERT INTO "TableName" () VALUES ()

@prust
Copy link
Collaborator

prust commented Jul 6, 2016

@coderuid: Sure enough, DEFAULT VALUES is included in Sql-92, I had no idea. From section 13.8 <insert statement> (page 388 of the spec):


         <insert statement> ::=
              INSERT INTO <table name>
                <insert columns and source>

         <insert columns and source> ::=
                [ <left paren> <insert column list> <right paren> ]
              <query expression>
              | DEFAULT VALUES

         <insert column list> ::= <column name list>

I'm ok with making it the default behavior if no values are provided, but I think it's important for it to also be available as explicit method like this: sql.insert('TableName').defaultValues() -> INSERT INTO "TableName" DEFAULT VALUES.

@coderuid: Are you interested in trying your hand at implementing this? The methods for the insert statement on are on lines 306-361 and the clauses for the insert statement are defined on lines 363-376. I think all that is necessary is:

  • Creating a 1-line defaultValues() method that sets this._default_values = true
  • Modifying the columns clause so it returns an empty string if this._default_values || !this._values
  • Modifying the values clause so it returns "DEFAULT VALUES" if this._default_values || !this._values

If you want to go above and beyond, you could add the new method to the documentation (index.html) and add a test (an example in the documentation, which will be converted into a test when you run tests/gen-tests.js and/or an explicit unit test in tests/tests.js).

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

No branches or pull requests

2 participants