Gluttony:Model無需任何處理,即可使用的,超方便Android ORM 數據庫框架

說是ORM框架,其實更該說是Android 數據庫領域的 DSL 語言。(領域特定語言)
所以用起來自然超簡約。

不多說了,Github地址:https://github.com/senyuyuan/Gluttony
文檔如下:

Gluttony · 饕餮

Gluttony, a super convenient and simple library to using Android database

饕餮,高效而簡約地使用Android數據庫

Library is compatible with Kotlin 1.0.5-2 build.

饕餮 兼容 kotlin 1.0.5-2 版本(最新版)

Content · 目錄

  • Feature · 特性
  • Install · 安裝
  • How to use · 如何使用
    • Configuration · 配置
    • Entities · 實體
    • Save · 保存
    • Find · 查詢
    • Update · 更新
    • Delete · 刪除
    • Condition · 條件

Feature · 特性

* The core concept, friendly to human, Gluttony will give you the perfect experience
* 核心理念,對人類友好,Gluttony將會給您完美的使用體驗
* Automatic table and column naming through reflection
* 通過反射自動建表
* Entities do not need any processing
* 實體類無需任何處理
* The future will provide two kinds of the kernel for your choice, 
  【sqlite】 and 【realm】, the performance of the pursuit of perfection
* 未來將會提供兩種內核供您選擇,【sqlite】以及【realm】,追求極致的性能

Install · 安裝

as a gradle dependency

作為一個gradle依賴庫

    compile 'sen.yuan.dao:gluttony:1.1'

How to use · 如何使用

Configuration · 配置

        //configure databaseName,cursorFactory,databaseVersion 
        //配置 數據庫名稱,cursorFactory,數據庫版本
        Gluttony.init(this, GluttonyConfig("gluttony_example",null,1))

In Application or the first Activity, initialize Gluttony.

在Application或是首個Activity中,初始化Gluttony·饕餮。

Entities · 實體

Entities do not need to do any processing.

實體類無需做任何處理。

Gluttony automatically for you to take care of everything.

Gluttony·饕餮 在數據庫中自動為您打理好一切。

Annotation: @PrimaryKey is used to specify a PrimaryKey.

注解:@PrimaryKey 用來指定主鍵。

data class UserData(
        @PrimaryKey
        var id: Int = -1,
        var name: String = "",
        var age: Int = -1,
        var isChildren: Boolean = false
)

Save · 保存

Save Entity directly · 直接保存實體

        val user = UserData()
        user.id = 666
        user.name = "sen"
        user.age = 23
        user.isChildren = false
        user.save()

        //or
        UserData(2, "john", 12, true).save()

Find · 查詢

Find Entity based on PrimaryKey · 根據primary key 查詢數據

        val user1 = UserData().findOneByKey(666)

Find the first Entity based on Condition · 根據條件 查詢第一個數據

        val user2 = UserData().findOne {
            condition {
                "age" between 7..16
                "isChild" Not false
            }
            orderBy("age", SqlOrderDirection.ASC)
        }

Find all Entities based on Condition · 根據條件 查詢所有數據,返回值為一個列表

        val userList = UserData().findAll {
            condition {
                "age" moreThan 11
                "name" like "s%"    //find names witch is starting with "s"
            }
        }

Update · 更新

Update Entity directly base on PrimaryKey · 根據primary key 直接更新實體

    var user3 = UserData().findOne { condition { "name" equalsData "lucy" } }!!
        user3.age += 1
        user3.update()
        
        //or
        
        var user4 = UserData(7, "lucy", 10, true)   //user4.id == user3.id · 注意primary key相同
        user4.update()  //user4 will overwrite the old data · 將會覆蓋掉舊數據

Update Entity directly or Save Entity when it doesn't exist · 直接 更新或保存實體 (如果實體是未保存過的話)

        var user5 = UserData(90, "white", 77, false)    // 90 is a new primary key
        user5.updateOrSave()    // Gluttony will save a new data

Update Entity based on PrimaryKey · 根據primary key 更新實體

    //update user who id is 90 to named black,age 80
    //lambda
        UserData().updateByKey(90) { arrayOf("name" to "black", "age" to 80) }

        //or pairs
        UserData().updateByKey(90, "name" to "green", "age" to 82)

Update all Entities based on Condition · 根據條件 更新所有實體

    //update user who name is green to name red,age 99
        UserData().update("name" to "red", "age" to 99) {
            condition {
                "name" equalsData "green"
            }
        }

Delete · 刪除

Delete Entity directly · 直接刪除實體

        var user9 = UserData(90)    //only need primary key
        user9.delete()

Delete Entity based on PrimaryKey · 根據primary key 刪除實體

        UserData().deleteByKey(666) //delete user which id is 666

Delete all Entities based on Condition · 根據條件 刪除所有實體

    //delete users who is child
        UserData().delete {
            condition {
                "isChild" equalsData true
            }
        }

Clear one Class's entities · 清空一個類的所有實體

        UserData().clear()

Condition · 條件

  • equalsData · 等于

  • moreThan · 大于

  • moreThanOrEquals · 大于等于

  • lessThan · 小于

  • lessThanOrEquals · 小于等于

  • Not · 非

  • In: Determine whether in the array · 判斷是否在數組中

  • notIn: Determine whether not in the array

  • between: Determine whether in the range

  • like: fuzzy query · 模糊查詢


two marks: % and _ · 兩個通配符:% 和 _

% : indefinite amount content · 不定數量的內容

_ : one amount content · 一個位置的內容

for example:    "gluttony%" -> find values witch is starting with "gluttony"

例如,"gluttony%" -> 查詢所有以"gluttony"開頭的數據

Welcome to staring the project, thanks!
歡迎關注(star)本項目,O(∩_∩)O謝謝!

QQ群:176275050

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 230,048評論 6 542
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 99,414評論 3 429
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 178,169評論 0 383
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 63,722評論 1 317
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 72,465評論 6 412
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 55,823評論 1 328
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,813評論 3 446
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 43,000評論 0 290
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 49,554評論 1 335
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 41,295評論 3 358
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 43,513評論 1 374
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 39,035評論 5 363
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,722評論 3 348
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 35,125評論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 36,430評論 1 295
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 52,237評論 3 398
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 48,482評論 2 379

推薦閱讀更多精彩內容