Class Surreal
- All Implemented Interfaces:
AutoCloseable
Surreal
class provides methods to interact with a Surreal database.
It includes functionality to connect to the database, sign in with different scopes,
set the namespace and database, execute queries, and perform CRUD operations on records.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes and releases any resources associated with this instance.Establishes a connection to the Surreal database using the provided connection string.<T> Value
Creates a record in the database with the given `RecordID` as the key and the provided content as the value.<T> T
Creates a record in the database with the given `RecordID` as the key and the provided content as the value.final <T> List
<T> Creates records in the database with the given table and the provided contents as the values.Creates records in the database with the given table and the provided contents as the values.void
Deletes a record identified by the provided RecordId.void
Deletes the specified records.void
Deletes the specified target.final <T> List
<T> Insert records in the database with the given table and the provided contents as the values.Insert records in the database with the given table and the provided contents as the values.<T extends InsertRelation>
TinsertRelation
(Class<T> type, String target, T content) Inserts a relation of the specified type and table with the provided content.<T extends InsertRelation>
ValueinsertRelation
(String target, T content) Inserts a relation to the specified table using the provided content.final <T extends InsertRelation>
List<T> insertRelations
(Class<T> type, String target, T... contents) Inserts multiple relations of a specified type into the target.final <T extends InsertRelation>
List<Value> insertRelations
(String target, T... contents) Inserts relations into the specified table with the provided contents.Executes a SurrealQL query on the database.Executes a parameterized SurrealQL query on the database.Establishes a relation between two records identified by `from` and `to` within a specified table.<T> Value
Establishes a relationship between two records within a specified table, attaching the provided content to this relationship.<R extends Relation,
T>
REstablishes a relation between two records and retrieves it based on the specified relation type.<T extends Relation>
TEstablishes and retrieves a relation of a specified type between two records.Selects a record by its RecordId and retrieves the corresponding Value.Selects values based on the provided RecordIds.<T> Optional
<T> Selects an instance of the specified type from a record identified by the given RecordId.<T> List
<T> Selects and retrieves a list of objects of the specified type based on the given record IDs.<T> Iterator
<T> Selects and retrieves an iterator of specified type for given targets.Selects and returns an iterator over the values corresponding to the given targets.<T> Iterator
<T> selectSync
(Class<T> type, String targets) Selects and returns a thread-safe iterator over a collection of objects of the specified type from the given targets.selectSync
(String targets) Selects and returns a thread-safe iterator to traverse values associated with the given targets.Attempts to sign in to the Surreal system using the provided credentials.<T> Value
Updates the value of a record with the specified content and update type.<T> T
Updates a record of the specified type and returns the updated record.<T> Iterator
<T> Updates the specified tables with the given content and returns an iterator over the updated elements of the specified type.<T> Iterator
<T> Updates the specified table with the provided content and returns an iterator for the updated values.Updates the specified tables with the given content.Updates the table with the given content based on the specified update type.<T> Iterator
<T> updateSync
(Class<T> type, String[] targets, UpType upType, T content) Updates the provided tables with the provided content and returns an iterator for the updated values.<T> Iterator
<T> updateSync
(Class<T> type, String target, UpType upType, T content) Updates the table with the provided content.updateSync
(String[] targets, UpType upType, T content) Updates the tables using the provided content and update type.updateSync
(String target, UpType upType, T content) Updates the specified table with the provided content.<T> Value
Inserts a new record or updates an existing record with the given content.<T> T
Upserts a record and returns the updated or inserted entity.<T> Iterator
<T> Updates or inserts the provided content based on the specified tables and update type.<T> Iterator
<T> Inserts or updates a record of the specified type with the given content.Inserts or updates values in the given tables.Performs an upsert operation on the specified table with the provided content.<T> Iterator
<T> upsertSync
(Class<T> type, String[] targets, UpType upType, T content) Performs an upsert operation with the specified content on the given tables.<T> Iterator
<T> upsertSync
(Class<T> type, String target, UpType upType, T content) Inserts or updates a record and returns an iterator over the result.upsertSync
(String[] targets, UpType upType, T content) Performs an upsert (update or insert) operation on the specified tables.upsertSync
(String target, UpType upType, T content) Inserts or updates the table with the provided content and returns a thread-safe iterator over the resulting values.Sets the database for the current instance of the Surreal class.Sets the namespace for the Surreal instance.
-
Constructor Details
-
Surreal
public Surreal()Constructs a new Surreal object.
-
-
Method Details
-
connect
-
signin
Attempts to sign in to the Surreal system using the provided credentials. The type of signin object determines the scope of the sign-in (Root, Namespace, or Database).For more details, check the authentication documentation.
- Parameters:
signin
- the credentials for signing in, which can be an instance of Root, Namespace, or Database- Returns:
- a Token representing the session token after a successful sign-in
- Throws:
SurrealException
- if the signin type is unsupported
-
useNs
Sets the namespace for the Surreal instance.For more details, check the use statement documentation.
- Parameters:
ns
- the namespace to use- Returns:
- the current instance of the
Surreal
class
-
useDb
Sets the database for the current instance of the Surreal class.For more details, check the use statement documentation.
- Parameters:
db
- the database name to use- Returns:
- the current instance of the
Surreal
class
-
query
Executes a SurrealQL query on the database.For more details, check the SurrealQL documentation.
- Parameters:
sql
- the SurrealQL query to be executed- Returns:
- a Response object containing the results of the query
-
queryBind
Executes a parameterized SurrealQL query on the database.For more details, check the SurrealQL documentation.
- Parameters:
sql
- the SurrealQL query to be executedparams
- a map containing parameter values to be bound to the SQL query- Returns:
- a Response object containing the results of the query
-
create
Creates a record in the database with the given `RecordID` as the key and the provided content as the value.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- the type of the content- Parameters:
thg
- the RecordId associated with the new recordcontent
- the content of the created record- Returns:
- a new Value object initialized with the provided RecordId and content
-
create
Creates a record in the database with the given `RecordID` as the key and the provided content as the value.For more details, check the SurrealQL documentation.
- Parameters:
type
- The class type of the object to createthg
- The RecordId used with the new recordcontent
- The content of the created record- Returns:
- An instance of the specified type
-
create
Creates records in the database with the given table and the provided contents as the values.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- the type of the contents- Parameters:
target
- the target for which the records are createdcontents
- the contents of the created records- Returns:
- a list of Value objects created based on the target and contents
-
create
Creates records in the database with the given table and the provided contents as the values.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- the type of objects to be created- Parameters:
type
- the class of the type to be createdtarget
- the target string used in the creation processcontents
- the contents to be used to create the objects- Returns:
- a list of objects of the specified type
-
insert
Insert records in the database with the given table and the provided contents as the values.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- the type of the contents- Parameters:
target
- the target for which the records are insertedcontents
- the contents of the inserted records- Returns:
- a list of Value objects inserted based on the target and contents
-
insert
Insert records in the database with the given table and the provided contents as the values.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- the type of objects to be inserted- Parameters:
type
- the class of the type to be insertedtarget
- the target string used in the insertion processcontents
- the contents to be used to insert the objects- Returns:
- a list of objects of the specified type
-
insertRelation
Inserts a relation to the specified table using the provided content.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- a type that extends InsertRelation- Parameters:
target
- the table where the relation is to be insertedcontent
- the content to insert as the relation- Returns:
- a Value object representing the inserted relation
-
insertRelation
Inserts a relation of the specified type and table with the provided content.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- the type of the relation that extends InsertRelation- Parameters:
type
- the class object of the type Ttarget
- the target identifier for the relationcontent
- the content to be inserted in the relation- Returns:
- the inserted relation of type T
-
insertRelations
@SafeVarargs public final <T extends InsertRelation> List<Value> insertRelations(String target, T... contents) Inserts relations into the specified table with the provided contents.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- the type of the insert relation- Parameters:
target
- the table into which the relations will be insertedcontents
- the contents of the relations to be inserted- Returns:
- a list of values representing the result of the insert operation
-
insertRelations
@SafeVarargs public final <T extends InsertRelation> List<T> insertRelations(Class<T> type, String target, T... contents) Inserts multiple relations of a specified type into the target.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- the type of InsertRelation- Parameters:
type
- the class type of the InsertRelationtarget
- the table in which the relations are to be insertedcontents
- the array of InsertRelation objects to be inserted- Returns:
- a list of inserted relations of the specified type
-
relate
Establishes a relation between two records identified by `from` and `to` within a specified table.For more details, check the SurrealQL documentation.
- Parameters:
from
- the record identifier from which the relation originatestable
- the name of the table where the relation will be establishedto
- the record identifier to which the relation points- Returns:
- a new
Value
instance representing the relation
-
relate
Establishes and retrieves a relation of a specified type between two records.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- The type of the relation extending Relation.- Parameters:
type
- The class type of the relation.from
- The starting record of the relation.table
- The name of the table that holds the relation.to
- The ending record of the relation.- Returns:
- The established relation of the specified type.
-
relate
Establishes a relationship between two records within a specified table, attaching the provided content to this relationship.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- the type of the content associated with the relation- Parameters:
from
- The record ID that the relationship starts from.table
- The table in which the relationship is being created.to
- The record ID that the relationship points to.content
- The content to attach to the relationship.- Returns:
- A Value object representing the newly created relationship.
-
relate
public <R extends Relation,T> R relate(Class<R> type, RecordId from, String table, RecordId to, T content) Establishes a relation between two records and retrieves it based on the specified relation type.For more details, check the SurrealQL documentation.
- Type Parameters:
R
- the type of the relationT
- the type of the content associated with the relation- Parameters:
type
- the class of the relation typefrom
- the record identifier of the source recordtable
- the name of the table where the relation is to be establishedto
- the record identifier of the target recordcontent
- the content to be associated with the relation- Returns:
- the established relation of the specified type
-
update
Updates the value of a record with the specified content and update type.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- The type of the content to be updated.- Parameters:
thg
- The RecordId of the thing to be updated.upType
- The type of update to be performed.content
- The new content to set for the specified record.- Returns:
- A Value object representing the updated value.
-
update
Updates a record of the specified type and returns the updated record.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- the type of the record- Parameters:
type
- the class type of the record to be updatedthg
- the identifier of the record to be updatedupType
- the type of update operation to be performedcontent
- the new content to update the record with- Returns:
- the updated record of the specified type
-
update
Updates the table with the given content based on the specified update type.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- the type of the content to be used for the update- Parameters:
target
- the table to be updatedupType
- the type of update operation to be performedcontent
- the content to update the target with- Returns:
- an Iterator of Value objects reflecting the updated state of the target
-
update
Updates the specified tables with the given content.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- the type of the content- Parameters:
targets
- an array of strings representing the table identifiers to be updatedupType
- the type of update operation to be performedcontent
- the content to update the targets with; the content can be of any type- Returns:
- an Iterator of Value objects representing the updated values
-
update
Updates the specified table with the provided content and returns an iterator for the updated values.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- the type of the content and the type parameter for the iterator- Parameters:
type
- the class type of the contenttarget
- the table to be updatedupType
- the type of update operation to be performedcontent
- the content to update the target with- Returns:
- an iterator over the updated values
-
update
Updates the specified tables with the given content and returns an iterator over the updated elements of the specified type.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- The type of the elements being updated.- Parameters:
type
- The class type of the elements to be updated.targets
- An array of table identifiers to be updated.upType
- The type of update operation to be performed.content
- The content to update the targets with.- Returns:
- An iterator over the updated elements of the specified type.
-
updateSync
Updates the specified table with the provided content.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- The type of the content to be synchronized.- Parameters:
target
- The table identifier to be updated.upType
- The type of update to be performed, represented by an UpType object.content
- The content to update the target with.- Returns:
- A thread-safe Iterator of Value objects that reflects the updated state.
-
updateSync
Updates the tables using the provided content and update type.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- the type of the content being updated- Parameters:
targets
- an array of strings representing the tables to be updatedupType
- an instance ofUpType
indicating the type of update to be performedcontent
- the content to be used for the update, which will be converted to aValue
- Returns:
- a thread-safe iterator over the updated
Value
objects
-
updateSync
Updates the table with the provided content. The updated resource is then returned as a thread-safe iterator of the specified type.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- the type of the content being updated- Parameters:
type
- the class type of the elements that the returned iterator will containtarget
- the identifier of the table resource to be updatedupType
- the type of update operation to be performedcontent
- the data to update the target resource with- Returns:
- a thread-safe iterator of the specified type containing the updated resource
-
updateSync
Updates the provided tables with the provided content and returns an iterator for the updated values.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- the type of the content being updated- Parameters:
type
- the class type of the contenttargets
- an array of target identifiers to be updatedupType
- the type of update to be performedcontent
- the content to be used for the update- Returns:
- a thread-safe iterator for the updated values
-
upsert
Inserts a new record or updates an existing record with the given content.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- The type of the content.- Parameters:
thg
- The record identifier.upType
- The update type specifying how to handle the upsert.content
- The content to be inserted or updated.- Returns:
- The resulting value after the upsert operation.
-
upsert
Upserts a record and returns the updated or inserted entity.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- The type of the entity to be upserted.- Parameters:
type
- The class type of the entity.thg
- The record identifier.upType
- The type of the update.content
- The content of the entity to be upserted.- Returns:
- The upserted entity of the specified type.
-
upsert
Performs an upsert operation on the specified table with the provided content. The operation type is determined by theUpType
enumeration.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- The type of the content to be upserted.- Parameters:
target
- The target on which the upsert operation is to be performed.upType
- The type of upsert operation to be executed.content
- The content to be upserted.- Returns:
- An iterator over the values resulting from the upsert operation.
-
upsert
Inserts or updates values in the given tables.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- The type of the content to upsert.- Parameters:
targets
- The array of tables to upsert values.upType
- The type specifying the upserting strategy to use.content
- The content to be inserted or updated.- Returns:
- An iterator over the upserted values.
-
upsert
Inserts or updates a record of the specified type with the given content.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- the type of the object to be upserted.- Parameters:
type
- the Class object representing the type of the object.target
- the table identifier where the records should be upserted.upType
- the type of upsert operation to perform.content
- the content of the object to be upserted.- Returns:
- an iterator of the type
T
containing the results of the upsert operation.
-
upsert
Updates or inserts the provided content based on the specified tables and update type.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- The type of the content to upsert.- Parameters:
type
- the Class object representing the type of the object.targets
- An array of target identifiers for the upsert operation.upType
- The type of the upsert operation specifying how to merge the content.content
- The content to be upserted.- Returns:
- An iterator over the result of the upsert operation.
-
upsertSync
Inserts or updates the table with the provided content and returns a thread-safe iterator over the resulting values.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- the type of the content to be upserted- Parameters:
target
- the target identifier where the content will be upsertedupType
- the type of upsert operationcontent
- the content to be upserted- Returns:
- a thread-safe iterator over the resulting values after the upsert operation
-
upsertSync
Performs an upsert (update or insert) operation on the specified tables.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- the type of the record to upsert- Parameters:
targets
- an array of target identifiers to perform the upsert operation onupType
- the type of upsert operation to performcontent
- the content to be upserted- Returns:
- a thread-safe Iterator of the resulting values from the upsert operation
-
upsertSync
Inserts or updates a record and returns an iterator over the result.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- the type of the record to upsert- Parameters:
type
- the class representing the type of the recordtarget
- the target location for the upsert operationupType
- the type of the upsert operationcontent
- the content of the record to be upserted- Returns:
- a thread-safe iterator over the upserted record
-
upsertSync
Performs an upsert operation with the specified content on the given tables.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- The type of the content being upserted and returned iterator's elements.- Parameters:
type
- The class type of the content.targets
- The array of table identifiers on which to perform the upsert operation.upType
- The type of upsert operation to be performed.content
- The content to be upserted.- Returns:
- A thread-safe iterator over the upserted content of the specified type.
-
select
Selects a record by its RecordId and retrieves the corresponding Value.For more details, check the SurrealQL documentation.
- Parameters:
recordId
- the unique identifier of the record to be selected- Returns:
- an Optional containing the Value if the record is found, or an empty Optional if not found
-
select
Selects an instance of the specified type from a record identified by the given RecordId.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- the type of the instance to be selected- Parameters:
type
- the class type of the instance to be selectedrecordId
- the unique identifier of the record from which to select the instance- Returns:
- an Optional containing the selected instance of the specified type if present, otherwise an empty Optional
-
select
Selects values based on the provided RecordIds.For more details, check the SurrealQL documentation.
- Parameters:
things
- an array of RecordId objects to be used in the selection.- Returns:
- a list of Value objects corresponding to the selected RecordIds.
-
select
Selects and retrieves a list of objects of the specified type based on the given record IDs.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- the type of objects to be retrieved- Parameters:
type
- the Class object of the type to be retrievedthings
- an array of RecordId instances identifying the records to be selected- Returns:
- a list of objects of the specified type corresponding to the given record IDs
-
select
Selects and returns an iterator over the values corresponding to the given targets.For more details, check the SurrealQL documentation.
- Parameters:
targets
- A string representing the targets to be selected.- Returns:
- An iterator over the values corresponding to the specified targets.
-
selectSync
Selects and returns a thread-safe iterator to traverse values associated with the given targets.For more details, check the SurrealQL documentation.
- Parameters:
targets
- The specified targets for which values need to be selected.- Returns:
- A thread-safe iterator to traverse the values associated with the specified targets.
-
select
Selects and retrieves an iterator of specified type for given targets.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- The type of objects to be selected.- Parameters:
type
- The class type of the objects to be selected.targets
- A string specifying the targets to select from.- Returns:
- An iterator of the specified type for the selected targets.
-
selectSync
Selects and returns a thread-safe iterator over a collection of objects of the specified type from the given targets.For more details, check the SurrealQL documentation.
- Type Parameters:
T
- the type of objects to be iterated over- Parameters:
type
- the class of the type of objects to be selectedtargets
- the targets from which to select objects- Returns:
- a thread-safe iterator over a collection of objects of the specified type
-
delete
Deletes a record identified by the provided RecordId.For more details, check the SurrealQL documentation.
- Parameters:
recordId
- the identifier of the record to be deleted
-
delete
Deletes the specified records.For more details, check the SurrealQL documentation.
- Parameters:
things
- An array of RecordId objects representing the records to be deleted.
-
delete
Deletes the specified target.For more details, check the SurrealQL documentation.
- Parameters:
target
- the name of the target to be deleted
-
close
public void close()Closes and releases any resources associated with this instance. This method is typically called when the instance is no longer needed. The underlying resources are safely cleaned up.- Specified by:
close
in interfaceAutoCloseable
-