Skip to content

Zerio-AB/sql_orm

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FiveM QueryBuilder

A Laravel-inspired QueryBuilder for FiveM, built on top of ox_lib and oxmysql.

Fork Notice

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.

Dependencies

  • oxmysql

Credits

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.

Installation

  • Under construction, please DO NOT use this yet. 🚧

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()

About

A Laravel-inspired QueryBuilder for FiveM, built on top of ox_lib and oxmysql.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Lua 100.0%