Class: GenericId<TableName>
values.GenericId
An identifier for a document in Convex.
Convex documents are uniquely identified by their Id
, which is accessible
on the _id
field. To learn more, see Data Modeling.
Documents can be loaded using db.get(id)
in query and mutation functions.
Important: Use myId.equals(otherId)
to check for equality.
Using ===
will not work because two different instances of Id
can refer
to the same document.
Id
s are 16 bytes long and consist of:
- A 14-byte random value.
- A 2-byte timestamp representing the document's creation, in days since the Unix epoch.
This is encoded in URL-safe base 64 (uses -
and _
).
If you're using code generation, use the Id
class typed for your data model in
convex/_generated/dataModel.js
.
Type parameters
Name | Type | Description |
---|---|---|
TableName | extends string | A string literal type of the table name (like "users"). |
Constructors
constructor
• new GenericId<TableName
>(tableName
, id
)
Type parameters
Name | Type |
---|---|
TableName | extends string |
Parameters
Name | Type |
---|---|
tableName | TableName |
id | string |
Defined in
Properties
tableName
• Readonly
tableName: TableName
The table name this GenericId references.
Defined in
id
• Readonly
id: string
The identifier string.
This is encoded in URL-safe base 64 (uses -
and _
).
Defined in
Methods
equals
▸ equals(other
): boolean
Check if this GenericId refers to the same document as another GenericId.
Parameters
Name | Type | Description |
---|---|---|
other | unknown | The other GenericId to compare to. |
Returns
boolean
true
if the objects refer to the same document.
Defined in
fromJSON
▸ Static
fromJSON(obj
): GenericId
<string
>
Parse a GenericId from its JSON representation.
Parameters
Name | Type |
---|---|
obj | any |
Returns
GenericId
<string
>
Defined in
toJSON
▸ toJSON(): JSONValue
Convert a GenericId into its JSON representation.
Returns
Defined in
toString
▸ toString(): string
Convert a GenericId into its string representation.
This includes the identifier but not the table name.
Returns
string
Defined in
inspect
▸ inspect(): string
Pretty-print this GenericId for debugging.
Returns
string