rockdai / sql-bricks

Transparent, Schemaless SQL Generation
http://csnw.github.io/sql-bricks
MIT License
213 stars 25 forks source link

Need for 'INSERT INTO TableName DEFAULT VALUES ' #87

Open coderuid opened 8 years ago

coderuid commented 8 years ago

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

prust commented 8 years ago

@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:

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).