Database initialization
To begin using Wise, the first thing you need is to establish a connection to a supported SQL database. Wise supports multiple backends (called providers), and setting it up is a single function call away.
ποΈ Basic usage
To initialize the database connection, use:
local database = wise.new(provider, credentials)
provider
β a string identifying the database backend (e.g."sqlite"
,"mysqloo"
,"tmysql4"
)credentials
β a table containing the necessary connection info
Providers
A provider is an interface between Wise and the actual database driver (e.g., mysqloo
or tmysql4
).
Currently, Wise supports three providers:
β
sqlite
Uses the built-in SQLite database included with Garry's Mod. No setup required, works out of the box. Great for local data or development.
local db = wise.new("sqlite", {})
β
mysqloo
Uses the mysqloo
binary module. Youβll need to install this on your server.
Ideal for remote SQL servers (e.g., MariaDB/MySQL) if you want persistence beyond SQLite.
local db = wise.new("mysqloo", {
host = "127.0.0.1",
user = "root",
pass = "root",
dbname = "gmod",
port = 3306
})
β
tmysql4
Uses the tmysql4
binary module, another MySQL-compatible driver.
Useful if you prefer tmysql4
over mysqloo
, or already use it in your project.
local db = wise.new("tmysql4", {
host = "127.0.0.1",
user = "root",
pass = "root",
dbname = "gmod",
port = 3306
})
π Credentials Table
The second argument to wise.new()
is a credentials table. Here's what it should contain (when using MySQL-based providers):
host
string
IP address or domain of the DB server
user
string
Username used to authenticate
pass
string
Password for the database user
dbname
string
Name of the database to connect to
port
number
(Optional) Port number (default: 3306)
Last updated