Giter Club home page Giter Club logo

lua-resty-dao's Introduction

Name

lua-resty-dao Simple database dal library

Table of Contents

Status

This library is considered production ready.

Description

This Lua library is a simple database client that provides abstract access like mybtais and is easy to use

Synopsis

worker_processes 1;

error_log logs/error.log warn;

events { worker_connections 1024; }

http { lua_package_path '${prefix}src/?.lua;;';

init_worker_by_lua_file dao.lua;
server {
    listen   8000;
    location /test {
        content_by_lua_file test.lua
    }
}

}

Example use

to use the library, we first need database configurtion

Back to TOC

Build-in Methods

insert

syntax: res = mapper:insert(record_table, opt_table?)

Insert a new record, the first argument is key-value lua table where match for database table schema

An option Lua table can be specified as the last argument to this method to specify various connect options:

  • return_insert_id

    Specifies return primary id when the table have auto increment primary key

when return_insert_id is the method return primary id, or else it return affected rows

Back to TOC

update

syntax: ret = mapper:update(condition_table, newvalue_table)

Update to newvalue when condition is match

The first argument is key-value format table for query condition, second argument is table than hold key-value pair for new value

It return affected rows number

Back to TOC

select

syntax: res = mapper:select(condition_table?, output_fields_table?)

Select fields from db when condition is match

The first argument is key-value format table for query condition, second argument is array for mark output fields

When first argument is not specified, it means select all rows

When second argument is not spedified, it means output all fields

The method return an array of rows, the format is like

{ {key1=value1, key2=value2},

{key1=value1, key2=values}

}

Back to TOC

delete

syntax: res = mapper:delete(condition_table?)

The first argument is key-value format table for query condition, if not specified the behavior is delete all rows

It return affected rows number

Back to TOC

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.