Giter Site home page Giter Site logo

lua-postgres's Introduction

Lua Postgres

A Postgres library for Lua. Other than the basic connection and query execution functionality you would expect in any database driver, it also supports automatic query parameter escaping via libpq, meta information about tables and result sets. Support for asynchronous queries is planned but not yet implemented.

I'm doing this in part because I need it, and in part to learn more about C programming. My total experience with C is reading K&R, and about 3 weeks of practice. Use this library at your own risk! That said, my need for this library grew out of frustrations with memory leaks, bugs and lack of maintainence with other existing Lua Postgres libraries, and so I've been fairly diligent about testing and keeping the code small and simple to read. Any bugs will likely be easy for an experienced C programmer to spot.

Why?

LuaSQL is OK, but the fact that it's an abstraction library means that by design, it will not support some of Postgres's useful vendor-specific features, like asynchronous queries, array and hash types, etc.

Other Postgres drivers I found for Lua were woefully buggy, incomplete, and abandoned, so I've decided to work on this one.

My goal is to create a solid, general-purpose but Postgres-specific library that exposes the most useful features of Postgres in a clean, Lua-idiomatic way rather than just a direct translation of libpq to Lua.

Compatibility

  • Lua 5.1 and 5.2
  • Verified working on Linux and OS X. Should work fine on *BSD but not yet tested.
  • Windows (probably, but not tested. Please let me know if you have problems.)

Example code

local postgres = require "postgres"
local conn, err = postgres.connection("dbname: my_database")
if err then error(err) end

local function emit(query)
  local result, err = conn:execute(query)
  if not result then error(err) end
  return result
end

emit "DROP TABLE IF EXISTS people"
emit "CREATE TABLE people(id SERIAL NOT NULL PRIMARY KEY, name VARCHAR(255))"
emit "insert into people (name) values ('Joe Schmoe')"
emit "insert into people (name) values ('John Doe')"
emit "insert into people (name) values ('Jim Beam')"

print(conn:execute("SELECT * FROM people WHERE id IN ($1)", "1,2,3"))

Acknowledgements

Some ideas and bits of code in this library are taken from Lua-Pgsql and Luapgsql, as well as LuaSQL.

Where to get it

http://github.com/norman/lua-postgres

License

MIT/X11

lua-postgres's People

Contributors

norman avatar

Watchers

James Cloos avatar  avatar

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.