Skip to content

Commit

Permalink
Add support precision in Firestore Document's DoubleValue and MapValue
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Jun 22, 2024
1 parent 7011c6d commit d02efac
Show file tree
Hide file tree
Showing 12 changed files with 550 additions and 54 deletions.
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

[![GitHub Sponsors](https://img.shields.io/github/sponsors/mobizt?logo=github)](https://github.com/sponsors/mobizt)

Revision `2024-06-19T11:47:09Z`
Revision `2024-06-22T06:00:12Z`

## Table of Contents

Expand Down Expand Up @@ -2951,17 +2951,18 @@ ENABLE_GSM_NETWORK
The following options are not yet defined in [**Config.h**](src/Config.h) and can be defined by user.

```cpp
FIREBASE_ETHERNET_MODULE_LIB `"EthernetLibrary.h"` // For the Ethernet library to work with external Ethernet module
FIREBASE_ETHERNET_MODULE_CLASS EthernetClass // For the Ethernet class object of Ethernet library to work with external Ethernet module
FIREBASE_ETHERNET_MODULE_TIMEOUT 2000 // For the time out in milliseconds to wait external Ethernet module to connect to network
ENABLE_ESP8266_ENC28J60_ETH // For native core library ENC28J60 Ethernet module support in ESP8266
ENABLE_ESP8266_W5500_ETH // For native core library W5500 Ethernet module support in ESP8266
ENABLE_ESP8266_W5100_ETH // For native core library W5100 Ethernet module support in ESP8266
FIREBASE_DISABLE_ONBOARD_WIFI // For disabling on-board WiFI functionality in case external Client usage
FIREBASE_DISABLE_NATIVE_ETHERNET // For disabling native (sdk) Ethernet functionality in case external Client usage
ENABLE_ASYNC_TCP_CLIENT // For Async TCP Client usage
FIREBASE_ASYNC_QUEUE_LIMIT // For maximum async queue limit setting for an async client
FIREBASE_DEFAULT_DEBUG_PORT // For Firebase.printf debug port
FIREBASE_ETHERNET_MODULE_LIB `"EthernetLibrary.h"` // For the Ethernet library to work with external Ethernet module.
FIREBASE_ETHERNET_MODULE_CLASS EthernetClass // For the Ethernet class object of Ethernet library to work with external Ethernet module.
FIREBASE_ETHERNET_MODULE_TIMEOUT 2000 // For the time out in milliseconds to wait external Ethernet module to connect to network.
ENABLE_ESP8266_ENC28J60_ETH // For native core library ENC28J60 Ethernet module support in ESP8266.
ENABLE_ESP8266_W5500_ETH // For native core library W5500 Ethernet module support in ESP8266.
ENABLE_ESP8266_W5100_ETH // For native core library W5100 Ethernet module support in ESP8266.
FIREBASE_DISABLE_ONBOARD_WIFI // For disabling on-board WiFI functionality in case external Client usage.
FIREBASE_DISABLE_NATIVE_ETHERNET // For disabling native (sdk) Ethernet functionality in case external Client usage.
ENABLE_ASYNC_TCP_CLIENT // For Async TCP Client usage.
FIREBASE_ASYNC_QUEUE_LIMIT // For maximum async queue limit setting for an async client.
FIREBASE_PRINTF_PORT // For Firebase.printf debug port.
FIREBASE_PRINTF_BUFFER // Firebase.printf buffer size.
```

You can assign the optional build options using one of the following methods.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,17 @@ void loop()
// We will create the document in the parent path "a0/b?
// a0 is the collection id, b? is the document id in collection a0.

String documentPath = "a0/b" + String(cnt);
String documentPath = "a0/b";
documentPath += cnt;

// If the document path contains space e.g. "a b c/d e f"
// It should encode the space as %20 then the path will be "a%20b%20c/d%20e%20f"

// double
Values::DoubleValue dblV(random(1, 500) / 100.0);
// double (obsoleted)
// Values::DoubleValue dblV(1234.567891);

// double value with precision.
Values::DoubleValue dblV(number_t(1234.567891, 6));

// boolean
Values::BooleanValue bolV(true);
Expand Down Expand Up @@ -179,8 +183,11 @@ void loop()
Values::MapValue mapV("name", Values::StringValue("wrench"));
mapV.add("mass", Values::StringValue("1.3kg")).add("count", Values::IntegerValue(3));

// lat long
Values::GeoPointValue geoV(1.486284, 23.678198);
// lat long (Obsoleated)
// Values::GeoPointValue geoV(1.486284, 23.678198);

// lat long with precision
Values::GeoPointValue geoV(number_t(1.486284, 6), number_t(23.678198, 6));

Document<Values::Value> doc("myDouble", Values::Value(dblV));
doc.add("myBool", Values::Value(bolV)).add("myInt", Values::Value(intV)).add("myNull", Values::Value(nullV));
Expand Down Expand Up @@ -253,4 +260,4 @@ String getTimestampString(uint64_t sec, uint32_t nano)

strftime(buf, sizeof(buf), format.c_str(), &ts);
return buf;
}
}
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "FirebaseClient",
"version": "1.2.13",
"version": "1.2.14",
"keywords": "communication, REST, esp32, esp8266, arduino",
"description": "Async Firebase Client library for Arduino.",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name=FirebaseClient

