Class: Cassandra::Statements::Prepared
- Inherits:
-
Object
- Object
- Cassandra::Statements::Prepared
- Includes:
- Cassandra::Statement
- Defined in:
- lib/cassandra/statements/prepared.rb
Overview
A prepared statement is created by calling Cassandra::Session#prepare or Cassandra::Session#prepare_async.
Instance Attribute Summary collapse
-
#cql ⇒ String
readonly
Original cql used to prepare this statement.
Instance Method Summary collapse
-
#bind(args = nil) ⇒ Cassandra::Statements::Bound
Creates a statement bound with specific arguments.
-
#execution_info ⇒ Cassandra::Execution::Info
Execution info for PREPARE request.
-
#inspect ⇒ String
A CLI-friendly prepared statement representation.
Instance Attribute Details
#cql ⇒ String (readonly)
Returns original cql used to prepare this statement.
27 28 29 |
# File 'lib/cassandra/statements/prepared.rb', line 27 def cql @cql end |
Instance Method Details
#bind(args = nil) ⇒ Cassandra::Statements::Bound
Creates a statement bound with specific arguments
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/cassandra/statements/prepared.rb', line 55 def bind(args = nil) if args Util.assert_instance_of_one_of([::Array, ::Hash], args) { "args must be an Array or a Hash, #{args.inspect} given" } else args = EMPTY_LIST end if args.is_a?(Hash) args = @params_metadata.map do |(_, _, name, type)| unless args.has_key?(name) name = name.to_sym raise ::ArgumentError, "argument :#{name} must be present in #{args.inspect}, but isn't" unless args.has_key?(name) end args[name] end else Util.assert_equal(@params_metadata.size, args.size) { "expecting exactly #{@params_metadata.size} bind parameters, #{args.size} given" } end params_types = @params_metadata.each_with_index.map do |(_, _, name, type), i| Util.assert_type(type, args[i]) { "argument for #{name.inspect} must be #{type}, #{args[i]} given" } type end return Bound.new(@cql, params_types, @result_metadata, args) if @params_metadata.empty? keyspace, table, _, _ = @params_metadata.first return Bound.new(@cql, params_types, @result_metadata, args, keyspace) unless keyspace && table values = ::Hash.new @params_metadata.zip(args) do |(keyspace, table, column, type), value| values[column] = value end partition_key = @schema.create_partition_key(keyspace, table, values) Bound.new(@cql, params_types, @result_metadata, args, keyspace, partition_key) end |
#execution_info ⇒ Cassandra::Execution::Info
Returns execution info for PREPARE request.
96 97 98 |
# File 'lib/cassandra/statements/prepared.rb', line 96 def execution_info @info ||= Execution::Info.new(@keyspace, @statement, @options, @hosts, @consistency, @retries, @trace_id ? Execution::Trace.new(@trace_id, @client) : nil) end |
#inspect ⇒ String
Returns a CLI-friendly prepared statement representation.
101 102 103 |
# File 'lib/cassandra/statements/prepared.rb', line 101 def inspect "#<#{self.class.name}:0x#{self.object_id.to_s(16)} @cql=#{@cql.inspect}>" end |