Mercurial Hosting > luan
view src/luan/modules/sql/Sql.luan @ 1341:a015a0b5c388
add Html.decode(), Lucene.count_tokens(), lucene boosts, Sql.database.set()
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 19 Feb 2019 08:14:40 -0700 |
parents | 725e52076f03 |
children | 7d9a1f8894b0 |
line wrap: on
line source
java() local Luan = require "luan:Luan.luan" local error = Luan.error local new_error = Luan.new_error or error() local set_metatable = Luan.set_metatable or error() local Database = require "java:luan.modules.sql.Database" local Logging = require "luan:logging/Logging.luan" local logger = Logging.logger "Sql" local Sql = {} local mt = {} function mt.__gc(database) if not database.is_closed() then logger.error(database.created) database.close() end end function Sql.database(spec) local database = {} set_metatable(database,mt) local java_database = Database.new(spec) database.java = java_database database.created = new_error "not closed, created:" database.close = java_database.con.close database.is_closed = java_database.con.isClosed database.update = java_database.update database.set = java_database.set function database.query(sql,...) local rs = java_database.query(sql,...) local mt = {} function mt.__index(_,key) local rtn = rs.getObject(key) return not rs.wasNull() and rtn or nil end local result = {} set_metatable(result,mt) return function() if rs.isClosed() then return nil end if not rs.next() then rs.close() return nil end return result end end return database end return Sql