Database
The Database module provides a unified interface for database operations.
Server Functions
GetResourceName
Returns the name of the underlying database resource being used.
local resourceName = dBridge.Database.GetResourceName()| Returned Data | Type | Description |
|---|---|---|
resourceName | string | The name of the database resource (e.g., "oxmysql"). |
Select
Fetches multiple rows from the database.
local result = await dBridge.Database.Select('SELECT * FROM users WHERE job = ?', {'police'})| Argument | Type | Description |
|---|---|---|
query | string | SQL query to execute. |
parameters? | any[] | Parameters for the query. |
| Returned Data | Type | Description |
|---|---|---|
result | table | Array of rows returned by the query. |
Execute
Executes a query and returns the number of affected rows.
local affectedRows = await dBridge.Database.Execute('UPDATE users SET job = ? WHERE identifier = ?', {'unemployed', 'char1:12345'})| Argument | Type | Description |
|---|---|---|
query | string | SQL query to execute. |
parameters? | any[] | Parameters for the query. |
| Returned Data | Type | Description |
|---|---|---|
affectedRows | number | Number of rows affected by the query. |
Scalar
Fetches a single value from the database.
local count = await dBridge.Database.Scalar('SELECT COUNT(*) FROM users')| Argument | Type | Description |
|---|---|---|
query | string | SQL query to execute. |
parameters? | any[] | Parameters for the query. |
| Returned Data | Type | Description |
|---|---|---|
result | number | The single value returned by the query. |
Insert
Inserts a row and returns the insert ID.
local insertId = await dBridge.Database.Insert('INSERT INTO users (name, job) VALUES (?, ?)', {'John Doe', 'police'})| Argument | Type | Description |
|---|---|---|
query | string | SQL query to execute. |
parameters? | any[] | Parameters for the query. |
| Returned Data | Type | Description |
|---|---|---|
insertId | number | The ID of the inserted row. |
Update
Updates or deletes rows and returns the number of affected rows. Alias for Execute in some implementations.
local affectedRows = await dBridge.Database.Update('DELETE FROM users WHERE id = ?', {1})| Argument | Type | Description |
|---|---|---|
query | string | SQL query to execute. |
parameters? | any[] | Parameters for the query. |
| Returned Data | Type | Description |
|---|---|---|
affectedRows | number | Number of rows affected by the query. |
Transaction
Executes a batch of queries as a transaction.
local success = await dBridge.Database.Transaction({
'UPDATE users SET money = money - 100 WHERE id = 1',
'UPDATE users SET money = money + 100 WHERE id = 2'
})| Argument | Type | Description |
|---|---|---|
queries | string[] | List of SQL queries to execute. |
parameters? | any[] | Parameters for the queries (optional). |
| Returned Data | Type | Description |
|---|---|---|
success | boolean | Whether the transaction was successful. |
Was this page helpful?
Installation
To avoid any issues, please review everything and double-check that you've completed the following steps.
Framework
Universal framework compatibility layer that provides consistent access to player data, jobs, and framework-specific functions across various frameworks. This is the foundation module that enables cross-framework development.