cassanity 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. data/Changelog.md +10 -0
  2. data/Gemfile +5 -3
  3. data/README.md +22 -15
  4. data/examples/_shared.rb +5 -1
  5. data/examples/batch.rb +17 -23
  6. data/examples/column_families.rb +12 -13
  7. data/examples/counters.rb +10 -18
  8. data/examples/keyspaces.rb +12 -17
  9. data/examples/select_range.rb +29 -19
  10. data/lib/cassanity/argument_generators/batch.rb +8 -0
  11. data/lib/cassanity/argument_generators/column_family_alter.rb +1 -1
  12. data/lib/cassanity/argument_generators/column_family_create.rb +1 -1
  13. data/lib/cassanity/argument_generators/column_family_delete.rb +2 -22
  14. data/lib/cassanity/argument_generators/column_family_drop.rb +1 -1
  15. data/lib/cassanity/argument_generators/column_family_insert.rb +2 -24
  16. data/lib/cassanity/argument_generators/column_family_select.rb +1 -1
  17. data/lib/cassanity/argument_generators/column_family_truncate.rb +1 -1
  18. data/lib/cassanity/argument_generators/column_family_update.rb +2 -24
  19. data/lib/cassanity/argument_generators/keyspace_create.rb +1 -1
  20. data/lib/cassanity/argument_generators/keyspace_drop.rb +1 -1
  21. data/lib/cassanity/argument_generators/keyspace_use.rb +1 -1
  22. data/lib/cassanity/argument_generators/where_clause.rb +1 -0
  23. data/lib/cassanity/argument_generators/with_clause.rb +12 -6
  24. data/lib/cassanity/client.rb +65 -0
  25. data/lib/cassanity/column_family.rb +70 -17
  26. data/lib/cassanity/connection.rb +8 -0
  27. data/lib/cassanity/decrement.rb +2 -15
  28. data/lib/cassanity/executors/cassandra_cql.rb +37 -11
  29. data/lib/cassanity/increment.rb +2 -15
  30. data/lib/cassanity/instrumentation/log_subscriber.rb +27 -0
  31. data/lib/cassanity/instrumenters/memory.rb +27 -0
  32. data/lib/cassanity/instrumenters/noop.rb +9 -0
  33. data/lib/cassanity/keyspace.rb +42 -6
  34. data/lib/cassanity/operator.rb +9 -0
  35. data/lib/cassanity/range.rb +4 -0
  36. data/lib/cassanity/schema.rb +21 -0
  37. data/lib/cassanity/version.rb +1 -1
  38. data/lib/cassanity.rb +16 -2
  39. data/spec/integration/cassanity/column_family_spec.rb +59 -78
  40. data/spec/integration/cassanity/connection_spec.rb +18 -34
  41. data/spec/integration/cassanity/keyspace_spec.rb +24 -34
  42. data/spec/unit/cassanity/argument_generators/batch_spec.rb +51 -3
  43. data/spec/unit/cassanity/argument_generators/column_family_alter_spec.rb +6 -6
  44. data/spec/unit/cassanity/argument_generators/column_family_create_spec.rb +6 -6
  45. data/spec/unit/cassanity/argument_generators/column_family_delete_spec.rb +5 -5
  46. data/spec/unit/cassanity/argument_generators/column_family_drop_spec.rb +2 -2
  47. data/spec/unit/cassanity/argument_generators/column_family_insert_spec.rb +5 -5
  48. data/spec/unit/cassanity/argument_generators/column_family_select_spec.rb +12 -12
  49. data/spec/unit/cassanity/argument_generators/column_family_truncate_spec.rb +2 -2
  50. data/spec/unit/cassanity/argument_generators/column_family_update_spec.rb +5 -5
  51. data/spec/unit/cassanity/argument_generators/keyspace_create_spec.rb +4 -4
  52. data/spec/unit/cassanity/argument_generators/keyspace_drop_spec.rb +1 -1
  53. data/spec/unit/cassanity/argument_generators/keyspace_use_spec.rb +1 -1
  54. data/spec/unit/cassanity/argument_generators/where_clause_spec.rb +26 -0
  55. data/spec/unit/cassanity/argument_generators/with_clause_spec.rb +26 -0
  56. data/spec/unit/cassanity/client_spec.rb +159 -0
  57. data/spec/unit/cassanity/column_family_spec.rb +64 -17
  58. data/spec/unit/cassanity/connection_spec.rb +8 -0
  59. data/spec/unit/cassanity/executors/cassandra_cql_spec.rb +35 -19
  60. data/spec/unit/cassanity/instrumentors/memory_spec.rb +26 -0
  61. data/spec/unit/cassanity/instrumentors/noop_spec.rb +22 -0
  62. data/spec/unit/cassanity/keyspace_spec.rb +25 -3
  63. data/spec/unit/cassanity/operator_spec.rb +10 -0
  64. data/spec/unit/cassanity/schema_spec.rb +6 -0
  65. data/spec/unit/cassanity_spec.rb +6 -0
  66. metadata +15 -4
