-
-
Save anonymous/863806a7968924630f54ee5999d284af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- The point of this script is to block the main thread until a query has finished. | |
-- It does not work and will crash your server. | |
local co = coroutine.create(function () | |
require("mysqloo") | |
local db = mysqloo.connect("hostname", "database", "password", "table") | |
function db:onConnectionFailed(err) | |
print("Database connection error: ", err) | |
end | |
function db:onConnected() | |
print("Database connection established.") | |
end | |
print("Connecting to database...") | |
db:connect() | |
db:wait() -- halt until connected | |
local query = db:query("SELECT version()") | |
query:start() | |
while query:status() ~= mysqloo.QUERY_COMPLETE do | |
coroutine.yield() | |
end | |
coroutine.yield(query:getData()) | |
end) | |
while coroutine.status(co) ~= "dead" do | |
local err, data = coroutine.resume(co) | |
if arg ~= nil then PrintTable(data) end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment