StorageFunctions interface, making it easy to swap storage implementations or modify queries.
Architecture
The storage system is organized as follows:server/storage/players.lua and exported via server/storage/main.lua.
Storage Functions
The completeStorageFunctions interface is defined in types.lua:88.
Ban Management
insertBan
Create a new ban entry in the database.fetchBan
Retrieve ban information for a player.deleteBan
Remove a ban from the database.Player Data Management
upsertPlayerEntity
Create or update a player’s character data.ON DUPLICATE KEY UPDATE to handle both inserts and updates (server/storage/players.lua:96).
fetchPlayerEntity
Retrieve a character by citizen ID.fetchAllPlayerEntities
Get all characters belonging to a license.searchPlayerEntities
Search for players using filters.deletePlayer
Delete a character and all associated data.characterDataTables (server/storage/players.lua:231).
fetchPlayerSkin
Get the active skin for a character.Group Management
addPlayerToJob
Add or update a player’s job.ON DUPLICATE KEY UPDATE to handle existing jobs (server/storage/players.lua:278).
addPlayerToGang
Add or update a player’s gang.fetchPlayerGroups
Get all jobs and gangs for a player.removePlayerFromJob
Remove a job from a player.removePlayerFromGang
Remove a gang from a player.Unique ID Validation
fetchIsUnique
Check if a value is unique across all characters.citizenid- Character IDAccountNumber- Bank account numberPhoneNumber- Phone numberFingerId- Fingerprint IDWalletId- Wallet IDSerialNumber- Phone serial number
User Management
createUser
Create a new user entry.fetchUserByIdentifier
Get user ID from any identifier.Database Schema
users Table
players Table
Stores character data with JSON columns for:money- Cash, bank, crypto balancescharinfo- Character information (name, birthdate, etc.)job- Current job data (can be null)gang- Current gang data (can be null)position- Last known position (vec4)metadata- Character metadata (health, armor, etc.)
player_groups Table
Stores all jobs and gangs a player has access to:Maintenance Commands
convertjobs
Copies primary job/gang from players table to player_groups table.cleanplayergroups
Removes invalid groups that no longer exist in the configuration.Error Handling
The storage layer includes validation and error handling:Performance Considerations
- Uses prepared statements for all queries
- JSON columns indexed with
JSON_EXTRACTfor searches - Transaction support for multi-table deletes
- Async operations using
MySQL.*.await()pattern
Example: Custom Storage Implementation
You can replace the storage implementation by creating your own module:StorageFunctions type.