Weed3 一個(gè)微型ORM框架(只有0.1Mb哦)
源碼:https://github.com/noear/weed3
源碼:https://gitee.com/noear/weed3
weed3提供了字段和對(duì)象格式化支持,通過(guò)DbContext進(jìn)行設(shè)定
//以mysql為例
DbContext db = new DbContext(...).fieldFormatSet("`%`")//設(shè)定字段格式符
.objectFormatSet("`%`");//設(shè)定對(duì)象格式符
//%號(hào)為占位符,`%`表過(guò)你的字段會(huì)轉(zhuǎn)為:`字段名`
字段格式符對(duì)會(huì)對(duì):
.set(..), .select(..), .orderBy(..), .groupBy(..) 里的字段進(jìn)行處理
對(duì)對(duì)象格式符對(duì)會(huì):
.table(..), innerJoin(..), leftJoin(..), rightJoin(..) 里的表名進(jìn)行處理
如果不設(shè)置,則需要自己手動(dòng)處理關(guān)鍵字;手動(dòng)處理與自動(dòng)處理并不沖突。
//手動(dòng)處理
db.table("`user`").where("`count`<10 AND sex=1").count();
格式化是由IDbFormater來(lái)處理的,如果覺(jué)得里面的實(shí)現(xiàn)不好,還可以自己寫(xiě)一個(gè)替換它:)
IDbFormater df = new DfNew(); //DfNew 算是自己寫(xiě)的
db.formaterSet(df); //搞定
//附:
public interface IDbFormater {
/** 字段格式符設(shè)置 */
void fieldFormatSet(String format);
/** 對(duì)象格式符設(shè)置 */
void objectFormatSet(String format);
/** 格式化字段(用于:set(..,v)) */
String formatField(String name);
/** 格式化多列(用于:select(..) orderBy(..) groupBy(..)) */
String formatColumns(String columns);
/** 格式化條件(用于:where(..) and(..) or(..)) */
String formatCondition(String condition);
/** 格式化對(duì)象(用于:from(..), join(..)) */
String formatObject(String name);
}