mysql

Functions:

create_table

mysql.create_table(table_name: string, columns: table): boolean

Name
Type
Description

table_name

string

Name of the table

columns

table

Definition of the table structure. A table containing column definitions, where each key is the column name and each value is the column type.

Creates a MySQL table. Returns false on failure.

MySQL Data Types

insert

mysql.insert(table_name: string, values: table[, callback: function(id)])

Name
Type
Description

table_name

string

Name of the table to insert into

values

table

A table containing column-value pairs to be inserted into the table.

callback

function

Optional. A callback function that receives the ID of the inserted row.

Inserts data into a table.

update

mysql.update(table_name: string, values: table, where: string, where_args: table[, callback: function(id)])

Name
Type
Description

table_name

string

Name of the table to insert into

values

table

A table containing column-value pairs to be inserted into the table.

where

string

A condition for the update (e.g., id = ?)

where_args

table

A table containing values to be used in the where condition.

callback

function

Optional. A callback function that receives the number of affected rows.

Updates data in a table.

query

mysql.update(table_name: string, columns: table[, where: string, where_args: table, callback: function(id)])

Name
Type
Description

table_name

string

Name of the table to insert into

columns

table

A table of column names to retrieve (default is * for all columns).

where

string

Optional. A condition for the query.

where_args

table

A table containing values to be used in the where condition.

callback

function

Optional. A callback function that receives a table of rows, where each row is represented as a table of column-value pairs.

Queries data from a table.

Example:

mysql.create_table("users", { 
    {"id", "INT PRIMARY KEY AUTO_INCREMENT"},
    {"username", "VARCHAR(255) NOT NULL"},
    {"password", "VARCHAR(255) NOT NULL"},
    {"email", "VARCHAR(255) UNIQUE"},
    {"created_at", "TIMESTAMP DEFAULT CURRENT_TIMESTAMP"},
    {"updated_at", "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"},
    {"is_active", "BOOLEAN DEFAULT TRUE"},
    {"last_login", "DATETIME"},
    {"user_role", "ENUM('admin', 'user', 'guest') DEFAULT 'user'"},
    {"balance", "DECIMAL(10, 2) DEFAULT 0.00"},
    {"size","INT"}
})

Last updated