Skip to content

Library Reference

Gabriel Francisco edited this page Jul 17, 2022 · 7 revisions

Functions

sqlier.Initialize

  1. string name: Identifier for the database
  2. string driver: Driver to be used, see drivers section
  3. optional table conninfo: Connection information, accepts the following:
    • string address: Host Address
    • string port: Port to connect with
    • string database: Database name
    • string user: User Name
    • string password: User Password

Examples

For Builtin SQLite

sqlier.Initialize("db_example", "sqlite")

For External MySQLoo

sqlier.Initialize("db_example", "mysqloo", {
    address = "127.0.0.1",
    port = "3306",
    database = "db_example_database",
    user = "username",
    pass = "pass"
})

sqlier.Model

returns: Model

  1. table modelstruct: Table that contains all the model information
    • string Table: Table to store the Model information in
    • string optional Database: Database identifier for the model to be created in
    • string Identity: Keyname of the Primary key for the model
    • table Columns: Contains the columns of the Model, each column entry contains these methods:
      • type Type: Type of the column
      • any Default: Default value
      • any OptionalArgs: These are optional, type specific arguments

Examples

Example Model

local User = 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"
})

Usage of the previous model

local new_user = User({
    Name = ply:Nick(),
    SteamId = ply:SteamId64(),
    Rank = "user"
})
new_user:save()

new_user.Rank = "donator"
new_user:save()

Tables

sqlier.Database

List of all databases, created with sqlier.Initialize

sqlier.Logger

Contains one method, log(string prefix, string log, number severity), which prints out the information passed to it.

sqlier.ModelBase

Is the metatable of all Models

sqlier.InstanceBase

Is the metatable of all ModelInstances

Types

All the following are stored in the table sqlier.Type

String

Special Parameters:

  • MaxLength: Defines the max length of the string (VARCHAR(MaxLength))

Integer

Special Parameters:

  • AutoIncrement: Tells SQL to automatically increment this based on the current amount (AUTOINCREMENT or AUTO_INCREMENT)

Float

No Special Parameters

SteamId64

(Identical to String except a max of 17 chars) No Special Parameters

Bool

No Special Parameters

Date

No Special Parameters

DateTime

No Special Parameters

Timestamp

No Special Parameters