st.database — MySQL Helpers (Server)
Requires oxmysql. Load the database module:
lua
st_lib 'database'lua
-- Create a table if it doesn't exist
-- Returns true if created, false if already existed
st.database.addTable('my_table', [[
id INT AUTO_INCREMENT PRIMARY KEY,
identifier VARCHAR(64) NOT NULL,
data JSON,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
]])
-- Add a column to an existing table (idempotent)
st.database.addColumn('my_table', 'new_column', 'INT DEFAULT 0')
-- Add a trigger (idempotent)
st.database.addTrigger('my_trigger', [[
AFTER INSERT ON my_table FOR EACH ROW
BEGIN
-- trigger body
END
]])All operations are await-based and safe to call on resource start.