تایپ کردن توابع
| نام | شرح |
TYPE
|
نوع مقدار را بهصورت STRING برمیگرداند.
|
IS_TYPE
|
اگر مقدار با نوع مشخصشده مطابقت داشته باشد، true را برمیگرداند.
|
نوع
نحو:
type(input: ANY) -> STRING
شرح:
نمایش رشتهای نوع input را برمیگرداند.
اگر مقدار غایب داده شود، NULL را برمیگرداند.
نمونه:
input |
type(input) |
|---|---|
| NULL | "null" |
| درست | "boolean" |
| 1 | "int32" |
| -۳ لیتر | "int64" |
| ۳.۱۴ | "float64" |
| 2024-01-01T00:00:00Z UTC | "timestamp" |
| «foo» | "string" |
| b"foo" | "bytes" |
| [۱، ۲] | "array" |
| {"a": 1} | "map" |
path("c/d") |
"reference" |
vector([1.0, 2.0]) |
"vector" |
object_id "a7f2c9d18b3e4509f67c12d8" |
"object_id" |
1.2e9m |
"decimal128" |
regex "/pattern/i" |
"regex" |
bson_timestamp(1732754912, 500) |
"bson_timestamp" |
| غایب | NULL |
نمونههای مشتری
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();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("title").not_equal("1984").as_("not1984")) .execute() )
جاوا
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(notEqual(field("title"), "1984").as("not1984")) .execute() .get();
رفتن
snapshot := client.Pipeline(). Collection("books"). Select(firestore.Fields( firestore.NotEqual(firestore.FieldOf("title"), "1984").As("not1984"), )). Execute(ctx)
IS_TYPE
نحو:
is_type(input: ANY, type: STRING) -> BOOLEAN
شرح:
اگر input با type مشخصشده مطابقت داشته باشد، true را برمیگرداند، درغیراینصورت false را برمیگرداند.
اگر input غایب باشد، NULL را برمیگرداند.
رشتههای 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"
نمونه:
input |
type |
is_type(input, type) |
|---|---|---|
| NULL | «null» | درست |
| درست | «بولی» | درست |
| ۳.۱۴ | «float64» | درست |
| «foo» | «رشته» | درست |
| b"foo" | «رشته» | نادرست |
| [۱، ۲] | «آرایه» | درست |
| {"a": 1} | «نقشه» | درست |
vector([1.0, 2.0]) |
«بردار» | درست |
| غایب | «رشته» | NULL |
| «bar» | «دیگر» | خطا |