version=1.2.13
version=1.2.14

author=Mobizt

Expand Down
12 changes: 6 additions & 6 deletions resources/docs/firestore_database.md
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ String createDocument(AsyncClientClass &aClient, Firestore::Parent parent, const
- `parent` - The Firestore::Parent object included project Id and database Id in its constructor.
- `documentPath` - The relative path of document to create in the collection.
- `mask` - The fields to return. If not set, returns all fields. Use comma (,) to separate between the field names.
- `document` - A Firestore document.
- `document` - A Firestore document. See [Firestore document class and functions](/resources/docs/firestore_database_document.md).
**Returns:**
Expand All @@ -457,7 +457,7 @@ void createDocument(AsyncClientClass &aClient, Firestore::Parent parent, const S
- `parent` - The Firestore::Parent object included project Id and database Id in its constructor.
- `documentPath` - The relative path of document to create in the collection.
- `mask` - The fields to return. If not set, returns all fields. Use comma (,) to separate between the field names.
- `document` - A Firestore document.
- `document` - A Firestore document. See [Firestore document class and functions](/resources/docs/firestore_database_document.md).
- `aResult` - The async result (AsyncResult)


Expand All @@ -482,7 +482,7 @@ void createDocument(AsyncClientClass &aClient, Firestore::Parent parent, const S
- `parent` - The Firestore::Parent object included project Id and database Id in its constructor.
- `documentPath` - The relative path of document to create in the collection.
- `mask` - The fields to return. If not set, returns all fields. Use comma (,) to separate between the field names.
- `document` - A Firestore document.
- `document` - A Firestore document. See [Firestore document class and functions](/resources/docs/firestore_database_document.md).
- `cb` - The async result callback (AsyncResultCallback).
- `uid` - The user specified UID of async result (optional).
Expand Down Expand Up @@ -510,7 +510,7 @@ String createDocument(AsyncClientClass &aClient, Firestore::Parent parent, const
- `collectionId` - The relative path of document collection id to create the document.
- `documentId` - The document id of document to be created.
- `mask` - The fields to return. If not set, returns all fields. Use comma (,) to separate between the field names.
- `document` - A Firestore document.
- `document` - A Firestore document. See [Firestore document class and functions](/resources/docs/firestore_database_document.md).

**Returns:**

Expand Down Expand Up @@ -539,7 +539,7 @@ void createDocument(AsyncClientClass &aClient, Firestore::Parent parent, const S
- `collectionId` - The relative path of document collection id to create the document.
- `documentId` - The document id of document to be created.
- `mask` - The fields to return. If not set, returns all fields. Use comma (,) to separate between the field names.
- `document` - A Firestore document.
- `document` - A Firestore document. See [Firestore document class and functions](/resources/docs/firestore_database_document.md).
- `aResult` - The async result (AsyncResult)
Expand All @@ -566,7 +566,7 @@ void createDocument(AsyncClientClass &aClient, Firestore::Parent parent, const S
- `collectionId` - The relative path of document collection id to create the document.
- `documentId` - The document id of document to be created.
- `mask` - The fields to return. If not set, returns all fields. Use comma (,) to separate between the field names.
- `document` - A Firestore document.
- `document` - A Firestore document. See [Firestore document class and functions](/resources/docs/firestore_database_document.md).
- `cb` - The async result callback (AsyncResultCallback).
- `uid` - The user specified UID of async result (optional).

Expand Down
67 changes: 67 additions & 0 deletions resources/docs/firestore_database_document.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

# Document

## Description

Google Cloud Firestore database Document class


```cpp
class Document
```
## Constructors
1. ### 🔹 Document(const String &name = "")
A Firestore document constructor with document resource name.
```cpp
Document(const String &name = "")
```

**Params:**

- `name` - The resource name of the document.

2. ### 🔹 Document(const String &key, T value)

A Firestore document constructor with `Values::Value` object. See [Firestore Value class and functions](/resources/docs/firestore_database_values.md).

```cpp
Document(const String &key, T value)
```
**Params:**
- `key` - The key of an object.
- `value` - The value of an `Values::Value` object.
## Functions
1. ### 🔹 Document &add(const String &key, T value)
Add the `Values::Value` object to Firestore document. See [Firestore Value class and functions](/resources/docs/firestore_database_values.md).
```cpp
Document &add(const String &key, T value)
```

**Params:**

- `key` - The key of an `Values::Value` object.

- `value` - The value of an `Values::Value` object.

2. ### 🔹 void setName(const String &name)

Set the document resource name.

```cpp
void setName(const String &name)
```
**Params:**
- `name` - The resource name of the document.
Loading

0 comments on commit d02efac

Please sign in to comment.