Update README.md

This commit is contained in:
Albert Shift 2015-03-23 21:42:56 -07:00
parent 8fcf22f2f5
commit 36b7ea9683

View file

@ -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();
```