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 <petite_abeille@mac.com> 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
complete.

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"}
print(author{'name'})
book:link(author)
book:freeze()

local books = publisher:getAll("book", {orderby = "book.id 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:
http://github.com/golgote/frigo

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...


[1] http://apr.apache.org/docs/apr-util/trunk/group___a_p_r___util___d_b_d.html

-----
Bertrand Mansion
Mamasam