Class SessionExtensions
Extends ISession with useful methods.
Namespace: Neon.Cassandra
Assembly: Neon.Cassandra.dll
Syntax
public static class SessionExtensions
Methods
ExecuteAsync(ISession, string)
Executes a text command asynchronously.
Declaration
public static Task<RowSet> ExecuteAsync(this ISession session, string cqlText)
Parameters
Type | Name | Description |
---|---|---|
ISession | session | The database session. |
string | cqlText | The command or query text. |
Returns
Type | Description |
---|---|
Task<RowSet> | The resulting RowSet. |
ExecuteBatch(ISession, string)
Executes a batch of SQL commands saeparated by lines including go separators. This works like Microsoft SQL server related tools.
note
The term batch here is different from the usual Cassandra terminology, where batch refers an BatchStatement which may include multiple statements that are executed together atomically. Batch here refers to statements extracted from the text passed and then executed individually.
Sorry for the confusion here, but we used this to be consistent with the our Postgres extensions and frankly, we couldn't think of a better term.
Declaration
public static void ExecuteBatch(this ISession session, string batchText)
Parameters
Type | Name | Description |
---|---|---|
ISession | session | The database session. |
string | batchText | The SQL commands possibly separated by go lines. |
Remarks
It's often necessary to execute a sequence of SQL commands that depend on each other. One example is a command that creates a table followed by commands that write rows. You might think that you could achieve this by executing the following as one command:
CREATE TABLE my_table (name text);
INSERT INTO my_table (name) values ('Jack');
INSERT INTO my_table (name) values ('Jill');
but this won't actually work because the database generates a query plan for the entire command and when it does this and sees the inserts into [my_table] but the table doesn't actually exist at the time the query plan is being created. So the command will fail.
What you really need to do is create the table first as a separate command and then do the inserts as one or more subsequent commands. This is not terribly convenient so we've introduced the concept of a batch of commands via this method. Here's what this would look like:
CREATE TABLE my_table (name text);
go
INSERT INTO my_table (name) values ('Jack');
INSERT INTO my_table (name) values ('Jill');
See how the go line separates the table creation from the inserts.
This method will split the batchText
into separate
commands on any go lines and then execute these commands in order.
note
go is case insensitive and any leading or trailing space on the line will be ignored.
ExecuteBatchAsync(ISession, string)
Asynchronously a batch of SQL commands saeparated by lines including go separators. This works like Microsoft SQL server related tools.
note
The term batch here is different from the usual Cassandra terminology, where batch refers an BatchStatement which may include multiple statements that are executed together atomically. Batch here refers to statements extracted from the text passed and then executed individually.
Sorry for the confusion here, but we used this to be consistent with the our Postgres extensions and frankly, we couldn't think of a better term.
Declaration
public static Task ExecuteBatchAsync(this ISession session, string batchText)
Parameters
Type | Name | Description |
---|---|---|
ISession | session | The database session. |
string | batchText | The SQL commands possibly separated by go lines. |
Returns
Type | Description |
---|---|
Task | The tracking Task. |
Remarks
note
This method doesn't actually execute the statements asynchronously because the Cassandra driver doesn't include an ISession.ExecuteAsync(string) method. This method simply calls ExecuteBatch(ISession, string). We're retaining this method for compatibility with our Postgres extensions.
It's often necessary to execute a sequence of SQL commands that depend on each other. One example is a command that creates a table followed by commands that write rows. You might think that you could achieve this by executing the following as one command:
CREATE TABLE my_table (name text);
INSERT INTO my_table (name) values ('Jack');
INSERT INTO my_table (name) values ('Jill');
but this won't actually work because the database generates a query plan for the entire command and when it does this and sees the inserts into [my_table] but the table doesn't actually exist at the time the query plan is being created. So the command will fail.
What you really need to do is create the table first as a separate command and then do the inserts as one or more subsequent commands. This is not terribly convenient so we've introduced the concept of a batch of commands via this method. Here's what this would look like:
CREATE TABLE my_table (name text);
go
INSERT INTO my_table (name) values ('Jack');
INSERT INTO my_table (name) values ('Jill');
See how the go line separates the table creation from the inserts.
This method will split the batchText
into separate
commands on any go lines and then execute these commands in order.
note
go is case insensitive and any leading or trailing space on the line will be ignored.