Skip to content

A modular SQL interface and wrapper for Garry's Mod.

Notifications You must be signed in to change notification settings

KragleStudios/ezdb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 

Repository files navigation

ezdb

A modular SQL interface and wrapper for Garry's Mod. Copy the addon's lua/bin to your server's lua/bin

Supports the following modules

Example

Replace the module string with any of the modules above.

hook.Add("InitPostEntity", "LoadDatabase", function()	
	local database = ezdb.create(
	{
		host 		= 	"localhost",
		username 	= 	"root",
		password 	= 	"",
		database 	= 	"serverguard",
		module 		= 	"tmysql4"
	})
	
	function database:onConnected()
		print("Connected to the database.")
	end

	function database:onConnectionFailed(err)
		ErrorNoHalt(err.."\n")
	end

	database:connect()
end)

You can execute raw queries or build them with the provided wrapper. For example, the following queries are identical.

database:query("SELECT * FROM users WHERE rank = 'user' LIMIT 1;", function(result)
	PrintTable(result)
end, ezdb.error)
local query = database:select("users")
	query:where("rank", "user")
	query:limit(1)
	query:callback(function(result)
		PrintTable(result)
	end)
query:execute()

The wrapper can also be used in-line, which allows for short and expressive queries to be executed in a single line. The following example would set every user's money to 0 if they have $5,000 or more.

database:update("users"):update("money", 0):whereGTE("money", 5000):execute()

All input using the wrapper is automatically escaped.

About

A modular SQL interface and wrapper for Garry's Mod.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages