query_builder 0.0.1
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.
- checksums.yaml +7 -0
- data/.coveralls.yml +2 -0
- data/.gitignore +9 -0
- data/.metrics +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +2 -0
- data/.travis.yml +25 -0
- data/.yardopts +3 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +7 -0
- data/Guardfile +14 -0
- data/LICENSE +21 -0
- data/README.md +95 -0
- data/Rakefile +34 -0
- data/config/metrics/STYLEGUIDE +230 -0
- data/config/metrics/cane.yml +5 -0
- data/config/metrics/churn.yml +6 -0
- data/config/metrics/flay.yml +2 -0
- data/config/metrics/metric_fu.yml +14 -0
- data/config/metrics/reek.yml +1 -0
- data/config/metrics/roodi.yml +24 -0
- data/config/metrics/rubocop.yml +80 -0
- data/config/metrics/saikuro.yml +3 -0
- data/config/metrics/simplecov.yml +6 -0
- data/config/metrics/yardstick.yml +37 -0
- data/lib/query_builder.rb +9 -0
- data/lib/query_builder/core.rb +19 -0
- data/lib/query_builder/core/attribute.rb +54 -0
- data/lib/query_builder/core/attribute_error.rb +25 -0
- data/lib/query_builder/core/base.rb +102 -0
- data/lib/query_builder/core/clause.rb +46 -0
- data/lib/query_builder/core/statement.rb +55 -0
- data/lib/query_builder/cql.rb +80 -0
- data/lib/query_builder/cql/contexts.rb +21 -0
- data/lib/query_builder/cql/contexts/aggregate.rb +42 -0
- data/lib/query_builder/cql/contexts/column.rb +59 -0
- data/lib/query_builder/cql/contexts/field.rb +48 -0
- data/lib/query_builder/cql/contexts/function.rb +46 -0
- data/lib/query_builder/cql/contexts/index.rb +44 -0
- data/lib/query_builder/cql/contexts/keyspace.rb +107 -0
- data/lib/query_builder/cql/contexts/permission.rb +59 -0
- data/lib/query_builder/cql/contexts/role.rb +51 -0
- data/lib/query_builder/cql/contexts/table.rb +140 -0
- data/lib/query_builder/cql/contexts/trigger.rb +42 -0
- data/lib/query_builder/cql/contexts/type.rb +52 -0
- data/lib/query_builder/cql/contexts/user.rb +53 -0
- data/lib/query_builder/cql/modifiers.rb +61 -0
- data/lib/query_builder/cql/modifiers/add_column.rb +50 -0
- data/lib/query_builder/cql/modifiers/add_field.rb +49 -0
- data/lib/query_builder/cql/modifiers/allow_filtering.rb +45 -0
- data/lib/query_builder/cql/modifiers/alter.rb +44 -0
- data/lib/query_builder/cql/modifiers/called_on_null.rb +47 -0
- data/lib/query_builder/cql/modifiers/clustering_order.rb +51 -0
- data/lib/query_builder/cql/modifiers/column.rb +59 -0
- data/lib/query_builder/cql/modifiers/compact_storage.rb +46 -0
- data/lib/query_builder/cql/modifiers/count.rb +47 -0
- data/lib/query_builder/cql/modifiers/counter.rb +45 -0
- data/lib/query_builder/cql/modifiers/delete.rb +48 -0
- data/lib/query_builder/cql/modifiers/distinct.rb +45 -0
- data/lib/query_builder/cql/modifiers/finalfunc.rb +47 -0
- data/lib/query_builder/cql/modifiers/if.rb +44 -0
- data/lib/query_builder/cql/modifiers/if_exists.rb +46 -0
- data/lib/query_builder/cql/modifiers/if_not_exists.rb +46 -0
- data/lib/query_builder/cql/modifiers/initcond.rb +49 -0
- data/lib/query_builder/cql/modifiers/insert.rb +68 -0
- data/lib/query_builder/cql/modifiers/limit.rb +49 -0
- data/lib/query_builder/cql/modifiers/norecursive.rb +45 -0
- data/lib/query_builder/cql/modifiers/or_replace.rb +44 -0
- data/lib/query_builder/cql/modifiers/order.rb +50 -0
- data/lib/query_builder/cql/modifiers/password.rb +49 -0
- data/lib/query_builder/cql/modifiers/primary_key.rb +51 -0
- data/lib/query_builder/cql/modifiers/returns.rb +49 -0
- data/lib/query_builder/cql/modifiers/selected.rb +54 -0
- data/lib/query_builder/cql/modifiers/sfunc.rb +47 -0
- data/lib/query_builder/cql/modifiers/statement.rb +47 -0
- data/lib/query_builder/cql/modifiers/stype.rb +47 -0
- data/lib/query_builder/cql/modifiers/superuser.rb +54 -0
- data/lib/query_builder/cql/modifiers/timestamp.rb +50 -0
- data/lib/query_builder/cql/modifiers/unlogged.rb +45 -0
- data/lib/query_builder/cql/modifiers/update.rb +44 -0
- data/lib/query_builder/cql/modifiers/using.rb +48 -0
- data/lib/query_builder/cql/modifiers/using_options.rb +51 -0
- data/lib/query_builder/cql/modifiers/where.rb +44 -0
- data/lib/query_builder/cql/modifiers/where_clustered.rb +51 -0
- data/lib/query_builder/cql/modifiers/with.rb +44 -0
- data/lib/query_builder/cql/modifiers/with_options.rb +42 -0
- data/lib/query_builder/cql/operators.rb +29 -0
- data/lib/query_builder/cql/operators/cql.rb +23 -0
- data/lib/query_builder/cql/operators/cql_composite.rb +20 -0
- data/lib/query_builder/cql/operators/cql_dec.rb +21 -0
- data/lib/query_builder/cql/operators/cql_element.rb +23 -0
- data/lib/query_builder/cql/operators/cql_entries.rb +20 -0
- data/lib/query_builder/cql/operators/cql_frozen.rb +20 -0
- data/lib/query_builder/cql/operators/cql_full.rb +20 -0
- data/lib/query_builder/cql/operators/cql_gt.rb +23 -0
- data/lib/query_builder/cql/operators/cql_gte.rb +23 -0
- data/lib/query_builder/cql/operators/cql_in.rb +23 -0
- data/lib/query_builder/cql/operators/cql_inc.rb +21 -0
- data/lib/query_builder/cql/operators/cql_keys.rb +20 -0
- data/lib/query_builder/cql/operators/cql_list.rb +21 -0
- data/lib/query_builder/cql/operators/cql_literal.rb +84 -0
- data/lib/query_builder/cql/operators/cql_lt.rb +23 -0
- data/lib/query_builder/cql/operators/cql_lte.rb +23 -0
- data/lib/query_builder/cql/operators/cql_map.rb +25 -0
- data/lib/query_builder/cql/operators/cql_set.rb +21 -0
- data/lib/query_builder/cql/operators/cql_token.rb +21 -0
- data/lib/query_builder/cql/operators/cql_token_value.rb +23 -0
- data/lib/query_builder/cql/operators/cql_ttl.rb +20 -0
- data/lib/query_builder/cql/operators/cql_tuple.rb +21 -0
- data/lib/query_builder/cql/operators/cql_tuple_value.rb +23 -0
- data/lib/query_builder/cql/operators/cql_writetime.rb +20 -0
- data/lib/query_builder/cql/statements.rb +25 -0
- data/lib/query_builder/cql/statements/alter_column.rb +27 -0
- data/lib/query_builder/cql/statements/alter_field.rb +27 -0
- data/lib/query_builder/cql/statements/alter_keyspace.rb +25 -0
- data/lib/query_builder/cql/statements/alter_role.rb +26 -0
- data/lib/query_builder/cql/statements/alter_table.rb +25 -0
- data/lib/query_builder/cql/statements/alter_user.rb +26 -0
- data/lib/query_builder/cql/statements/batch.rb +31 -0
- data/lib/query_builder/cql/statements/create_aggregate.rb +36 -0
- data/lib/query_builder/cql/statements/create_column.rb +35 -0
- data/lib/query_builder/cql/statements/create_field.rb +25 -0
- data/lib/query_builder/cql/statements/create_function.rb +38 -0
- data/lib/query_builder/cql/statements/create_index.rb +41 -0
- data/lib/query_builder/cql/statements/create_keyspace.rb +26 -0
- data/lib/query_builder/cql/statements/create_role.rb +26 -0
- data/lib/query_builder/cql/statements/create_table.rb +30 -0
- data/lib/query_builder/cql/statements/create_trigger.rb +29 -0
- data/lib/query_builder/cql/statements/create_type.rb +26 -0
- data/lib/query_builder/cql/statements/create_user.rb +27 -0
- data/lib/query_builder/cql/statements/delete.rb +32 -0
- data/lib/query_builder/cql/statements/drop_aggregate.rb +25 -0
- data/lib/query_builder/cql/statements/drop_column.rb +23 -0
- data/lib/query_builder/cql/statements/drop_function.rb +25 -0
- data/lib/query_builder/cql/statements/drop_index.rb +25 -0
- data/lib/query_builder/cql/statements/drop_keyspace.rb +25 -0
- data/lib/query_builder/cql/statements/drop_role.rb +25 -0
- data/lib/query_builder/cql/statements/drop_table.rb +25 -0
- data/lib/query_builder/cql/statements/drop_trigger.rb +25 -0
- data/lib/query_builder/cql/statements/drop_type.rb +25 -0
- data/lib/query_builder/cql/statements/drop_user.rb +25 -0
- data/lib/query_builder/cql/statements/grant.rb +31 -0
- data/lib/query_builder/cql/statements/insert.rb +27 -0
- data/lib/query_builder/cql/statements/list_permissions.rb +35 -0
- data/lib/query_builder/cql/statements/list_roles.rb +23 -0
- data/lib/query_builder/cql/statements/list_users.rb +23 -0
- data/lib/query_builder/cql/statements/rename_column.rb +27 -0
- data/lib/query_builder/cql/statements/rename_field.rb +25 -0
- data/lib/query_builder/cql/statements/revoke.rb +31 -0
- data/lib/query_builder/cql/statements/select.rb +35 -0
- data/lib/query_builder/cql/statements/truncate.rb +23 -0
- data/lib/query_builder/cql/statements/update.rb +31 -0
- data/lib/query_builder/cql/statements/use.rb +23 -0
- data/lib/query_builder/rspec.rb +25 -0
- data/lib/query_builder/version.rb +9 -0
- data/query_builder.gemspec +31 -0
- data/spec/integration/alter_keyspace_spec.rb +17 -0
- data/spec/integration/alter_role_spec.rb +28 -0
- data/spec/integration/alter_table_add_spec.rb +21 -0
- data/spec/integration/alter_table_alter_spec.rb +15 -0
- data/spec/integration/alter_table_drop_spec.rb +15 -0
- data/spec/integration/alter_table_rename_spec.rb +15 -0
- data/spec/integration/alter_table_with_spec.rb +17 -0
- data/spec/integration/alter_type_add_spec.rb +15 -0
- data/spec/integration/alter_type_alter_spec.rb +15 -0
- data/spec/integration/alter_type_rename_spec.rb +15 -0
- data/spec/integration/alter_user_spec.rb +28 -0
- data/spec/integration/batch_spec.rb +32 -0
- data/spec/integration/create_aggregate_spec.rb +31 -0
- data/spec/integration/create_function_spec.rb +29 -0
- data/spec/integration/create_index_spec.rb +35 -0
- data/spec/integration/create_keyspace_spec.rb +24 -0
- data/spec/integration/create_role_spec.rb +26 -0
- data/spec/integration/create_table_spec.rb +34 -0
- data/spec/integration/create_trigger_spec.rb +21 -0
- data/spec/integration/create_type_spec.rb +20 -0
- data/spec/integration/create_user_spec.rb +23 -0
- data/spec/integration/delete_spec.rb +28 -0
- data/spec/integration/drop_aggregate_spec.rb +21 -0
- data/spec/integration/drop_function_spec.rb +21 -0
- data/spec/integration/drop_index_spec.rb +21 -0
- data/spec/integration/drop_keyspace_spec.rb +18 -0
- data/spec/integration/drop_role_spec.rb +18 -0
- data/spec/integration/drop_table_spec.rb +18 -0
- data/spec/integration/drop_trigger_spec.rb +21 -0
- data/spec/integration/drop_type_spec.rb +18 -0
- data/spec/integration/drop_user_spec.rb +18 -0
- data/spec/integration/grant_spec.rb +29 -0
- data/spec/integration/insert_spec.rb +22 -0
- data/spec/integration/list_permissions_spec.rb +34 -0
- data/spec/integration/list_roles_spec.rb +12 -0
- data/spec/integration/list_users_spec.rb +12 -0
- data/spec/integration/revoke_spec.rb +29 -0
- data/spec/integration/select_spec.rb +46 -0
- data/spec/integration/truncate_spec.rb +12 -0
- data/spec/integration/update_spec.rb +23 -0
- data/spec/integration/use_spec.rb +12 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/unit/core/attribute_error_spec.rb +38 -0
- data/spec/unit/core/attribute_spec.rb +70 -0
- data/spec/unit/core/base_spec.rb +110 -0
- data/spec/unit/core/clause_spec.rb +101 -0
- data/spec/unit/core/statement_spec.rb +88 -0
- data/spec/unit/cql/operators/cql_composite_spec.rb +12 -0
- data/spec/unit/cql/operators/cql_dec_spec.rb +12 -0
- data/spec/unit/cql/operators/cql_element_spec.rb +12 -0
- data/spec/unit/cql/operators/cql_entries_spec.rb +12 -0
- data/spec/unit/cql/operators/cql_frozen_spec.rb +12 -0
- data/spec/unit/cql/operators/cql_full_spec.rb +12 -0
- data/spec/unit/cql/operators/cql_gt_spec.rb +19 -0
- data/spec/unit/cql/operators/cql_gte_spec.rb +19 -0
- data/spec/unit/cql/operators/cql_in_spec.rb +12 -0
- data/spec/unit/cql/operators/cql_inc_spec.rb +12 -0
- data/spec/unit/cql/operators/cql_keys_spec.rb +12 -0
- data/spec/unit/cql/operators/cql_list_spec.rb +12 -0
- data/spec/unit/cql/operators/cql_literal_spec.rb +83 -0
- data/spec/unit/cql/operators/cql_lt_spec.rb +19 -0
- data/spec/unit/cql/operators/cql_lte_spec.rb +19 -0
- data/spec/unit/cql/operators/cql_map_spec.rb +12 -0
- data/spec/unit/cql/operators/cql_set_spec.rb +12 -0
- data/spec/unit/cql/operators/cql_spec.rb +12 -0
- data/spec/unit/cql/operators/cql_token_spec.rb +12 -0
- data/spec/unit/cql/operators/cql_token_value_spec.rb +12 -0
- data/spec/unit/cql/operators/cql_ttl_spec.rb +12 -0
- data/spec/unit/cql/operators/cql_tuple_spec.rb +12 -0
- data/spec/unit/cql/operators/cql_tuple_value_spec.rb +12 -0
- data/spec/unit/cql/operators/cql_writetime_spec.rb +12 -0
- data/spec/unit/cql/operators_spec.rb +66 -0
- metadata +405 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module QueryBuilder::Core
|
|
4
|
+
|
|
5
|
+
# Abstract base class for CQL statemens (roots of AST)
|
|
6
|
+
#
|
|
7
|
+
# The statement can belong to some context (keyspace, table).
|
|
8
|
+
# It is created with several clauses (like WHERE, SET etc.)
|
|
9
|
+
#
|
|
10
|
+
# @abstract
|
|
11
|
+
#
|
|
12
|
+
class Statement < Base
|
|
13
|
+
|
|
14
|
+
attribute :context, default: nil
|
|
15
|
+
|
|
16
|
+
# @!method initialize(type, *attributes, &block)
|
|
17
|
+
# Initializes the statement with a type, attributes and block
|
|
18
|
+
#
|
|
19
|
+
# @param (see QueryBuilder::Clause)
|
|
20
|
+
# @param [Proc] block
|
|
21
|
+
# The block that returns an array of clauses for the statement
|
|
22
|
+
#
|
|
23
|
+
def initialize(*)
|
|
24
|
+
@clauses = block_given? ? Array[*yield] : []
|
|
25
|
+
super
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# @!method clauses(type = nil)
|
|
29
|
+
# Returns array of chunks of code for the statement's clauses
|
|
30
|
+
#
|
|
31
|
+
# @param [Symbol] type The optional type to select clauses by
|
|
32
|
+
#
|
|
33
|
+
# @return [Array<String>]
|
|
34
|
+
#
|
|
35
|
+
def clauses(cond = nil)
|
|
36
|
+
(cond ? @clauses.select { |item| cond.equal? item.type } : @clauses)
|
|
37
|
+
.map(&:to_s)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# @!method <<(clause)
|
|
41
|
+
# Returns a new statement where the clause is added
|
|
42
|
+
#
|
|
43
|
+
# @param [QueryBuilder::Clause] clause
|
|
44
|
+
#
|
|
45
|
+
# @return [QueryBuilder::Statement]
|
|
46
|
+
#
|
|
47
|
+
def <<(clause)
|
|
48
|
+
new_clauses = @clauses.dup
|
|
49
|
+
new_clauses.delete clause
|
|
50
|
+
self.class.new(attributes) { new_clauses + [clause] }
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end # class Statement
|
|
54
|
+
|
|
55
|
+
end # module QueryBuilder::Core
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module QueryBuilder
|
|
4
|
+
|
|
5
|
+
require_relative "cql/operators"
|
|
6
|
+
require_relative "cql/contexts"
|
|
7
|
+
require_relative "cql/modifiers"
|
|
8
|
+
require_relative "cql/statements"
|
|
9
|
+
|
|
10
|
+
# The builder for CQL-specific statements
|
|
11
|
+
#
|
|
12
|
+
module CQL
|
|
13
|
+
|
|
14
|
+
# Returns the context of Cassandra keyspace
|
|
15
|
+
#
|
|
16
|
+
# @param [#to_s] name The name of the keyspace
|
|
17
|
+
#
|
|
18
|
+
# @param [QueryBuilder::CQL::Contexts::Keyspace]
|
|
19
|
+
#
|
|
20
|
+
def self.keyspace(name)
|
|
21
|
+
Contexts::Keyspace.new(name: name)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Returns the context of Cassandra user
|
|
25
|
+
#
|
|
26
|
+
# @param [#to_s] name The name of the user
|
|
27
|
+
#
|
|
28
|
+
# @param [QueryBuilder::CQL::Contexts::User]
|
|
29
|
+
#
|
|
30
|
+
def self.user(name)
|
|
31
|
+
Contexts::User.new(name: name)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Returns the context of Cassandra users role
|
|
35
|
+
#
|
|
36
|
+
# @param [#to_s] name The name of the role
|
|
37
|
+
#
|
|
38
|
+
# @param [QueryBuilder::CQL::Contexts::Role]
|
|
39
|
+
#
|
|
40
|
+
def self.role(name)
|
|
41
|
+
Contexts::Role.new(name: name)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Returns the context of Cassandra root permission
|
|
45
|
+
#
|
|
46
|
+
# @param [#to_s, nil] name The name of the permission
|
|
47
|
+
#
|
|
48
|
+
# @param [QueryBuilder::CQL::Contexts::Permission]
|
|
49
|
+
#
|
|
50
|
+
def self.permission(name = nil)
|
|
51
|
+
Contexts::Permission.new(name: name)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Builds the 'LIST USERS' CQL statement
|
|
55
|
+
#
|
|
56
|
+
# @return [QueryBuilder::Statements::ListUsers]
|
|
57
|
+
#
|
|
58
|
+
def self.users
|
|
59
|
+
Statements::ListUsers.new
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Builds the 'LIST ROLES' CQL statement
|
|
63
|
+
#
|
|
64
|
+
# @return [QueryBuilder::Statements::ListRoles]
|
|
65
|
+
#
|
|
66
|
+
def self.roles
|
|
67
|
+
Statements::ListRoles.new
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Builds the 'BATCH' CQL statement
|
|
71
|
+
#
|
|
72
|
+
# @return [QueryBuilder::Statements::Batch]
|
|
73
|
+
#
|
|
74
|
+
def self.batch
|
|
75
|
+
Statements::Batch.new
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
end # module CQL
|
|
79
|
+
|
|
80
|
+
end # module QueryBuilder
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module QueryBuilder
|
|
4
|
+
|
|
5
|
+
module CQL
|
|
6
|
+
|
|
7
|
+
# The collection of CQL-specific contexts for statements
|
|
8
|
+
#
|
|
9
|
+
module Contexts
|
|
10
|
+
|
|
11
|
+
# The base class for CQL-specific contexts
|
|
12
|
+
#
|
|
13
|
+
Base = Core::Base
|
|
14
|
+
|
|
15
|
+
Dir[File.expand_path("../contexts/*.rb", __FILE__)].each(&method(:load))
|
|
16
|
+
|
|
17
|
+
end # module Contexts
|
|
18
|
+
|
|
19
|
+
end # module CQL
|
|
20
|
+
|
|
21
|
+
end # module QueryBuilder
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module QueryBuilder::CQL
|
|
4
|
+
|
|
5
|
+
module Contexts
|
|
6
|
+
|
|
7
|
+
# Describes the Cassandra user-defined aggregate
|
|
8
|
+
#
|
|
9
|
+
class Aggregate < Base
|
|
10
|
+
|
|
11
|
+
attribute :keyspace, required: true
|
|
12
|
+
attribute :name, required: true
|
|
13
|
+
|
|
14
|
+
# Returns the full name of the aggregate
|
|
15
|
+
#
|
|
16
|
+
# @return [String]
|
|
17
|
+
#
|
|
18
|
+
def to_s
|
|
19
|
+
[keyspace, name].join(".")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Builds the 'CREATE AGGREGATE' CQL statement
|
|
23
|
+
#
|
|
24
|
+
# @return [QueryBuilder::Statements::CreateAggregate]
|
|
25
|
+
#
|
|
26
|
+
def create
|
|
27
|
+
Statements::CreateAggregate.new(context: self)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Builds the 'DROP AGGREGATE' CQL statement
|
|
31
|
+
#
|
|
32
|
+
# @return [QueryBuilder::Statements::DropAggregate]
|
|
33
|
+
#
|
|
34
|
+
def drop
|
|
35
|
+
Statements::DropAggregate.new(context: self)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
end # class Aggregate
|
|
39
|
+
|
|
40
|
+
end # module Contexts
|
|
41
|
+
|
|
42
|
+
end # module QueryBuilder::CQL
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module QueryBuilder::CQL
|
|
4
|
+
|
|
5
|
+
module Contexts
|
|
6
|
+
|
|
7
|
+
# Describes the Cassandra table column
|
|
8
|
+
#
|
|
9
|
+
class Column < Base
|
|
10
|
+
|
|
11
|
+
attribute :table, required: true
|
|
12
|
+
attribute :name, required: true
|
|
13
|
+
|
|
14
|
+
# Builds the 'ALTER TABLE ... ADD' CQL statement
|
|
15
|
+
#
|
|
16
|
+
# @param [#to_s] type
|
|
17
|
+
# @param [Hash] options
|
|
18
|
+
# @option options [Boolean] :static
|
|
19
|
+
#
|
|
20
|
+
# @return [QueryBuilder::Statements::AddColumn]
|
|
21
|
+
#
|
|
22
|
+
def create(type, options = {})
|
|
23
|
+
Statements::CreateColumn
|
|
24
|
+
.new(context: self, type: type, static: options[:static])
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Builds the 'ALTER TABLE ... RENAME' CQL statement
|
|
28
|
+
#
|
|
29
|
+
# @param [#to_s] name
|
|
30
|
+
#
|
|
31
|
+
# @return [QueryBuilder::Statements::RenameColumn]
|
|
32
|
+
#
|
|
33
|
+
def rename(name)
|
|
34
|
+
Statements::RenameColumn.new(context: self, name: name)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Builds the 'ALTER TABLE ... ALTER' CQL statement
|
|
38
|
+
#
|
|
39
|
+
# @param [#to_s] type
|
|
40
|
+
#
|
|
41
|
+
# @return [QueryBuilder::Statements::AlterColumn]
|
|
42
|
+
#
|
|
43
|
+
def alter(type)
|
|
44
|
+
Statements::AlterColumn.new(context: self, type: type)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Builds the 'ALTER TABLE ... DROP' CQL statement
|
|
48
|
+
#
|
|
49
|
+
# @return [QueryBuilder::Statements::DropColumn]
|
|
50
|
+
#
|
|
51
|
+
def drop
|
|
52
|
+
Statements::DropColumn.new(context: self)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end # class Column
|
|
56
|
+
|
|
57
|
+
end # module Contexts
|
|
58
|
+
|
|
59
|
+
end # module QueryBuilder::CQL
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module QueryBuilder::CQL
|
|
4
|
+
|
|
5
|
+
module Contexts
|
|
6
|
+
|
|
7
|
+
# Describes the field of Cassandra user-defined type
|
|
8
|
+
#
|
|
9
|
+
class Field < Base
|
|
10
|
+
|
|
11
|
+
attribute :type, required: true
|
|
12
|
+
attribute :name, required: true
|
|
13
|
+
|
|
14
|
+
# Builds the 'ALTER TYPE ... ADD' CQL statement
|
|
15
|
+
#
|
|
16
|
+
# @param [#to_s] type
|
|
17
|
+
#
|
|
18
|
+
# @return [QueryBuilder::Statements::CreateField]
|
|
19
|
+
#
|
|
20
|
+
def create(type)
|
|
21
|
+
Statements::CreateField.new(context: self, type: type)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Builds the 'ALTER TYPE ... ALTER' CQL statement
|
|
25
|
+
#
|
|
26
|
+
# @param [#to_s] type
|
|
27
|
+
#
|
|
28
|
+
# @return [QueryBuilder::Statements::AlterField]
|
|
29
|
+
#
|
|
30
|
+
def alter(type)
|
|
31
|
+
Statements::AlterField.new(context: self, type: type)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Builds the 'ALTER TYPE ... RENAME' CQL statement
|
|
35
|
+
#
|
|
36
|
+
# @param [#to_s] name
|
|
37
|
+
#
|
|
38
|
+
# @return [QueryBuilder::Statements::RenameField]
|
|
39
|
+
#
|
|
40
|
+
def rename(name)
|
|
41
|
+
Statements::RenameField.new(context: self, name: name)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end # class Field
|
|
45
|
+
|
|
46
|
+
end # module Contexts
|
|
47
|
+
|
|
48
|
+
end # module QueryBuilder::CQL
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module QueryBuilder::CQL
|
|
4
|
+
|
|
5
|
+
module Contexts
|
|
6
|
+
|
|
7
|
+
# Describes the Cassandra user-defined function
|
|
8
|
+
#
|
|
9
|
+
class Function < Base
|
|
10
|
+
|
|
11
|
+
attribute :keyspace, required: true
|
|
12
|
+
attribute :name, required: true
|
|
13
|
+
|
|
14
|
+
# Returns the full name of the function
|
|
15
|
+
#
|
|
16
|
+
# @return [String]
|
|
17
|
+
#
|
|
18
|
+
def to_s
|
|
19
|
+
[keyspace, name].join(".")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Builds the 'CREATE FUNCTION' CQL statement
|
|
23
|
+
#
|
|
24
|
+
# @param [#to_s] language
|
|
25
|
+
# @param [#to_s] body
|
|
26
|
+
#
|
|
27
|
+
# @return [QueryBuilder::Statements::CreateFunction]
|
|
28
|
+
#
|
|
29
|
+
def create(language, body)
|
|
30
|
+
Statements::CreateFunction
|
|
31
|
+
.new(context: self, language: language, body: body)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Builds the 'DROP FUNCTION' CQL statement
|
|
35
|
+
#
|
|
36
|
+
# @return [QueryBuilder::Statements::DropFunction]
|
|
37
|
+
#
|
|
38
|
+
def drop
|
|
39
|
+
Statements::DropFunction.new(context: self)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
end # class Function
|
|
43
|
+
|
|
44
|
+
end # module Contexts
|
|
45
|
+
|
|
46
|
+
end # module QueryBuilder::CQL
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module QueryBuilder::CQL
|
|
4
|
+
|
|
5
|
+
module Contexts
|
|
6
|
+
|
|
7
|
+
# Describes the Cassandra table index
|
|
8
|
+
#
|
|
9
|
+
class Index < Base
|
|
10
|
+
|
|
11
|
+
attribute :table, required: true
|
|
12
|
+
attribute :name
|
|
13
|
+
|
|
14
|
+
# <description>
|
|
15
|
+
#
|
|
16
|
+
# @return [<type>] <description>
|
|
17
|
+
#
|
|
18
|
+
def to_s
|
|
19
|
+
[table.keyspace.name, name].join(".")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Builds the 'CREATE INDEX' CQL statement for the current table
|
|
23
|
+
#
|
|
24
|
+
# @param [Hash] options
|
|
25
|
+
#
|
|
26
|
+
# @return [QueryBuilder::Statements::CreateIndex]
|
|
27
|
+
#
|
|
28
|
+
def create(*options)
|
|
29
|
+
Statements::CreateIndex.new(context: self).add(options)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Builds the 'DROP INDEX' CQL statement
|
|
33
|
+
#
|
|
34
|
+
# @return [QueryBuilder::Statements::DropIndex]
|
|
35
|
+
#
|
|
36
|
+
def drop
|
|
37
|
+
Statements::DropIndex.new(context: self)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end # class Index
|
|
41
|
+
|
|
42
|
+
end # module Contexts
|
|
43
|
+
|
|
44
|
+
end # module QueryBuilder::CQL
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module QueryBuilder::CQL
|
|
4
|
+
|
|
5
|
+
module Contexts
|
|
6
|
+
|
|
7
|
+
# Describes the Cassandra keyspace
|
|
8
|
+
#
|
|
9
|
+
class Keyspace < Base
|
|
10
|
+
|
|
11
|
+
attribute :name, required: true
|
|
12
|
+
|
|
13
|
+
# Returns the name of the keyspace
|
|
14
|
+
#
|
|
15
|
+
# @return [String]
|
|
16
|
+
#
|
|
17
|
+
def to_s
|
|
18
|
+
name.to_s
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Returns the table context
|
|
22
|
+
#
|
|
23
|
+
# @param [#to_s] name
|
|
24
|
+
#
|
|
25
|
+
# @return [QueryBuilder::CQL::Contexts::Table]
|
|
26
|
+
#
|
|
27
|
+
def table(name)
|
|
28
|
+
Table.new(keyspace: self, name: name)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Returns the type context
|
|
32
|
+
#
|
|
33
|
+
# @param [#to_s] name
|
|
34
|
+
#
|
|
35
|
+
# @return [QueryBuilder::CQL::Contexts::Type]
|
|
36
|
+
#
|
|
37
|
+
def type(name)
|
|
38
|
+
Type.new(keyspace: self, name: name)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Returns the function context
|
|
42
|
+
#
|
|
43
|
+
# @param [#to_s] name
|
|
44
|
+
#
|
|
45
|
+
# @return [QueryBuilder::CQL::Contexts::Function]
|
|
46
|
+
#
|
|
47
|
+
def function(name)
|
|
48
|
+
Function.new(keyspace: self, name: name)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Returns the aggregate context
|
|
52
|
+
#
|
|
53
|
+
# @param [#to_s] name
|
|
54
|
+
#
|
|
55
|
+
# @return [QueryBuilder::CQL::Contexts::Aggregate]
|
|
56
|
+
#
|
|
57
|
+
def aggregate(name)
|
|
58
|
+
Aggregate.new(keyspace: self, name: name)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Returns the context of Cassandra keyspace permission
|
|
62
|
+
#
|
|
63
|
+
# @param [#to_s, nil] name The name of the permission
|
|
64
|
+
#
|
|
65
|
+
# @param [QueryBuilder::CQL::Contexts::Permission]
|
|
66
|
+
#
|
|
67
|
+
def permission(name = nil)
|
|
68
|
+
Contexts::Permission.new(keyspace: self, name: name)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Builds the 'CREATE KEYSPACE' CQL statement for the current keyspace
|
|
72
|
+
#
|
|
73
|
+
# @return [QueryBuilder::Statements::CreateKeyspace]
|
|
74
|
+
#
|
|
75
|
+
def create
|
|
76
|
+
Statements::CreateKeyspace.new(context: self)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Builds the 'ALTER KEYSPACE' CQL statement for the current keyspace
|
|
80
|
+
#
|
|
81
|
+
# @return [QueryBuilder::CQL::Statements::AlterKeyspace]
|
|
82
|
+
#
|
|
83
|
+
def alter
|
|
84
|
+
Statements::AlterKeyspace.new(context: self)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Builds the 'DROP KEYSPACE' CQL statement for the current keyspace
|
|
88
|
+
#
|
|
89
|
+
# @return [QueryBuilder::CQL::Statements::DropKeyspace]
|
|
90
|
+
#
|
|
91
|
+
def drop
|
|
92
|
+
Statements::DropKeyspace.new(context: self)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Builds the 'USE' CQL statement
|
|
96
|
+
#
|
|
97
|
+
# @return [QueryBuilder::Statements::Use]
|
|
98
|
+
#
|
|
99
|
+
def use
|
|
100
|
+
Statements::Use.new(context: self)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
end # class Keyspace
|
|
104
|
+
|
|
105
|
+
end # module Contexts
|
|
106
|
+
|
|
107
|
+
end # module QueryBuilder::CQL::Contexts
|