Hey everyone!
I’m working on a Laravel-inspired QueryBuilder for FiveM, built using ox_lib and oxmysql. It’s meant to make working with databases in your scripts way easier, with stuff like models (haven’t started that yet), tables, and simple query methods—kind of like how Laravel does it.
Right now, it’s still super early and more of a showcase than anything. Things will probably break and change a lot as I keep working on it, but I wanted to share what I’ve got so far.
Feel free to check it out and drop any feedback or ideas!
Usage Examples
Here are some basic examples of how to use the query builder:
Complex Select Query
-- 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()
Basic Paginated Select Query
-- 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))
Basic Count Query
-- 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))
Basic Insert Query
-- 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"
})
Basic Update Query
-- Update user group
local affectedRows = DB:table("users")
:where("identifier", "char1:12345")
:update({
group = "moderator"
})
Basic Delete Query
-- Delete user by identifier
local affectedRows = DB:table("users")
:where("identifier", "char1:12345")
:delete()