Skip to content

Multi-Insert Idea #17

@stanistan

Description

@stanistan

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions