Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zhaoyufei133
litepal
提交
be4811b2
L
litepal
项目概览
zhaoyufei133
/
litepal
与 Fork 源项目一致
从无法访问的项目Fork
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
litepal
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
be4811b2
编写于
6月 01, 2020
作者:
郭
郭霖
提交者:
GitHub
6月 01, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Release 3.1.0 version.
上级
fbee8590
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
31 addition
and
85 deletion
+31
-85
README.md
README.md
+31
-85
未找到文件。
README.md
浏览文件 @
be4811b2
...
...
@@ -20,17 +20,9 @@ Experience the magic right now and have fun!
Edit your
**build.gradle**
file and add below dependency.
If you program with Java:
```
groovy
dependencies
{
implementation
'org.litepal.android:java:3.0.0'
}
```
If you program with Kotlin:
```
groovy
dependencies
{
implementation
'org.litepal.android:kotlin:3.0.0'
implementation
'org.litepal.guolindev:core:3.1.0'
}
```
...
...
@@ -141,8 +133,6 @@ public class Album extends LitePalSupport {
private
float
price
;
private
byte
[]
cover
;
private
List
<
Song
>
songs
=
new
ArrayList
<
Song
>();
// generated getters and setters.
...
...
@@ -182,8 +172,7 @@ Now the tables will be generated automatically with SQLs like this:
CREATE
TABLE
album
(
id
integer
primary
key
autoincrement
,
name
text
unique
default
'unknown'
,
price
real
,
cover
blob
price
real
);
CREATE
TABLE
song
(
...
...
@@ -205,8 +194,6 @@ public class Album extends LitePalSupport {
@Column
(
ignore
=
true
)
private
float
price
;
private
byte
[]
cover
;
private
Date
releaseDate
;
private
List
<
Song
>
songs
=
new
ArrayList
<
Song
>();
...
...
@@ -391,64 +378,7 @@ Kotlin:
val
songs
=
LitePal
.
where
(
"name like ? and duration < ?"
,
"song%"
,
"200"
).
order
(
"duration"
).
find
<
Song
>()
```
#### 7. Async operations
Every database operation is on main thread by default. If your operation might spent a long time,
for example saving or querying tons of records. You may want to use async operations.
LitePal support async operations on all crud methods. If you want to find all records from song table
on a background thread, use codes like this.
Java:
```
java
LitePal
.
findAllAsync
(
Song
.
class
).
listen
(
new
FindMultiCallback
<
Song
>()
{
@Override
public
void
onFinish
(
List
<
Song
>
allSongs
)
{
}
});
```
Kotlin:
```
kotlin
LitePal
.
findAsync
<
Song
>().
listen
{
allSongs
->
}
```
Just use
**findAllAsync()**
instead of
**findAll()**
, and append a
**listen()**
method, the finding result will
be callback to
**onFinish()**
method once it finished.
Abd saving asynchronously is quite the same.
Java:
```
java
Album
album
=
new
Album
();
album
.
setName
(
"album"
);
album
.
setPrice
(
10.99f
);
album
.
setCover
(
getCoverImageBytes
());
album
.
saveAsync
().
listen
(
new
SaveCallback
()
{
@Override
public
void
onFinish
(
boolean
success
)
{
}
});
```
Kotlin:
```
kotlin
val
album
=
Album
()
album
.
name
=
"album"
album
.
price
=
10.99f
album
.
cover
=
getCoverImageBytes
()
album
.
saveAsync
().
listen
{
success
->
}
```
Just use
**saveAsync()**
instead of
**save()**
. It will save Album into database on a background, and
the saving result will be callback to
**onFinish()**
method.
#### 8. Multiple databases
#### 7. Multiple databases
If your app needs multiple databases, LitePal support it completely. You can create as many databases as you want at runtime. For example:
```
java
LitePalDB
litePalDB
=
new
LitePalDB
(
"demo2"
,
1
);
...
...
@@ -473,20 +403,29 @@ And you can delete any database by specified database name:
LitePal
.
deleteDatabase
(
"newdb"
);
```
#### 9. Listen database create or upgrade
If you need to listen database create or upgrade events and fill some initial data in the callbacks, you can do it like this:
#### 8. Transaction
LitePal support transaction for atomic db operations. All operations in the transaction will be committed or rolled back together.
Java usage:
```
java
LitePal
.
registerDatabaseListener
(
new
DatabaseListener
()
{
@Override
public
void
onCreate
()
{
// fill some initial data
}
LitePal
.
beginTransaction
();
boolean
result1
=
// db operation1
boolean
result2
=
// db operation2
boolean
result3
=
// db operation3
if
(
result1
&&
result2
&&
result3
)
{
LitePal
.
setTransactionSuccessful
();
}
LitePal
.
endTransaction
();
```
@Override
public
void
onUpgrade
(
int
oldVersion
,
int
newVersion
)
{
// upgrade data in db
}
});
Kotlin usage:
```
kotlin
LitePal
.
runInTransaction
{
val
result1
=
// db operation1
val
result2
=
// db operation2
val
result3
=
// db operation3
result1
&&
result2
&&
result3
}
```
## ProGuard
...
...
@@ -521,6 +460,13 @@ If you find any bug when using LitePal, please report **[here](https://github.co
## Change logs
### 3.1.0
*
Support transaction.
*
Add return value for
***LitePal.saveAll()**
method.
*
No longer support byte array field as column in table.
*
Deprecate all async methods. You should handle async operations by yourself.
*
Fix known bugs.
### 3.0.0
*
Optimize generic usage for async operation APIs.
*
Add
**LitePal.registerDatabaseListener()**
method for listening create or upgrade database events.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录