brianc/node-sql — pull request #112 by kevinoid (2013-06-25 16:54:50+00:00)
Title: Add support for INSERT with SELECT

This pull request adds support for INSERT statements which insert the result of a query, as discussed in issue #111.

The changes are pretty self-explanatory with a few notable caveats that should be considered:

1. There is some ambiguity of the user intent when insert is called without any values. Since we don't know at the point of call whether `.select()` will be called subsequently. Although the resolution could be deferred, it adds some code complication, so instead I used the heuristic that if any columns are specified it is assumed that a SELECT will follow. This seems pretty reasonable to me, although it does change the behavior of `table.insert(col1, col2)` for users who were previously depending on that statement to add a row of default values.

2. Previously `Column.value()` would mutate the `Column`. This makes inserting a query result more difficult since the user must set the value of the column back to `undefined` to avoid inserting the previously set value. This pull request changes the behavior so that `Column.value()` returns a clone of the `Column` rather than mutating the `Column` in-place. But, again, there is potential for user breakage.

Let me know what you think.