lua-users home
lua-l archive

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


This is the library I have been working on. I probably should have written some better documentation and done more testing before releasing it, but for those that requested some sample code earlier, you should have no problem finding the interesting parts.

I have been using LuaSQL with my own patches and an abstraction layer (written in Lua) which resembles this library. It works quite well for my purposes, but it isn't quite release quality. For example, I had to integrated support for some non-privative data types that I use. This library has a mechanism for installing custom data type handlers without hacking the internals of the library.

Anyway, here is an example of a basic query using my library:

local stmt = conn:statement"SELECT a, b, c FROM t WHERE d > $1 AND e = $2"
stmt:setInteger(1, 1234)
stmt:setString(2, "abcd")
local rs, count = stmt:selectResultSet()

Which might return something like:

rs = {
   {a=7, b="word", c=true},
   {a=2, b="eofe", c=false},
   {a=5, b="sesg", c=false},
count = 23

Nothing revolutionary, but I find it much nicer than working with cursors and doing a bunch of string concatenations to write queries. Besides result set's you can also select individual results, individual fields and key-value pair tables. I included a slightly more detailed example with the source.

If there is any interest in this, I can post more about other features. Questions and comments are welcome.


Attachment: luapostgres-1.0.0.tar.bz2
Description: Binary data