Small and simple SQL builder.

Small and simple SQL builder.

Copyright 2012 Inaka <>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


condition() =
            {'and', [condition()]} |
            {'or', [condition()]} |
            {field(), term()}

field() = string() | atom()


s_count(TableName::string(), SelectFields::[field()], Conditions::condition(), ExtraWhere::string()) -> {iolist(), [term()]}

Returns number of results, useful for pagination.

s(TableName::string(), SelectFields::[field()], Conditions::condition(), ExtraWhere::string(), Page::non_neg_integer(), PageSize::non_neg_integer(), OrderBy::string()) -> {iolist(), [term()]}

Generic select function.

i(TableName::atom() | string(), Proplist::proplist() (see module proplists)) -> {iodata(), [term()]}


u(TableName::atom() | string(), UpdateFields::proplist() (see module proplists), Conditions::condition()) -> {iodata(), [term()], [term()]}


d(TableName::string(), Conditions::condition()) -> {iolist(), [term()]}


escape(Field::field()) -> string()

values_conditions(Expr::conditions() (see module sumo)) -> {[any()], conditions() (see module sumo)}

where_clause(Exprs::conditions() (see module sumo)) -> iodata()

where_clause(Exprs::conditions() (see module sumo), EscapeFun::function()) -> iodata()

where_clause(Exprs::conditions() (see module sumo), EscapeFun::function(), SlotFun::function()) -> iodata()

slot_question(X1::{'?', integer()}) -> string()

slot_numbered(X1::{'?', integer()}) -> iodata()

order_by_clause(SortFields::[{atom(), sort_order() (see module sumo)}]) -> iolist()

order_by_clause(SortFields::[{atom(), sort_order() (see module sumo)}], EscapeFun::function()) -> iolist()