PPlusFireStore.API (pplus_firestore v0.1.5)
View SourceModule to interact with Google Firestore API
Summary
Functions
Delete document from firestore
Get document from firestore
List documents from firestore
Update document in firestore
Types
Functions
@spec create_document( auth_token :: String.t(), parent :: String.t(), collection :: String.t(), data :: map(), opts :: Keyword.t() ) :: {:ok, PPlusFireStore.Model.Document.t()} | {:error, error_code(), Tesla.Env.t()} | {:error, any()}
Create document
Parameters
- auth_token: auth token
- parent: The parent resource. For example:
projects/{project_id}/databases/{database_id}/documents
orprojects/{project_id}/databases/{database_id}/documents/chatrooms/{chatroom_id}
- collection: collection name
- data: map with document data
- opts: optional parameters. See: https://hexdocs.pm/google_api_firestore/GoogleApi.Firestore.V1.Api.Projects.html#firestore_projects_databases_documents_create_document/5
Example:
iex> PPlusFireStore.API.create_document("token", "projects/my_project/databases/(default)/documents", "books", %{author: "John Doe"})
{:ok,
%PPlusFireStore.Model.Document{
path: "projects/my_project/databases/(default)/documents/books/esgXQM7pqNCwQwYRJeBJ",
data: %{"author" => "John Due"},
created_at: ~U[2025-01-10 17:14:04.738331Z],
updated_at: ~U[2025-01-10 17:14:04.738331Z]
}}
Note: One of the optional parameters is documentId
, which is the id of the document to be created. If not provided, Firestore will generate an id automatically. It is important to pass the document id if you want to control the creation of duplicate documents.
@spec delete_document( auth_token :: String.t(), path :: String.t(), opts :: Keyword.t() ) :: :ok | {:error, error_code(), Tesla.Env.t()} | {:error, any()}
Delete document from firestore
Parameters
- auth_token: auth token
- path: The name of the document to delete. For example:
projects/{project_id}/databases/{database_id}/documents/{document_path}
- opts: optional parameters. See: https://hexdocs.pm/google_api_firestore/GoogleApi.Firestore.V1.Api.Projects.html#firestore_projects_databases_documents_delete/4
Example:
iex> PPlusFireStore.API.delete_document("token", "projects/my_project/databases/(default)/documents/books/esgXQM7pqNCwQwYRJeBJ")
{:ok, :deleted}
@spec get_document( auth_token :: String.t(), path :: String.t(), opts :: Keyword.t() ) :: {:ok, PPlusFireStore.Model.Document.t()} | {:error, error_code(), Tesla.Env.t()} | {:error, any()}
Get document from firestore
Parameters
- auth_token: auth token
- path: The name of the document to retrieve. For example:
projects/{project_id}/databases/{database_id}/documents/{document_path}
- opts: optional parameters. See: https://hexdocs.pm/google_api_firestore/GoogleApi.Firestore.V1.Api.Projects.html#firestore_projects_databases_documents_get/4
Example:
iex> PPlusFireStore.API.get_document("token", "projects/my_project/databases/(default)/documents/books/esgXQM7pqNCwQwYRJeBJ")
{:ok,
%PPlusFireStore.Model.Document{
path: "projects/my_project/databases/(default)/documents/books/esgXQM7pqNCwQwYRJeBJ",
data: %{"author" => "John Due"},
created_at: ~U[2025-01-10 17:14:04.738331Z],
updated_at: ~U[2025-01-10 17:14:04.738331Z]
}}
@spec list_documents( auth_token :: String.t(), parent :: String.t(), collection :: String.t(), opts :: Keyword.t() ) :: {:ok, PPlusFireStore.Model.Page.t(PPlusFireStore.Model.Document.t())} | {:error, error_code(), Tesla.Env.t()} | {:error, any()}
List documents from firestore
Parameters
- auth_token: auth token
- parent: The parent resource. For example:
projects/{project_id}/databases/{database_id}/documents
orprojects/{project_id}/databases/{database_id}/documents/chatrooms/{chatroom_id}
- collection: collection name
- opts: optional parameters. See: https://hexdocs.pm/google_api_firestore/GoogleApi.Firestore.V1.Api.Projects.html#firestore_projects_databases_documents_list/5
Example:
iex> PPlusFireStore.API.list_documents("token", "projects/my_project/databases/(default)/documents", "books", pageSize: 1)
{:ok,
%PPlusFireStore.Model.Page{
data: [
%PPlusFireStore.Model.Document{
path: "projects/my_project/databases/(default)/documents/books/esgXQM7pqNCwQwYRJeBJ",
data: %{"author" => "John Due"},
created_at: ~U[2025-01-10 17:14:04.738331Z],
updated_at: ~U[2025-01-10 17:14:04.738331Z]
}
],
next_page_token: "AFTOeJwGTcAtgJAapbJ0K7tPwpH9saWYfm4bG991Kk4qdP3NXq9pFfp5IW-E6lwbnRW661DKMJjo5EA7y2iF8GFjaCPLlXN7c0jMYATSRgclgLEChgsSIBjt"
}}
@spec run_query( auth_token :: String.t(), parent :: String.t(), query :: GoogleApi.Firestore.V1.Model.StructuredQuery.t(), opts :: Keyword.t() ) :: {:ok, PPlusFireStore.Model.Page.t(PPlusFireStore.Model.Document.t())} | {:error, Tesla.Env.t()} | {:error, any()}
@spec update_document( auth_token :: String.t(), path :: String.t(), data :: map(), opts :: Keyword.t() ) :: {:ok, PPlusFireStore.Model.Document.t()} | {:error, error_code(), Tesla.Env.t()} | {:error, any()}
Update document in firestore
Parameters
- auth_token: auth token
- path: The name of the document to update. For example:
projects/{project_id}/databases/{database_id}/documents/{document_path}
- data: map with document data
- opts: optional parameters. See: https://hexdocs.pm/google_api_firestore/GoogleApi.Firestore.V1.Api.Projects.html#firestore_projects_databases_documents_patch/5
Example:
iex> PPlusFireStore.API.update_document("token", "projects/my_project/databases/(default)/documents/books/esgXQM7pqNCwQwYRJeBJ", %{author: "John Doe da Silva"})
{:ok,
%PPlusFireStore.Model.Document{
path: "projects/my_project/databases/(default)/documents/books/esgXQM7pqNCwQwYRJeBJ",
data: %{"author" => "John Due da Silva"},
created_at: ~U[2025-01-10 17:14:04.738331Z],
updated_at: ~U[2025-01-10 17:14:04.738331Z]
}}