Funkcje typu
| Nazwa | Opis |
TYPE
|
Zwraca typ wartości jako STRING.
|
IS_TYPE
|
Zwraca true, jeśli wartość pasuje do określonego typu.
|
TYP
Składnia:
type(input: ANY) -> STRING
Opis:
Zwraca ciąg znaków reprezentujący typ input.
Jeśli podano wartość nieobecną, zwraca NULL.
Przykłady:
input |
type(input) |
|---|---|
| NULL | „null” |
| prawda | „boolean” |
| 1 | „int32” |
| -3L | "int64" |
| 3.14 | „float64” |
| 2024-01-01T00:00:00Z UTC | „timestamp” |
| „foo” | „string” |
| b"foo" | „bajty” |
| [1, 2] | „array” |
| {"a": 1} | „map” |
path("c/d") |
„reference” |
vector([1.0, 2.0]) |
„wektor” |
| ABSENT | NULL |
Przykłady klientów
Node.js
const result = await db.pipeline() .collection("books") .select(field("title").notEqual("1984").as("not1984")) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select(field("title").notEqual("1984").as("not1984")) );
Swift
let result = try await db.pipeline() .collection("books") .select([Field("title").notEqual("1984").as("not1984")]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select(field("title").notEqual("1984").alias("not1984")) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select(field("title").notEqual("1984").alias("not1984")) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("title").not_equal("1984").as_("not1984")) .execute() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(notEqual(field("title"), "1984").as("not1984")) .execute() .get();
IS_TYPE
Składnia:
is_type(input: ANY, type: STRING) -> BOOLEAN
Opis:
Zwraca wartość true, jeśli input pasuje do określonego type, w przeciwnym razie zwraca false.
Jeśli argument input nie jest podany, zwraca wartość NULL.
Obsługiwane ciągi znaków type:
"null""boolean""int32""int64""float64""decimal128""number""timestamp""string""bytes""array""map""reference""vector""geo_point""max_key""min_key""object_id""regex""bson_timestamp"
Przykłady:
input |
type |
is_type(input, type) |
|---|---|---|
| NULL | „null” | prawda |
| prawda | „boolean” | prawda |
| 3.14 | „float64” | prawda |
| „foo” | „string” | prawda |
| b"foo" | „string” | fałsz |
| [1, 2] | „array” | prawda |
| {"a": 1} | „map” | prawda |
vector([1.0, 2.0]) |
„wektor” | prawda |
| ABSENT | „string” | NULL |
| „bar” | „inne” | BŁĄD |