IzumiSy/elm-firestore/10.0.1

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.

Updates configuration.

Path

type Path

Type to point document path to operate.

A Path value is always required in calling CRUD operations. This interface design enforces users to call path function to build Path value beforehand in order to prevent forgetting specifiying path to operate.

path : String -> Firestore -> Path

Specifies document path.

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

CRUDs

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

A record structure for a document fetched from Firestore.

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

A record structure composed of multiple documents fetched from Firestore.

type Name

Name field of Firestore document

id : Name -> String

Extracts ID from Name field

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

Gets a single document.

list : Decoder a -> Options -> Path -> Task Error (Documents a)

Lists documents.

-> { id : String
, document : Encoder
}
-> Path
-> Task Error (Document a)

Creates a document with a given document id.

Takes the document id as the first argument.

insert : Decoder a -> Encoder -> Path -> Task Error (Document a)

Insert a document into a collection.

The document will get a fresh document id.

upsert : Decoder a -> Encoder -> Path -> Task Error (Document a)

Updates an existing document.

Creates one if not present.

patch : Decoder a -> Options -> Path -> Task Error (Document a)

Updates only specific fields.

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

delete : Path -> Task Error ()

Deletes a document.

Will succeed if document does not exist.

Deletes a document.

Will fail if document does not exist.

Query

type alias Query a =
{ transaction : Maybe TransactionId
, document : Document a
, readTime : Posix
, skippedResults : Int
}

A record structure for query operation result

runQuery : Decoder a -> Query -> Firestore -> Task Error (List (Query a))

Runs a query operation

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

Transaction ID

type alias CommitTime =
Posix

A time transaction commited at

Starts a new transaction.

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.

model.firestore
    |> Firestore.commit
        (transaction
            |> Firestore.updateTx "users/user1" newUser1
            |> Firestore.updateTx "users/user2" newUser2
            |> Firestore.deleteTx "users/user3"
            |> Firestore.deleteTx "users/user4"
        )
    |> Task.attempt Commited
getTx : Transaction -> Decoder a -> Path -> Task Error (Document a)

Gets a single document in transaction

listTx : Transaction -> Decoder a -> Options -> Path -> Task Error (Documents a)

Lists documents in transaction

-> Decoder a
-> Query
-> Task Error (List (Query a))

Runs a query operation in transaction

Adds update into the transaction

Adds deletion into the transaction