nut.db.getInsertID - brianhang/nutscript2 GitHub Wiki
Description
index = nut.db.getInsertID()
This server function returns the last index encountered from an insert query.
Returns
| Name | Description |
|---|---|
index |
The index of the last inserted row. If there were no insertions, then nil is returned. |
Example
-- Assuming SQLite database is being used.
local QUERY_CREATE_BOX = [[
CREATE TABLE boxes (
x INTEGER PRIMARY KEY,
y INTEGER
);
]]
-- Create the boxes table.
nut.db.query(QUERY_CREATE_BOX, function()
-- Insert a box.
nut.db.query("INSERT INTO boxes (y) VALUES (123)", function(status, result)
if (status) then
print("Inserted box #"..nut.db.getInsertID())
end
end)
end)