String()#
relationalai.std.strings
#String(item: Any) -> Expression
Checks if an item is a string. Must be called in a rule or query context.
Parameters#
Name | Type | Description |
---|---|---|
item | Any | The item to check. |
Returns#
An Expression
object.
Example#
#import relationalai as rai
from relationalai.std.strings import String
# =====
# SETUP
# =====
# Create a model named "people" with a Person type.
model = rai.Model("people")
Person = model.Type("Person")
# Add some people to the model.
with model.rule():
Person.add(id=1).set(name="Alice")
Person.add(id="2").set(name="Bob") # Note that the id is a string.
# =======
# EXAMPLE
# =======
with model.query() as select:
person = Person()
String(person.id) # Filter people whose id is a string.
response = select(person.name)
print(response.results)
# name
# 0 Bob
with model.query() as select:
person = Person()
with model.not_found():
String(person.id) # Filter people whose id is not a string.
response = select(person.name)
print(response.results)
# name
# 0 Alice