Skip to content

Commit

Permalink
updates readme
Browse files Browse the repository at this point in the history
  • Loading branch information
mchmarny committed Mar 22, 2022
1 parent b1bdc3f commit 3f7a168
Showing 1 changed file with 18 additions and 40 deletions.
58 changes: 18 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# oven

[Cloud Firestore](https://firebase.google.com/docs/firestore) wrapper client library
[Cloud Firestore](https://firebase.google.com/docs/firestore) client helper library

[![test](https://github.com/mchmarny/oven/actions/workflows/test-on-push.yaml/badge.svg?branch=main)](https://github.com/mchmarny/oven/actions/workflows/test-on-push.yaml)
[![Go Report Card](https://goreportcard.com/badge/github.com/mchmarny/oven)](https://goreportcard.com/report/github.com/mchmarny/oven)
Expand All @@ -19,7 +19,7 @@ Having used Firestore on a few projects though, I did find it wee bit verbose an

* Easy Save, Update, Get, Delete
* Structured criteria Query
* Easy to extend via Firestore client and collection accessors
* Extends Firestore client

# Install

Expand All @@ -34,30 +34,6 @@ The [examples](./examples) folder includes some of the most common use-cases wit
* [Basic CRUD](examples/crud/main.go) - Save, Get, Update, Delete operations
* [Structured Query](examples/query/main.go) - With automatic result mapping to a slice

## Service

```go
package main

import (
"context"

"github.com/mchmarny/oven"
)

func main() {
ctx := context.Background()
s := oven.New(ctx, "my-project-id")
}
```

You can also use an existing Firestore client:

```go
// c is an existing *firestore.Client
s := oven.NewWithClient(c)
```

## Save

```go
Expand All @@ -67,16 +43,16 @@ b := Book{
Author: "Douglas Adams",
}

if err := s.Save(ctx, "books", b.ID, &b); err != nil {
if err := oven.Save(ctx, client, "books", b.ID, &b); err != nil {
handleErr(err)
}
```

## Get

```go
b := &Book{}
if err := s.Get(ctx, "books", "id-123", b); err != nil {
b, err := oven.Get[Book](ctx, client, "books", "id-123")
if err != nil {
handleErr(err)
}
```
Expand All @@ -90,36 +66,38 @@ m := map[string]interface{}{
"title": "Some new title",
}

if err := s.Update(ctx, "books", "id-123", m); err != nil {
if err := oven.Update(ctx, client, "books", "id-123", m); err != nil {
handleErr(err)
}
```

## Delete

```go
if err := s.Delete(ctx, "books", "id-123"); err != nil {
if err := oven.Delete(ctx, client, "books", "id-123"); err != nil {
handleErr(err)
}
```

## Query

```go
q := &oven.Query{
Collection: "books",
Criteria: &oven.Criterion{
Path: "author", // `firestore:"author"`
Operation: oven.OperationTypeEqual,
Value: "Douglas Adams",
q := &oven.Criteria{
Collection: book.CollectionName,
Criterions: []*oven.Criterion{
{
Path: "author", // `firestore:"author"`
Operation: oven.OperationTypeEqual,
Value: bookAuthor,
},
},
OrderBy: "published", // `firestore:"published"`
Desc: true,
Limit: 10,
Limit: bookCollectionSize,
}

var list []*Book
if err := s.Query(ctx, q, &list); err != nil {
list, err := oven.Query(ctx, client, q)
if err != nil {
handleErr(err)
}
```
Expand Down

0 comments on commit 3f7a168

Please sign in to comment.