Class: Ilios::Cassandra::Statement

Inherits:
Object
  • Object
show all
Defined in:
ext/ilios/ilios.c

Instance Method Summary collapse

Instance Method Details

#bind(hash) ⇒ Cassandra::Statement

Binds a specified column value to a query. A hash object should be given with column name as key.

Parameters:

  • hash (Hash)

    A hash object to bind.

Returns:

Raises:

  • (RangeError)

    If an invalid range of values was given.

  • (TypeError)

    If an invalid type of values was given.

  • (Cassandra::StatementError)

    If an invalid column name was given.



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'ext/ilios/statement.c', line 227

static VALUE statement_bind(VALUE self, VALUE hash)
{
    CassandraStatement *cassandra_statement;
    statement_bind_context ctx;
    VALUE bound_values;

    Check_Type(hash, T_HASH);
    TypedData_Get_Struct(self, CassandraStatement, &cassandra_statement_data_type, cassandra_statement);

    // Merge into a copy instead of mutating in place: the previous hash may be
    // shared with a frozen (Ractor-shareable) statement or be iterated by an
    // execution on another thread.
    if (NIL_P(cassandra_statement->bound_values)) {
        bound_values = rb_hash_new();
    } else {
        bound_values = rb_hash_dup(cassandra_statement->bound_values);
    }
    RB_OBJ_WRITE(self, &cassandra_statement->bound_values, bound_values);

    ctx.prepared = cassandra_statement->prepared;
    ctx.statement = cassandra_statement->statement;
    ctx.bound_values = bound_values;

    rb_hash_foreach(hash, hash_cb, (VALUE)&ctx);
    return self;
}

#idempotent=(idempotent) ⇒ Cassandra::Statement

Sets whether the statement is idempotent. Idempotent statements are able to be automatically retried after timeouts/errors and can be speculatively executed. The default is false.

Parameters:

  • idempotent (Boolean)

    Whether the statement is idempotent.

Returns:



278
279
280
281
282
283
284
285
286
# File 'ext/ilios/statement.c', line 278

static VALUE statement_idempotent(VALUE self, VALUE idempotent)
{
    CassandraStatement *cassandra_statement;

    GET_STATEMENT(self, cassandra_statement);
    cassandra_statement->idempotent = RTEST(idempotent) ? idempotency_true : idempotency_false;
    cass_statement_set_is_idempotent(cassandra_statement->statement, cassandra_statement->idempotent == idempotency_true ? cass_true : cass_false);
    return self;
}

#page_size=(page_size) ⇒ Cassandra::Statement

Sets the statement's page size. The default is 10000.

Parameters:

  • page_size (Integer)

    A page size.

Returns:



260
261
262
263
264
265
266
267
268
# File 'ext/ilios/statement.c', line 260

static VALUE statement_page_size(VALUE self, VALUE page_size)
{
    CassandraStatement *cassandra_statement;

    GET_STATEMENT(self, cassandra_statement);
    cassandra_statement->page_size = NUM2INT(page_size);
    cass_statement_set_paging_size(cassandra_statement->statement, cassandra_statement->page_size);
    return self;
}