String()#
relationalai.std.strings
#String(item: Producer) -> Expression
Filters values produced by a Producer
to only include strings.
Must be called in a rule or query context.
Parameters#
Name | Type | Description |
---|---|---|
item | Producer | The Producer object to filter. |
Returns#
An Expression
object.
Example#
Use String()
to filter string values:
#import relationalai as rai
from relationalai.std import strings
# =====
# SETUP
# =====
model = rai.Model("MyModel")
Person = model.Type("Person")
with model.rule():
Person.add(id=1).set(name="Alice")
Person.add(id="2").set(name="Bob") # id is a string.
# ========
# EXAMPLES
# ========
# Get people whose id is a string.
with model.query() as select:
person = Person()
strings.String(person.id)
response = select(person.id, person.name)
print(response.results)
# id name
# 0 1 Bob
# Get people whose id is not a string.
with model.query() as select:
person = Person()
with model.not_found():
strings.String(person.id)
response = select(person.id, person.name)
print(response.results)
# id name
# 0 2 Alice