data/Changelog.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  Not all changes will be here, but the important ones will be for sure.
4
4
 
5
+ ## 0.4.0
6
+
7
+ * Added Cassanity::Client to make setup easier ([pull request](https://github.com/jnunemaker/cassanity/pull/8))
8
+ * Added easy instrumenting of CQL calls and a log subscriber ([pull request](https://github.com/jnunemaker/cassanity/pull/9))
9
+ * Added prettier inspecting of all the things
10
+ * Added #batch to Keyspace and ColumnFamily [commit](https://github.com/jnunemaker/cassanity/commit/1a6393b)
11
+ * Allow setting default keyspace and column family names when performing a batch
12
+ * Added Cassanity::Range and Cassanity.range shortcuts for range queries. [commit](5834d9e)
13
+ * Allow passing hash as schema instead of forcing Cassanity::Schema instance
14
+
5
15
  ## 0.3.0
6
16
 
7
17
  * Changed [update counter value API](https://github.com/jnunemaker/cassanity/commit/a0f5a76)
data/Gemfile CHANGED
@@ -3,9 +3,11 @@ gemspec
3
3
 
4
4
  gem 'rake'
5
5
  gem 'rspec', '~> 2.8'
6
+ gem 'activesupport', :require => false
6
7
 
7
8
  group(:guard) do
8
- gem 'guard', '~> 1.0.0'
9
- gem 'guard-rspec', '~> 0.6.0'
10
- gem 'guard-bundler', '~> 0.1.0'
9
+ gem 'guard'
10
+ gem 'guard-rspec'
11
+ gem 'guard-bundler'
12
+ gem 'rb-fsevent'
11
13
  end
data/README.md CHANGED
@@ -21,25 +21,16 @@ Or install it yourself as:
21
21
  ```ruby
22
22
  require 'cassanity'
23
23
 
24
- # cassandra-cql connection
25
- client = CassandraCQL::Database.new('127.0.0.1:9160', {
26
- cql_version: '3.0.0',
27
- })
28
-
29
- # what is going to execute the cql queries?
30
- executor = Cassanity::Executors::CassandraCql.new({
31
- client: client,
32
- })
33
-
34
- # setup connection with something that can execute queries
35
- connection = Cassanity::Connection.new({
36
- executor: executor,
37
- })
24
+ # client does the heavy lifting of setting up a cassandra cql database instance,
25
+ # a cassanity executor for that database, and a cassanity connection
26
+ client = Cassanity::Client.new
38
27
 
39
28
  # get keyspace instance
40
- keyspace = connection[:my_app]
29
+ keyspace = client[:my_app]
41
30
 
42
31
  # tell client to use keyspace for future queries
32
+ # this is optional as cassanity always sends the keyspace and column family name
33
+ # whenever they are needed
43
34
  keyspace.use
44
35
 
45
36
  # schema for apps column family
@@ -61,6 +52,22 @@ apps = keyspace.column_family({
61
52
  schema: apps_schema,
62
53
  })
63
54
 
55
+ # you can also just pass a hash for the schema
56
+ apps = keyspace.column_family({
57
+ name: :apps,
58
+ schema: {
59
+ primary_key: :id,
60
+ columns: {
61
+ id: :text,
62
+ name: :text,
63
+ created_at: :timestamp,
64
+ },
65
+ with: {
66
+ comment: 'For storing apps',
67
+ }
68
+ },
69
+ })
70
+
64
71
  # create column family based on name and schema
65
72
  apps.create
66
73
 
data/examples/_shared.rb CHANGED
@@ -2,8 +2,12 @@
2
2
  # Sets up load path for examples and requires some stuff
3
3
  require 'pp'
4
4
  require 'pathname'
5
- require 'logger'
6
5
 
7
6
  root_path = Pathname(__FILE__).dirname.join('..').expand_path
8
7
  lib_path = root_path.join('lib')
9
8
  $:.unshift(lib_path)
9
+
10
+ require 'logger'
11
+ require 'cassanity/instrumentation/log_subscriber'
12
+
13
+ Cassanity::Instrumentation::LogSubscriber.logger = Logger.new(STDOUT, Logger::DEBUG)
data/examples/batch.rb CHANGED
@@ -1,40 +1,34 @@
1
1
  require_relative '_shared'
2
2
  require 'cassanity'
3
3
 
4
- client = CassandraCQL::Database.new('127.0.0.1:9160', {
5
- cql_version: '3.0.0',
4
+ client = Cassanity::Client.new('127.0.0.1:9160', {
5
+ instrumenter: ActiveSupport::Notifications,
6
6
  })
7
7
 
8
- executor = Cassanity::Executors::CassandraCql.new(client: client)
9
-
10
- connection = Cassanity::Connection.new(executor: executor)
11
- keyspace = connection['cassanity_examples']
8
+ keyspace = client['cassanity_examples']
12
9
  keyspace.recreate
13
10
 
14
11
  # setting up the apps column family
15
- apps_schema = Cassanity::Schema.new({
16
- primary_key: :id,
17
- columns: {
18
- id: :text,
19
- name: :text,
12
+ apps = keyspace.column_family('apps', {
13
+ schema: {
14
+ primary_key: :id,
15
+ columns: {
16
+ id: :text,
17
+ name: :text,
18
+ },
20
19
  },
21
20
  })
22
- apps = keyspace.column_family('apps', schema: apps_schema)
23
21
  apps.create
24
22
 
25
- # passing in keyspace and column family names by default
26
- default_arguments = {
27
- keyspace_name: keyspace.name,
28
- name: apps.name,
29
- }
30
-
31
23
  # batch several operations in one network call
32
- connection.batch({
24
+ client.batch({
25
+ keyspace_name: keyspace.name,
26
+ column_family_name: apps.name,
33
27
  modifications: [
34
- [:insert, default_arguments.merge(data: {id: '1', name: 'github'})],
35
- [:insert, default_arguments.merge(data: {id: '2', name: 'gist'})],
36
- [:update, default_arguments.merge(set: {name: 'github.com'}, where: {id: '1'})],
37
- [:delete, default_arguments.merge(where: {id: '2'})],
28
+ [:insert, data: {id: '1', name: 'github'}],
29
+ [:insert, data: {id: '2', name: 'gist'}],
30
+ [:update, set: {name: 'github.com'}, where: {id: '1'}],
31
+ [:delete, where: {id: '2'}],
38
32
  ],
39
33
  })
40
34
 
@@ -1,26 +1,24 @@
1
1
  require_relative '_shared'
2
2
  require 'cassanity'
3
3
 
4
- client = CassandraCQL::Database.new('127.0.0.1:9160', {
5
- cql_version: '3.0.0',
4
+ client = Cassanity::Client.new('127.0.0.1:9160', {
5
+ instrumenter: ActiveSupport::Notifications,
6
6
  })
7
- executor = Cassanity::Executors::CassandraCql.new(client: client)
8
7
 
9
- connection = Cassanity::Connection.new(executor: executor)
10
- keyspace = connection['cassanity_examples']
8
+ keyspace = client['cassanity_examples']
11
9
  keyspace.recreate
12
10
 
13
- apps_schema = Cassanity::Schema.new({
14
- primary_key: :id,
15
- columns: {
16
- id: :text,
17
- name: :text,
11
+ # get an instance of a column family, providing schema means it can create itself
12
+ apps = keyspace.column_family('apps', {
13
+ schema: {
14
+ primary_key: :id,
15
+ columns: {
16
+ id: :text,
17
+ name: :text,
18
+ },
18
19
  },
19
20
  })
20
21
 
21
- # get an instance of a column family, providing schema means it can create itself
22
- apps = keyspace.column_family('apps', schema: apps_schema)
23
-
24
22
  # create column family based on schema
25
23
  apps.create
26
24
 
@@ -65,5 +63,6 @@ begin
65
63
 
66
64
  # All errors inherit from Cassanity::Error so you can catch everything easily
67
65
  rescue Cassanity::Error => e
66
+ puts "\n\nError should be raised here."
68
67
  puts e.inspect
69
68
  end
data/examples/counters.rb CHANGED
@@ -1,31 +1,23 @@
1
1
  require_relative '_shared'
2
2
  require 'cassanity'
3
3
 
4
- client = CassandraCQL::Database.new('127.0.0.1:9160', {
5
- cql_version: '3.0.0',
4
+ client = Cassanity::Client.new('127.0.0.1:9160', {
5
+ instrumenter: ActiveSupport::Notifications,
6
6
  })
7
7
 
8
- executor = Cassanity::Executors::CassandraCql.new({
9
- client: client,
10
- logger: Logger.new(STDOUT),
11
- })
12
-
13
- connection = Cassanity::Connection.new(executor: executor)
14
- keyspace = connection['cassanity_examples']
8
+ keyspace = client['cassanity_examples']
15
9
  keyspace.recreate
16
10
 
17
- rollups_schema = Cassanity::Schema.new({
18
- primary_key: :id,
19
- columns: {
20
- id: :text,
21
- value: :counter,
22
- },
23
- })
24
-
25
11
  # get an instance of a column family, providing schema means it can create itself
26
12
  rollups = keyspace.column_family({
27
13
  name: :rollups,
28
- schema: rollups_schema,
14
+ schema: {
15
+ primary_key: :id,
16
+ columns: {
17
+ id: :text,
18
+ value: :counter,
19
+ },
20
+ },
29
21
  })
30
22
 
31
23
  # create column family based on schema
@@ -1,23 +1,20 @@
1
1
  require_relative '_shared'
2
2
  require 'cassanity'
3
3
 
4
- client = CassandraCQL::Database.new('127.0.0.1:9160', {
5
- cql_version: '3.0.0',
4
+ client = Cassanity::Client.new('127.0.0.1:9160', {
5
+ instrumenter: ActiveSupport::Notifications,
6
6
  })
7
- executor = Cassanity::Executors::CassandraCql.new(client: client)
8
-
9
- connection = Cassanity::Connection.new(executor: executor)
10
7
 
11
8
  # gets instance of keyspace
12
- keyspace = connection['cassanity_examples']
9
+ keyspace = client['cassanity_examples']
13
10
 
14
11
  # or you can do this...
15
- keyspace = connection.keyspace('cassanity_examples')
12
+ keyspace = client.keyspace('cassanity_examples')
16
13
 
17
14
  pp keyspace
18
15
 
19
16
  # you can also provide options
20
- keyspace = connection.keyspace('cassanity_examples', {
17
+ keyspace = client.keyspace('cassanity_examples', {
21
18
  strategy_class: 'SimpleStrategy',
22
19
  strategy_options: {
23
20
  replication_factor: 1,
@@ -37,16 +34,14 @@ keyspace.use
37
34
  apps = keyspace.column_family('apps')
38
35
 
39
36
  # you can also pass a schema so the column family is all knowing
40
- apps_schema = Cassanity::Schema.new({
41
- primary_key: :id,
42
- columns: {
43
- id: :text,
44
- name: :text,
45
- },
46
- })
47
-
48
37
  apps = keyspace.column_family('apps', {
49
- schema: apps_schema,
38
+ schema: {
39
+ primary_key: :id,
40
+ columns: {
41
+ id: :text,
42
+ name: :text,
43
+ },
44
+ },
50
45
  })
51
46
  pp apps
52
47
 
@@ -1,32 +1,24 @@
1
1
  require_relative '_shared'
2
2
  require 'cassanity'
3
3
 
4
- client = CassandraCQL::Database.new('127.0.0.1:9160', {
5
- cql_version: '3.0.0',
4
+ client = Cassanity::Client.new('127.0.0.1:9160', {
5
+ instrumenter: ActiveSupport::Notifications,
6
6
  })
7
7
 
8
- executor = Cassanity::Executors::CassandraCql.new({
9
- client: client,
10
- logger: Logger.new(STDOUT),
11
- })
12
-
13
- connection = Cassanity::Connection.new(executor: executor)
14
- keyspace = connection['cassanity_examples']
8
+ keyspace = client['cassanity_examples']
15
9
  keyspace.recreate
16
10
 
17
- rollups_schema = Cassanity::Schema.new({
18
- primary_key: [:id, :timestamp],
19
- columns: {
20
- id: :text,
21
- timestamp: :int,
22
- value: :counter,
23
- },
24
- })
25
-
26
11
  # get an instance of a column family, providing schema means it can create itself
27
12
  rollups = keyspace.column_family({
28
13
  name: :rollups,
29
- schema: rollups_schema,
14
+ schema: {
15
+ primary_key: [:id, :timestamp],
16
+ columns: {
17
+ id: :text,
18
+ timestamp: :int,
19
+ value: :counter,
20
+ },
21
+ },
30
22
  })
31
23
 
32
24
  # create column family based on schema
@@ -66,6 +58,24 @@ pp rollups.select({
66
58
  }
67
59
  })
68
60
 
61
+ # you can also use cassanity range
62
+ # returns timestamps 1, 2 and 3
63
+ pp rollups.select({
64
+ where: {
65
+ id: :views,
66
+ timestamp: Cassanity::Range.new(1, 3),
67
+ }
68
+ })
69
+
70
+ # or the shortcut for it
71
+ # returns timestamps 1, 2 and 3
72
+ pp rollups.select({
73
+ where: {
74
+ id: :views,
75
+ timestamp: Cassanity.range(1, 3),
76
+ }
77
+ })
78
+
69
79
  # also works with operators
70
80
  # returns 3, 4 and 5
71
81
  pp rollups.select({
@@ -34,6 +34,14 @@ module Cassanity
34
34
  command_name, command_arguments = modification
35
35
  command = @commands.fetch(command_name)
36
36
 
37
+ if args[:column_family_name]
38
+ command_arguments[:column_family_name] ||= args[:column_family_name]
39
+ end
40
+
41
+ if args[:keyspace_name]
42
+ command_arguments[:keyspace_name] ||= args[:keyspace_name]
43
+ end
44
+
37
45
  modification_cql, *modification_variables = command.call(command_arguments)
38
46
  modifications << modification_cql
39
47
  variables.concat(modification_variables)
@@ -11,7 +11,7 @@ module Cassanity
11
11
 
12
12
  # Internal
13
13
  def call(args = {})
14
- name = args.fetch(:name)
14
+ name = args.fetch(:column_family_name)
15
15
  with = args[:with] || {}
16
16
 
17
17
  variables = []
@@ -11,7 +11,7 @@ module Cassanity
11
11
 
12
12
  # Internal
13
13
  def call(args = {})
14
- name = args.fetch(:name)
14
+ name = args.fetch(:column_family_name)
15
15
  schema = args.fetch(:schema)
16
16
  columns = schema.columns
17
17
  primary_keys = schema.primary_keys
@@ -11,29 +11,9 @@ module Cassanity
11
11
  @where_clause = args.fetch(:where_clause) { WhereClause.new }
12
12
  end
13
13
 
14
- # Internal: Converts a Hash of arguments to CQL with bound variables.
15
- #
16
- # args - The Hash of arguments to use.
17
- # :name - The String name of the column family
18
- # :where - The Hash of options to use to filter the delete
19
- # :columns - The Array of columns you would like to delete
20
- # (default is all columns) (optional).
21
- # :using - The Hash of options for the query ie: consistency, ttl,
22
- # and timestamp (default: {}) (optional).
23
- #
24
- # Examples
25
- #
26
- # call({
27
- # name: 'apps',
28
- # where: {
29
- # id: '1',
30
- # },
31
- # })
32
- #
33
- # Returns Array where first element is CQL string and the rest are
34
- # bound values.
14
+ # Internal
35
15
  def call(args = {})
36
- name = args.fetch(:name)
16
+ name = args.fetch(:column_family_name)
37
17
  where = args.fetch(:where)
38
18
  columns = args.fetch(:columns) { [] }
39
19
  using = args[:using]
@@ -4,7 +4,7 @@ module Cassanity
4
4
 
5
5
  # Internal
6
6
  def call(args = {})
7
- name = args.fetch(:name)
7
+ name = args.fetch(:column_family_name)
8
8
 
9
9
  if (keyspace_name = args[:keyspace_name])
10
10
  name = "#{keyspace_name}.#{name}"
@@ -2,31 +2,9 @@ module Cassanity
2
2
  module ArgumentGenerators
3
3
  class ColumnFamilyInsert
4
4
 
5
- # Internal: Converts a Hash of arguments to CQL with bound variables.
6
- #
7
- # args - The Hash of arguments to use.
8
- # :name - The String name of the column family
9
- # :data - The Hash of keys and values to insert
10
- # :using - The Hash of options for the query ie: consistency, ttl,
11
- # and timestamp (optional).
12
- #
13
- # Examples
14
- #
15
- # call({
16
- # name: 'apps',
17
- # data: {id: '1', name: 'GitHub'},
18
- # })
19
- #
20
- # call({
21
- # name: 'apps',
22
- # data: {id: '1', name: 'GitHub'},
23
- # using: {consistency: 'quorum'},
24
- # })
25
- #
26
- # Returns Array where first element is CQL string and the rest are
27
- # bound values.
5
+ # Internal
28
6
  def call(args = {})
29
- name = args.fetch(:name)
7
+ name = args.fetch(:column_family_name)
30
8
  data = args.fetch(:data)
31
9
  using = args[:using] || {}
32
10
  keys = data.keys
@@ -18,7 +18,7 @@ module Cassanity
18
18
  # Internal
19
19
  def call(args = {})
20
20
  select = Array(args.fetch(:select, '*'))
21
- name = args.fetch(:name)
21
+ name = args.fetch(:column_family_name)
22
22
  where = args[:where]
23
23
  using = args[:using]
24
24
  order = args[:order]
@@ -4,7 +4,7 @@ module Cassanity
4
4
 
5
5
  # Internal
6
6
  def call(args = {})
7
- name = args.fetch(:name)
7
+ name = args.fetch(:column_family_name)
8
8
 
9
9
  if (keyspace_name = args[:keyspace_name])
10
10
  name = "#{keyspace_name}.#{name}"
@@ -13,31 +13,9 @@ module Cassanity
13
13
  @where_clause = args.fetch(:where_clause) { WhereClause.new }
14
14
  end
15
15
 
16
- # Internal: Converts a Hash of arguments to CQL with bound variables.
17
- #
18
- # args - The Hash of arguments to use.
19
- # :name - The String name of the column family
20
- # :set - The Hash of data to actually update
21
- # :where - The Hash of options to use to filter the update
22
- # :using - The Hash of options for the query ie: consistency, ttl,
23
- # and timestamp (optional).
24
- #
25
- # Examples
26
- #
27
- # call({
28
- # name: 'apps',
29
- # set: {
30
- # name: 'GitHub',
31
- # },
32
- # where: {
33
- # :id => '1',
34
- # }
35
- # })
36
- #
37
- # Returns Array where first element is CQL string and the rest are
38
- # bound values.
16
+ # Internal
39
17
  def call(args = {})
40
- name = args.fetch(:name)
18
+ name = args.fetch(:column_family_name)
41
19
  set = args.fetch(:set)
42
20
  where = args.fetch(:where)
43
21
  using = args[:using] || {}
@@ -11,7 +11,7 @@ module Cassanity
11
11
  # Internal
12
12
  def call(args = {})
13
13
  options, variables = [], []
14
- name = args.fetch(:name)
14
+ name = args.fetch(:keyspace_name)
15
15
  cql = "CREATE KEYSPACE #{name}"
16
16
 
17
17
  with = {
@@ -4,7 +4,7 @@ module Cassanity
4
4
 
5
5
  # Internal
6
6
  def call(args = {})
7
- name = args.fetch(:name)
7
+ name = args.fetch(:keyspace_name)
8
8
  cql = "DROP KEYSPACE #{name}"
9
9
  [cql]
10
10
  end
@@ -4,7 +4,7 @@ module Cassanity
4
4
 
5
5
  # Internal
6
6
  def call(args = {})
7
- name = args.fetch(:name)
7
+ name = args.fetch(:keyspace_name)
8
8
  cql = "USE #{name}"
9
9
  [cql]
10
10
  end
@@ -4,6 +4,7 @@ require 'cassanity/operators/gt'
4
4
  require 'cassanity/operators/gte'
5
5
  require 'cassanity/operators/lt'
6
6
  require 'cassanity/operators/lte'
7
+ require 'cassanity/range'
7
8
 
8
9
  module Cassanity
9
10
  module ArgumentGenerators
@@ -12,14 +12,20 @@ module Cassanity
12
12
  variables, withs = [], []
13
13
 
14
14
  with.each do |key, value|
15
- if value.is_a?(Hash)
16
- value.each do |sub_key, sub_value|
17
- withs << "#{key}:#{sub_key} = ?"
18
- variables << sub_value
15
+ if key == :compact_storage
16
+ if value
17
+ withs << "COMPACT STORAGE"
19
18
  end
20
19
  else
21
- withs << "#{key} = ?"
22
- variables << value
20
+ if value.is_a?(Hash)
21
+ value.each do |sub_key, sub_value|
22
+ withs << "#{key}:#{sub_key} = ?"
23
+ variables << sub_value
24
+ end
25
+ else
26
+ withs << "#{key} = ?"
27
+ variables << value
28
+ end
23
29
  end
24
30
  end
25
31
 
@@ -0,0 +1,65 @@
1
+ require 'forwardable'
2
+ require 'cassandra-cql'
3
+ require 'cassanity/executors/cassandra_cql'
4
+ require 'cassanity/connection'
5
+
6
+ module Cassanity
7
+ class Client
8
+ extend Forwardable
9
+
10
+ # Public: The instance of the CassandraCQL::Database being used.
11
+ attr_reader :driver
12
+
13
+ # Public: The instance of the Cassanity::Executors::CassandraCQL that will
14
+ # execute all queries.
15
+ attr_reader :executor
16
+
17
+ # Public: The instance of the Cassanity::Connection that is the entry point
18
+ # for all operations.
19
+ attr_reader :connection
20
+
21
+ # Public: Initialize an instance of the client.
22
+ #
23
+ # servers - The String or Array of Strings representing the servers to
24
+ # connect to.
25
+ # options - The Hash of CassandraCQL::Database options.
26
+ # thrift_options - The Hash of CassandraCQL::Database thrift client options.
27
+ def initialize(servers = nil, options = {}, thrift_options = {})
28
+ @servers = servers || '127.0.0.1:9160'
29
+ @options = options.merge(cql_version: '3.0.0')
30
+ @thrift_options = thrift_options.dup
31
+ @instrumenter = @options.delete(:instrumenter)
32
+
33
+ @driver = CassandraCQL::Database.new(@servers, @options, @thrift_options)
34
+
35
+ @executor = Cassanity::Executors::CassandraCql.new({
36
+ client: @driver,
37
+ instrumenter: @instrumenter,
38
+ })
39
+
40
+ @connection = Cassanity::Connection.new({
41
+ executor: @executor,
42
+ })
43
+ end
44
+
45
+ # Methods on client that should be delegated to connection.
46
+ DelegateToConnectionMethods = [
47
+ :keyspaces,
48
+ :keyspace,
49
+ :[],
50
+ :batch,
51
+ ]
52
+
53
+ def_delegators :@connection, *DelegateToConnectionMethods
54
+
55
+ # Public
56
+ def inspect
57
+ attributes = [
58
+ "driver=#{driver.inspect}",
59
+ "executor=#{executor.inspect}",
60
+ "connection=#{connection.inspect}",
61
+ ]
62
+ "#<#{self.class.name}:#{object_id} #{attributes.join(', ')}>"
63
+ end
64
+ end
65
+ end