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

Feature: Switch Query Builder insert method to use raw SQL and support multi-row inserts #3

Open
JasonTheAdams opened this issue Sep 28, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@JasonTheAdams
Copy link

Currently the Query Builder user wpdb::insert() under the hood to run the insert. This is lame for a couple reasons:

  1. You can't really do anything particularly complex as we're limited to what that function supports
  2. For example, you can only insert a single row at a time... Have 20 rows to insert? Too bad. Do it 20 times. 😭

Let's just ditch wpdb and build the SQL ourselves. We don't need them! I think as a good first step the following should be possible:

DB::table('post_meta')
	->insert([
		['post_id' => 1, 'meta_key' => 'foo', 'meta_value' => 'bar'],
		['post_id' => 1, 'meta_key' => 'foo2', 'meta_value' => 'bar2'],
		['post_id' => 1, 'meta_key' => 'foo3', 'meta_value' => 'bar3'],
	]);

Currently the insert signature contains a $format parameter. I'm inclined to just drop that and infer from the value type what it should be: strings should be strings, numbers should be numbers, and so forth. Crazy stuff! Dropping the last parameter shouldn't break anything since passing additional parameters in PHP doesn't throw an error.

@JasonTheAdams JasonTheAdams added the enhancement New feature or request label Sep 28, 2022
@borkweb borkweb changed the title Feature: Switch Query Builder update method to use raw SQL and support multi-row inserts Feature: Switch Query Builder insert method to use raw SQL and support multi-row inserts Sep 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant