IzumiSy/elm-firestore/8.0.0

NOTE: the latest version is 13.0.0

Firestore

A library to have your app interact with Firestore in Elm

Data type for Firestore

Constructors

Builds a new Firestore connection with Config

Drills down document paths with a specific path name.

This function is aimed to be chanind with pipeline operators in order to build up document path.

firestore
    |> Firestore.collection "users"
    |> Firestore.collection "items"
    |> Firestore.collection "tags"
    |> Firestore.get
    |> Task.attempt GotUserItemTags

Of course, you can make it a single string as well

firestore
    |> Firestore.collection "users/items/tags"
    |> Firestore.get
    |> Task.attempt GotUserItemTags

Updates configuration

CRUDs

type alias Document a =
{ name : String
, fields : a
, createTime : Posix
, updateTime : Posix
}

A record structure for a document fetched from Firestore.

get : Decoder a -> Firestore -> Task Error (Document a)

Gets a single document.

The next page token.

This token is required in fetching the next page offset by pageSize in list operation.

type alias Documents a =
{ documents : List (Document a)
, nextPageToken : Maybe PageToken
}

A record structure composed of multiple documents fetched from Firestore.

type alias ListOption =
{ pageSize : Int
, orderBy : String
, pageToken : Maybe PageToken
}

Data structure for query parameter in calling list operation.

list : ListOption -> Decoder a -> Firestore -> Task Error (Documents a)

Lists documents.

create : Decoder a -> Encoder -> Firestore -> Task Error (Document a)

Creates a new document.

-> List ( String, Field )
-> Task Error (Document a)

Updates only specific fields. If the fields do not exists, they will be created.

delete : Firestore -> Task Error ()

Deletes a document.

Error

type Error
= Http_ Error
| Response FirestoreError

An error type

This type is available in order to disregard type of errors between protocol related errors as Http_ or backend related errors as Response.

type alias FirestoreError =
{ code : Int
, message : String
, status : String
}

Data structure for errors from Firestore

Transaction

Data type for Transaction

type alias CommitTime =
Posix

A time transaction commited at

Starts a new transaction.

Adds a new update into the transaction

model.firestore
    |> Firestore.commit
        (transaction
            |> Firestore.update draft1
            |> Firestore.update draft2
            |> Firestore.update draft3
        )
    |> Task.attempt Commited
commit : Transaction -> Firestore -> Task Error CommitTime

Commits a transaction, while optionally updating documents.

Only readWrite transaction is currently supported which requires authorization that can be set via Config.withAuthorization function.