RecordId

A RecordId uniquely identifies a record in SurrealDB. It consists of a table name and an ID value. The ID can be a long, String, UUID, or a composite key using Array or Object. See the SurrealQL record ID documentation for details on how record identifiers work in SurrealDB.

Source: surrealdb.java

Constructors

RecordId(String table, long id)

Creates a record ID with a numeric identifier.

Method Syntax

new RecordId(table, id)
ParameterTypeDescription
table StringThe table name.
id longThe numeric record identifier.

Example

RecordId id = new RecordId("person", 1);

RecordId(String table, String id)

Creates a record ID with a string identifier.

Method Syntax

new RecordId(table, id)
ParameterTypeDescription
table StringThe table name.
id StringThe string record identifier.

Example

RecordId id = new RecordId("person", "tobie");

RecordId(String table, UUID id)

Creates a record ID with a UUID identifier.

Method Syntax

new RecordId(table, id)
ParameterTypeDescription
table StringThe table name.
id UUIDThe UUID record identifier.

Example

RecordId id = new RecordId("person", UUID.randomUUID());

RecordId(String table, Array id)

Creates a record ID with a composite key using an array.

Method Syntax

new RecordId(table, id)
ParameterTypeDescription
table StringThe table name.
id ArrayThe composite key as an array.

RecordId(String table, Object id)

Creates a record ID with a composite key using an object.

Method Syntax

new RecordId(table, id)
ParameterTypeDescription
table StringThe table name.
id ObjectThe composite key as an object.

Methods

.getTable()

Returns the table name of this record ID.

Method Syntax

recordId.getTable()

Returns: String

Example

RecordId id = new RecordId("person", "tobie");
String table = id.getTable();

.getId()

Returns the identifier part of this record ID.

Method Syntax

recordId.getId()

Returns: Id

Example

RecordId id = new RecordId("person", "tobie");
Id identifier = id.getId();

Id

The Id class represents the identifier part of a RecordId. It wraps the underlying value and provides type checking and extraction methods.

Static Factory Methods

Id.from(long id)

Creates an Id from a numeric value.

Method Syntax

Id.from(id)
ParameterTypeDescription
id longThe numeric identifier.

Returns: Id

Id.from(String id)

Creates an Id from a string value.

Method Syntax

Id.from(id)
ParameterTypeDescription
id StringThe string identifier.

Returns: Id

Id.from(UUID id)

Creates an Id from a UUID value.

Method Syntax

Id.from(id)
ParameterTypeDescription
id UUIDThe UUID identifier.

Returns: Id

Type Checking Methods

MethodReturns true when
isLong()The ID is a numeric value
isString()The ID is a string value
isUuid()The ID is a UUID value
isArray()The ID is a composite array key
isObject()The ID is a composite object key

Getter Methods

MethodReturn TypeDescription
getLong()longReturns the numeric ID value
getString()StringReturns the string ID value
getUuid()UUIDReturns the UUID ID value
getArray()ArrayReturns the composite array key
getObject()ObjectReturns the composite object key

RecordIdRange

The RecordIdRange class represents a range of record IDs within a table. It can be used with methods like select to retrieve a subset of records.

Constructor

RecordIdRange(String table, Id start, Id end)

Creates a range of record IDs. Pass null for start or end to leave that bound open.

Method Syntax

new RecordIdRange(table, start, end)
ParameterTypeDescription
table StringThe table name.
start IdThe start of the range. Pass null for an unbounded start.
end IdThe end of the range. Pass null for an unbounded end.

Methods

.getTable()

Returns the table name of this range.

Method Syntax

range.getTable()

Returns: String

.getStart()

Returns the start bound of the range, or null if unbounded.

Method Syntax

range.getStart()

Returns: Id (nullable)

.getEnd()

Returns the end bound of the range, or null if unbounded.

Method Syntax

range.getEnd()

Returns: Id (nullable)

Example

Selecting a range of records

RecordIdRange range = new RecordIdRange("users", Id.from(1), Id.from(100));
List<Value> results = db.select(range);

See Also