A Laravel-inspired QueryBuilder for FiveM, built on top of ox_lib and oxmysql.
This is just a fork, the original repo was built by @tomiichx.
I've made personal changes to make this fit my own use case better, as I'd like to use this as a git submodule in my own scripts (instead of requiring this to be an dependency on the users server). We also removed the requirement of ox_lib, as it was anyways barely being used.
- oxmysql
This resource is built on top of oxmysql for database handling and ox_lib for miscellaneous utility functions. Huge thanks to the Overextended team for their contributions to the FiveM ecosystem.
- Under construction, please DO NOT use this yet. 🚧
Here are some basic examples of how to use the query builder:
-- Retrieve a list of users filtered by group, grouped by identifier, ordered by lastname, and limited to 10 results
local users = DB:table("users")
:select("identifier", "firstname", "lastname")
:where("group", "LIKE", "%admin")
:groupBy("identifier")
:orderBy("lastname", "ASC")
:limit(10)
:get()-- Get paginated results by specifying perPage and currentPage
local entriesPerPage = 10
local currentPage = 1
local obj = DB:table("users")
:select("firstname", "lastname")
:paginate(entriesPerPage, currentPage)
print(("Returned %d out of %d"):format(entriesPerPage, obj.totalCount))-- Count the number of users active in the last hour
local count = DB:table("users")
:where("last_seen", ">", os.time() - 3600)
:count()
print(("Count: %d"):format(count))-- Insert a new user record
local insertId = DB:table("users"):insert({
identifier = "char1:12345",
firstname = "John",
lastname = "Doe",
accounts = { bank = 100, cash = 0, black_money = 0 }, -- Automatically parsed as JSON string
group = "admin"
})-- Update user group
local affectedRows = DB:table("users")
:where("identifier", "char1:12345")
:update({
group = "moderator"
})-- Delete user by identifier
local affectedRows = DB:table("users")
:where("identifier", "char1:12345")
:delete()