Git Product home page Git Product logo

lem-mariadb's Introduction

lem-mariadb

About

lem-mariadb is a MariaDB/MySQL library for the Lua Event Machine. It allows you to query MariaDB and MySQL databases without blocking other coroutines. It works with all versions of MariaDB and MySQL servers, but it needs the MariaDB client library, as the MySQL client library does not have a non-blocking interface.

Installation

Get the source and do

make
make install

This installs the library under /usr/local/lib/lua/5.1/. Use

make PREFIX=<your custom path> install

to install to <your custom path>/lib/lua/5.1/.

Usage

Import the module using something like

local db = require 'lem.mariadb'

This sets db to a table with a single function.

  • db.connect{host=HOST, user=USER, passwd=PASSWORD, db=SCHEMA, port=PORT, socket=SOCKET_PATH)

    Connect to the database using the given parameters. If any parameter is omitted, a default is used. Returns a new database connection object on success, or otherwise nil followed by an error message (string) and error code (integer).

The metatable of database connection objects can be found under db.Connection. Prepared statements metatable (see below) is under db.PrepStmt.

Database connection objects has the following methods.

  • db:close()

    Close the database connection.

    Returns true on success or otherwise nil, 'already closed', if the connection was already closed.

  • db:exec(query)

    Execute an SQL query, and return the result as a Lua table with entries 1, 2, ... for each rows. Each row is again a Lua table with entries 1, 2, ... for each returned column. If there is no result set (eg. CREATE TABLE), the value true is returned instead of a Lua table.

    This method does not support placeholders (see db:prepare() / stmt:run() for that).

    In case of error, nil is returned followed by an error message and error code.

    If another coroutine is using this database connection the error message will be 'busy'. If the connection is closed the error message will be 'closed'.

  • db:prepare(query)

    prepares an SQL statement. Returns a new prepared statement object, or nil followed by an error message and error code in case of error.

    If another coroutine is using this database connection the error message will be 'busy'. If the connection is closed the error message will be 'closed'.

Prepared statement objects have the following method:

  • stmt:run(...)

    Executes the prepared statement with the given parameters. Each parameter is substituted for the corresponding placeholder '?' in the original SQL query that was prepared.

    The result is returned as a Lua table with entries 1, 2, ... for each rows. Each row is again a Lua table with entries 1, 2, ... for each returned column. If there is no result set (eg. CREATE TABLE), the value true is returned instead of a Lua table.

    In case of error, nil is returned followed by an error message and error code.

    If another coroutine is using this database connection the error message will be 'busy'. If the connection is closed the error message will be 'closed'.

License

lem-mariadb is free software. It is distributed under the terms of the GNU Lesser General Public License.

Contact

Kristian Nielsen [email protected]

lem-mariadb's People

Contributors

knielsen avatar esmil avatar

Stargazers

Jonathan McHugh avatar Richard Bensley avatar Markus Bergholz avatar BigJoe avatar

Watchers

 avatar James Cloos avatar BigJoe avatar  avatar

Forkers

esmil

lem-mariadb's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.