skeleton insert code
[dbsrgits/DBIx-Data-Store-old.git] / lib / DBIx / Data / Store / Command / Insert / LastInsertId.pm
diff --git a/lib/DBIx/Data/Store/Command/Insert/LastInsertId.pm b/lib/DBIx/Data/Store/Command/Insert/LastInsertId.pm
new file mode 100644 (file)
index 0000000..eb9d904
--- /dev/null
@@ -0,0 +1,27 @@
+package DBIx::Data::Store::Command::Insert::LastInsertId;
+
+use Moose;
+use Method::Signatures::Simple;
+
+has 'id_column' => (is => 'ro', required => 1);
+
+has 'insert_call_command' => (is => 'ro', required => 1);
+
+has 'raw_store' => (is => 'ro', required => 1);
+
+method execute {
+  $self->insert_call_command->execute;
+  return { $self->id_column => $self->_get_last_insert_id }
+};
+
+method _get_last_insert_id {
+  # this should probably involve some sort of call to the raw
+  # store to get the command object from it, but meh
+  $self->raw_store->connection->run(sub {
+    shift->last_insert_id((undef) x 4)
+  });
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;