type_bridge.attribute.string¶
string
¶
String
¶
Bases: Attribute
String attribute type that accepts str values.
Example
class Name(String): pass
class Email(String): pass
With Literal for type safety¶
class Status(String): pass
status: Literal["active", "inactive"] | Status
Initialize String attribute with a string value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The string value to store |
required |
Source code in type_bridge/attribute/string.py
__str__
¶
__add__
¶
Concatenate strings.
Source code in type_bridge/attribute/string.py
__radd__
¶
contains
classmethod
¶
Create contains string expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
String
|
String value to search for |
required |
Returns:
| Type | Description |
|---|---|
StringExpr
|
StringExpr for attr contains value |
Example
Email.contains(Email("@company.com")) # email contains "@company.com"
Source code in type_bridge/attribute/string.py
like
classmethod
¶
Create regex pattern matching expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
String
|
Regex pattern to match |
required |
Returns:
| Type | Description |
|---|---|
StringExpr
|
StringExpr for attr like pattern |
Example
Name.like(Name("^A.*")) # name starts with 'A'
Source code in type_bridge/attribute/string.py
regex
classmethod
¶
Create regex pattern matching expression (alias for like).
Note
Automatically converts to TypeQL 'like' operator. Both 'like' and 'regex' perform regex pattern matching in TypeDB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
String
|
Regex pattern to match |
required |
Returns:
| Type | Description |
|---|---|
StringExpr
|
StringExpr for attr like pattern |
Example
Email.regex(Email(".@gmail.com")) # Generates TypeQL: $email like ".@gmail.com"
Source code in type_bridge/attribute/string.py
startswith
classmethod
¶
Create startswith string expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
String
|
Prefix string to check for |
required |
Returns:
| Type | Description |
|---|---|
StringExpr
|
StringExpr for attr like "^prefix.*" |
Source code in type_bridge/attribute/string.py
endswith
classmethod
¶
Create endswith string expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
suffix
|
String
|
Suffix string to check for |
required |
Returns:
| Type | Description |
|---|---|
StringExpr
|
StringExpr for attr like ".*suffix$" |
Source code in type_bridge/attribute/string.py
build_lookup
classmethod
¶
Build an expression for string-specific lookups.
Overrides base method to handle contains, regex, startswith, endswith.