database icon indicating copy to clipboard operation
database copied to clipboard

Hints for new features for INSERT

Open pine3ree opened this issue 5 years ago • 3 comments

Hello @wolfy-j ,

just a simple suggestion as it's a feature I implemented many times:

  • add IGNORE for INSERT (just need a boolean like SelectQuery::distinct)
  • add the ability to compile this type of query INSERT INTO table (username, email) SELECT username, email FROM other_table WHERE.... with a new method InsertQuery::select(SelectQuery $select) and building the last part of the INSERT statement with the compiled SELECT statement.

kind regards, maks

unrelated
  • You can use self as a return type for any public function fluentMethod(): self
  • In php-do blocks it's usually better to use @return $this if the return value is the same instance (and not for instance a clone)

pine3ree avatar May 01 '20 01:05 pine3ree

All accepted. Injecting SELECT into INSERT is not a problem, we already have such capability on VALUE level.

We will implement this feature somewhere in a future milestone.

wolfy-j avatar May 01 '20 10:05 wolfy-j

Hello @wolfy-j ,

All accepted. Injecting SELECT into INSERT is not a problem, we already have such capability on VALUE level.

but the compiler have this hardcoded string format: 'INSERT INTO %s (%s) VALUES %s',

we need a more flexible format (like selectQuery) to allow: INSERT{ IGNORE} INTO table{ column_list(...)} {VALUES source_values(...)|SELECT FROM...}

  • the column_list(...) fragment should be optional, even in not INSERT...SELECT statements
  • the last part should allow both (mutually excluding) VALUES and SELECT statements

kind regards

pine3ree avatar May 01 '20 19:05 pine3ree

Hi, I meant to say that your suggestion was accepted :) It's pretty easy to change the compiler since all the tokens are isolated.

I would appreciate any PR, if not - this feature will be revised in future releases.

wolfy-j avatar May 02 '20 14:05 wolfy-j