lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Wed, Jan 21, 2009 at 7:04 PM, Petite Abeille <> wrote:
> On Jan 21, 2009, at 4:56 PM, Bertrand Mansion wrote:
>> I am writing a wrapper to make working with LuaSQL more efficient.
> Out of curiosity, what part of LuaSQL do you find inefficient to work with?
> The library itself? SQL in general? Or?

I like SQL, I wouldn't want to write some kind of query builder, I
prefer to use SQL directly. I think LuaSQL is ok even if I would
really like to see a Lua extension for apr_dbd [1] which is more

In my project, I have written the following functions :
- emulated prepare/execute
- select query limits (limit, offset)
- utility functions for fetchOne (returns the first value of the first
row), fetchRow (returns the first row), fetchCol (returns the
designated column), fetchAssoc (returns an associative table),
fetchAll (returns everything in a table)
- identifier escaping ( mysql: `group`, sqlite: "group", etc)
- start/commit/rollback a transaction

Then on top of this I have written a simple "ORM". At the moment, you
can do things like:
book = con:factory('book')
book{title = "Tschai"}
author = con:factory('author'}
author{name = "Jack Vance"}

local books = publisher:getAll("book", {orderby = " ASC"})
local author = con:findOne("author", {where = "name LIKE ?"}, "Jack Vance")
local authors = con:find("SELECT {author} FROM author WHERE name LIKE
?", "Jack%")

...and a lot of other cool things that makes it easier for me to use
LuaSQL and write less SQL for common tasks.

The current code is here:

but I am now thinking about changing a few things (I am not too happy
with the API) and I have to finish implementing other features and
write documentation...


Bertrand Mansion