Repository navigation
The ORM
imshooter edited this page Nov 29, 2026
·
1 revision
An ORM maps a row of a table to variables of the script. One variable is the key that finds the row.
new
MySQL:gDatabase,
ORM:gPlayerOrm[MAX_PLAYERS],
gPlayerId[MAX_PLAYERS],
gPlayerName[MAX_PLAYERS][MAX_PLAYER_NAME + 1],
gPlayerMoney[MAX_PLAYERS],
Float:gPlayerHealth[MAX_PLAYERS]
;
forward OnPlayerLoaded(playerid);
stock LoadPlayer(playerid) {
new const
ORM:orm = orm_create("players", gDatabase)
;
orm_addvar_int(orm, gPlayerId[playerid], "id");
orm_addvar_string(orm, gPlayerName[playerid], MAX_PLAYER_NAME + 1, "name");
orm_addvar_int(orm, gPlayerMoney[playerid], "money");
orm_addvar_float(orm, gPlayerHealth[playerid], "health");
orm_setkey(orm, "name");
GetPlayerName(playerid, gPlayerName[playerid], MAX_PLAYER_NAME + 1);
gPlayerOrm[playerid] = orm;
orm_select(orm, "OnPlayerLoaded", "i", playerid);
}
public OnPlayerLoaded(playerid) {
if (orm_errno(gPlayerOrm[playerid]) == ERROR_NO_DATA) {
orm_insert(gPlayerOrm[playerid]);
}
return 1;
}| Native | Query |
|---|---|
| orm_select | reads the row with the key into the variables |
| orm_update | writes the variables into the row with the key |
| orm_insert | inserts the variables, and sets an integer key to the new AUTO_INCREMENT value |
| orm_delete | deletes the row with the key |
| orm_save | updates when the key is set, inserts when it is 0 or empty |
orm_errno tells whether the last select found a row. orm_apply_cache writes a row of the active cache into the variables by the names of their fields. The variables must outlive the ORM.
mysql 0.6.0 · Repository · Releases · MIT License
Guides
- Installation
- Configuration
- Queries
- The cache
- JSON cells
- Prepared statements
- Transactions
- The ORM
- Passwords
- Errors
- TLS
- Coming from another plugin
- Performance
Reference
Functions
Connections
Queries
Cache
- cache_get_row_count
- cache_get_field_count
- cache_get_result_count
- cache_get_field_name
- cache_get_field_type
- cache_get_field_index
- cache_set_result
- cache_get_value_index
- cache_get_value_index_int
- cache_get_value_index_float
- cache_get_value_index_bool
- cache_is_value_index_null
- cache_get_value_name
- cache_get_value_name_int
- cache_get_value_name_float
- cache_get_value_name_bool
- cache_is_value_name_null
- cache_get_row
- cache_save
- cache_delete
- cache_set_active
- cache_unset_active
- cache_is_any_active
- cache_is_valid
- cache_affected_rows
- cache_insert_id
- cache_warning_count
- cache_get_query_exec_time
- cache_get_query_string
- cache_get_errno