Giter Club home page Giter Club logo

luaqub's Introduction

Lua Query Builder

LuaQuB is a small query builder module for Lua. I am building this because I'm tired of typing similar queries over and over as strings.

Requirements

The module will work perfectly with Lua v5.x

Usage

Save the LuaQuB.lua file (in root directory) to a folder listed under Lua's package.path or package.cpath variable. Call the module in your program by using require as follows:

local Builder = require "LuaQuB"

Create an object by using .new() method of Builder module. This object will be used for bulding the query.

local object = Builder.new()
object:select( "id, date, time, message, t2.col1, t2.col2" )
object:from( "tbl1, tbl2 AS t2" )
object:where( "tbl1.id = t2.remote_id" )
object:where( "LENGTH(message) < 255" )
object:limit( 30, 10 )		-- The second argument is offset

To get the compiled query in string format, just call tostring passing the object as parameter.

print( tostring(object) )

which will give you the following output

SELECT id,
	date,
	time,
	message,
	t2.col1,
	t2.col2
FROM tbl1,
	tbl2 AS t2
WHERE tbl1.id = t2.remote_id
	AND LENGTH(message) < 255
LIMIT 30
OFFSET 10

Building

LuaQuB can build queries for SELECT, UPDATE, INSERT and DELETE commands. The output is for MySQL. There is no plan on increasing support for other database engines.

Examples

Short examples for each of the four supported commands and their various variations have been added under the tests/ directory.

Not supported

The module does not check whether your input was properly escaped or not. It assumes that your input will be accordingly given.

luaqub's People

Contributors

hjpotter92 avatar th0rb 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.