Update README.md
This commit is contained in:
parent
8fcf22f2f5
commit
36b7ea9683
1 changed files with 43 additions and 4 deletions
47
README.md
47
README.md
|
@ -14,9 +14,48 @@ Java 8 Cassandra Client
|
|||
|
||||
### Example
|
||||
|
||||
Entity definition:
|
||||
```
|
||||
session.select(timeline::getUserId, timeline::getTimestamp, timeline::getText)
|
||||
.where(timeline::getUserId, "==", userId)
|
||||
.orderBy(timeline::getTimestamp, "desc").limit(5).sync()
|
||||
.forEach(System.out::println);
|
||||
@Table("timelines")
|
||||
public interface Timeline {
|
||||
|
||||
@PartitionKey
|
||||
UUID getUserId();
|
||||
|
||||
void setUserId(UUID uid);
|
||||
|
||||
@ClusteringColumn
|
||||
@DataTypeName(Name.TIMEUUID)
|
||||
Date getTimestamp();
|
||||
|
||||
void setTimestamp(Date ts);
|
||||
|
||||
@Column
|
||||
String getText();
|
||||
|
||||
void setText(String text);
|
||||
}
|
||||
```
|
||||
|
||||
Session initialization:
|
||||
```
|
||||
Timeline timeline = Casser.dsl(Timeline.class);
|
||||
CasserSession session = Casser.init(getSession()).showCql().createDrop(Timeline.class).get();
|
||||
```
|
||||
|
||||
Select information:
|
||||
```
|
||||
session.select(timeline::getUserId, timeline::getTimestamp, timeline::getText)
|
||||
.where(timeline::getUserId, "==", userId)
|
||||
.orderBy(timeline::getTimestamp, "desc").limit(5).sync()
|
||||
.forEach(System.out::println);
|
||||
```
|
||||
|
||||
Insert information:
|
||||
```
|
||||
Timeline post = Casser.pojo(Timeline.class);
|
||||
post.setUserId(userId);
|
||||
post.setTimestamp(new Date(postTime+1000L*i));
|
||||
post.setText("hello");
|
||||
session.upsert(post).sync();
|
||||
```
|
||||
|
|
Loading…
Reference in a new issue