Giter Site home page Giter Site logo

maku_sqlorm's Introduction

FiveM SQL ORM

Simple lua sql ORM for FiveM

Usage

First of all, you have to choose if you want to create a repository by export, or if you want to have the file added in the manifest of your script. If you choose adding to manifest file, add @maku_sqlorm/server/sv-parser.lua file to server scripts

Creating repository

Each repository is created using a function and annotation. For annotations, you choose a table name for @entity type and then columns with data type, name, and additional sql lang data for the @column types. If we chosed export way before, we use exports.maku_sqlorm:createRepository, if adding to the manifest, we skip the export call for orm script. The first argument for createRepository must be the path to the repository file so that the parser can retrieve the data from annotations.

--- @entity players
--- @column id number NOT NULL AUTO_INCREMENT
--- @column nick string NOT NULL
--- @column money number NOT NULL DEFAULT '0'
--- @primaryKey id
local function createPlayersRepository()
    return exports.maku_sqlorm:createRepository('example/players.lua') -- Using export case
    return createRepository('example/players.lua', GetCurrentResourceName()) -- Including file in manifest case
end

Then we call function and define a variable.

PlayersRepository = createPlayersRepository()

Now we have created a repository object and can use its functions. A list of all functions can be found below

Repository functions

Main

local object = Repository:find(column, value)
Repository:findAsync(column, value, callback)

object:save()
local objects = Repository:findAll()
Repository:findAllAsync(callback)
local object = Repository:createEntity(data)
object:save()

When the save or saveAsync function is called on object, the object in the database is updated or, if it does not have a defined primary key, it is created.

Other

Repository:insert(data)
Repository:insertAsync(data, callback)

Repository:update(data)
Repository:updateAsync(data, callback)

Repository:delete(id)
Repository:deleteAsync(id, callback)

Great example can be found there.

Dependencies

maku_sqlorm's People

Watchers

 avatar

Forkers

marvisak

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.