Skip to content

Latest commit

History

65 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Are you tired of these lots of heavy database libraries which do a lot of things which you don't need? You came at the right place! This project aims to offer a way of writing a very simple code only one time and be able to switch between multiple database drivers without problems. The most easier and lightweight database abstraction of the market!

Alert: This project will not fill all the edge database cases and does not aim to do so.

Documentation

You can find the full library documentaion here.

Usage

Setup a database

Firstly you will need to setup your databases, sqlier can be initialized by running the initializer function sqlier.Initialize(name, drive, conn) which accepts the following arguments:

  1. STRINGname: Identification name for the database (can be anything)
  2. STRINGdriver: The desired database driver, currently supports:
  3. optional | STRINGConnection info: Only needed when using MySqloo driver, passing the database authentication details.
-- Sqlitesqlier.Initialize("db1", "sqlite")
-- MySQLsqlier.Initialize("db2", "mysqloo", { address="localhost", port="3306", database="GmodServer", user="root", password="" })

Setup a model

Now you will have to setup a model, it works like a class:

localUser=sqlier.Model({
Table="user",
Columns= {
Id= {
Type=sqlier.Type.Integer,
AutoIncrement=true
},
Name= {
Type=sqlier.Type.String
},
Rank= {
Type=sqlier.Type.String,
MaxLength=15
},
SteamId64= {
Type=sqlier.Type.SteamId64
},
CreateTimestamp= {
Type=sqlier.Type.Timestamp
}
},
Identity="Id"
})

The columns CreateTimestamp and UpdateTimestamp are hard-coded internally populated automatically.

Instantiate, update or delete a model

localnew_user=User({
Name=ply:Nick(),
SteamId=ply:SteamId64(),
Rank="user"
})
new_user:save()
new_user.Rank="donator"new_user:save()
new_user:delete()

If you want to know when a save or delete is done, you can pass a callback or use their async api, if using util.Promise:

new_user:save(function()
print("Save is done")
end)
util.PromiseAsync(function()
new_user:saveAsync():Await()
new_user:deleteAsync():Await()
end)

Querying

We have some simple methods to do querying:

-- The fastest way, get by identityUser:get(2, function(user)
end)
-- Find one by property filteringUser:find({ Name="ceifa" }, function(user)
end)
-- Get many by property filteringUser:filter({ Rank="donator" }, function(users)
end)

If you have support for util.Promise, you can use the async methods:

util.PromiseAsync(function()
localuser=User:getAsync(2):Await()
localuser=User:findAsync({ Name="ceifa" }):Await()
localusers=User:filterAsync({ Rank="donator" }):Await()
end)

But if you want more complex queries, you will have to do it yourself:

localuser_db=User:database()
ifuser_db.Driver=="sqlite" oruser_db.Driver=="mysqloo" thenuser_db:query("SELECT Name, COUNT(*) as Quantity FROM user GROUP BY Name", function(names)
end)
elseerror("Database driver not supported")
end

About

Yet another gmod database abstraction

Resources

Stars

34 stars

Watchers

3 watching

Forks

Releases

Packages

Contributors

Languages