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

Multi-Insert Idea #17

Open
stanistan opened this issue Jan 9, 2012 · 1 comment
Open

Multi-Insert Idea #17

stanistan opened this issue Jan 9, 2012 · 1 comment

Comments

@stanistan
Copy link
Contributor

Right now, we have this insert structure:

<?php 
aql::insert($table_name, $field_value_pairs);

And no way to quickly insert multiple records quickly, the only way is to loop through an array of fields and run an individual aql::insert, which also does a select to return the inserted row.

Proposal

<?php
$table_name = 'artist';

$fields = array(
    array(
        'name' => 'Pink Floyd'
    ),
    array(
        'name' => 'Metallica',
        'year_started' => 'Not sure'
    ),
    array(
        'name' => 'Sleepytime Gorilla Museum',
        'genre' => 'weird' // not actual genre schema, 
    ),
    array(
        'name' => 'Radiohead'
    ),
    // etc
);

aql::multi_insert($table_name, $fields);

This would figure out the minimum number of insert queries for field-data pairs given and insert them in a transaction. If all of the fields are the same, then this would be minimized to one query which would be much faster than the current alternative.

If aql::insert() contains a multi-dimensional array, multi_insert() would be used instead.

Note: this would not return an array of rows inserted.

@zgr024
Copy link
Contributor

zgr024 commented Jan 9, 2012

multi_insert() should return an array of inserted id's

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