@@ -29,7 +29,7 @@ Experience the magic right now and have fun!
Edit your **build.gradle** file and add below dependency:
``` groovy
dependencies{
compile'org.litepal.android:core:2.0.0'
implementation'org.litepal.android:core:2.1.0'
}
```
#### 2. Configure litepal.xml
...
...
@@ -237,7 +237,9 @@ But there are some upgrading conditions that LitePal can't handle and all data i
Be careful of the above conditions which will cause losing data.
#### 3. Save data
The saving API is quite object oriented. Each model which inherits from **LitePalSupport** would have the **save()** method for free:
The saving API is quite object oriented. Each model which inherits from **LitePalSupport** would have the **save()** method for free.
Java:
``` java
Albumalbum=newAlbum();
album.setName("album");
...
...
@@ -255,70 +257,168 @@ song2.setDuration(356);
song2.setAlbum(album);
song2.save();
```
Kotlin:
```kotlin
valalbum=Album()
album.name="album"
album.price=10.99f
album.cover=getCoverImageBytes()
album.save()
valsong1=Song()
song1.name="song1"
song1.duration=320
song1.album=album
song1.save()
valsong2=Song()
song2.name="song2"
song2.duration=356
song2.album=album
song2.save()
```
This will insert album, song1 and song2 into database with associations.
#### 4. Update data
The simplest way, use **save()** method to update a record found by **find()**:
The simplest way, use **save()** method to update a record found by **find()**.
Java:
``` java
AlbumalbumToUpdate=LitePal.find(Album.class,1);
albumToUpdate.setPrice(20.99f);// raise the price
albumToUpdate.save();
```
Each model which inherits from **LitePalSupport** would also have **update()** and **updateAll()** method. You can update a single record with a specified id:
Kotlin:
```kotlin
valalbumToUpdate=LitePal.find<Album>(1)
albumToUpdate.price=20.99f// raise the price
albumToUpdate.save()
```
Each model which inherits from **LitePalSupport** would also have **update()** and **updateAll()** method. You can update a single record with a specified id.
Java:
``` java
AlbumalbumToUpdate=newAlbum();
albumToUpdate.setPrice(20.99f);// raise the price
albumToUpdate.update(id);
```
Or you can update multiple records with a where condition:
Kotlin:
```kotlin
valalbumToUpdate=Album()
albumToUpdate.price=20.99f// raise the price
albumToUpdate.update(id)
```
Or you can update multiple records with a where condition.
Java:
``` java
AlbumalbumToUpdate=newAlbum();
albumToUpdate.setPrice(20.99f);// raise the price
albumToUpdate.updateAll("name = ?","album");
```
Kotlin:
```kotlin
valalbumToUpdate=Album()
albumToUpdate.price=20.99f// raise the price
albumToUpdate.updateAll("name = ?","album")
```
#### 5. Delete data
You can delete a single record using the static **delete()** method in **LitePal**:
You can delete a single record using the static **delete()** method in **LitePal**.
Java:
``` java
LitePal.delete(Song.class,id);
```
Or delete multiple records using the static **deleteAll()** method in **LitePal**:
Kotlin:
```kotlin
LitePal.delete<Song>(id)
```
Or delete multiple records using the static **deleteAll()** method in **LitePal**.
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.
...
...
@@ -390,6 +502,7 @@ Get it on:
If you find any bug when using LitePal, please report **[here](https://github.com/LitePalFramework/LitePal/issues/new)**. Thanks for helping us making better.
## Change logs
### 2.0.0
* Offer new APIs for CRUD operations. Deprecate **DataSupport**, use **LitePal** and **LitePalSupport** instead.