Class: NoSE::Backend::Backend
- Defined in:
- lib/nose/backend.rb
Overview
Superclass of all database backends
Direct Known Subclasses
Defined Under Namespace
Classes: DeleteStatementStep, FilterStatementStep, IndexLookupStatementStep, InsertStatementStep, LimitStatementStep, SortStatementStep, StatementStep
Instance Method Summary collapse
-
#by_id_graph ⇒ Boolean
By default, do not use ID graphs.
- #drop_index ⇒ void abstract
-
#generate_id ⇒ Object
abstract
:nocov:.
- #index_empty?(_index) ⇒ Boolean abstract
- #index_exists?(_index) ⇒ Boolean abstract
-
#index_insert_chunk(_index, _chunk) ⇒ void
abstract
:nocov:.
-
#indexes_ddl(_execute = false, _skip_existing = false, _drop_existing = false) ⇒ Enumerable
abstract
:nocov:.
-
#indexes_sample(_index, _count) ⇒ Array<Hash>
abstract
:nocov:.
-
#initialize(model, indexes, plans, update_plans, _config) ⇒ Backend
constructor
A new instance of Backend.
-
#prepare(statement, plans = []) ⇒ Object
Prepare a statement to be executed with the given plans.
-
#prepare_query(query, fields, conditions, plans = []) ⇒ PreparedQuery
Prepare a query to be executed with the given plans.
-
#prepare_update(update, plans) ⇒ PreparedUpdate
Prepare an update for execution.
-
#query(query, plans = []) ⇒ Array<Hash>
Execute a query with the stored plans.
-
#update(update, plans = []) ⇒ void
Execute an update with the stored plans.
Methods included from Supertype
Methods included from Listing
Constructor Details
#initialize(model, indexes, plans, update_plans, _config) ⇒ Backend
Returns a new instance of Backend.
11 12 13 14 15 16 |
# File 'lib/nose/backend.rb', line 11 def initialize(model, indexes, plans, update_plans, _config) @model = model @indexes = indexes @plans = plans @update_plans = update_plans end |
Instance Method Details
#by_id_graph ⇒ Boolean
By default, do not use ID graphs
20 21 22 |
# File 'lib/nose/backend.rb', line 20 def by_id_graph false end |
#drop_index ⇒ void
Subclasses implement to remove existing indexes
This method returns an undefined value.
38 39 |
# File 'lib/nose/backend.rb', line 38 def drop_index end |
#generate_id ⇒ Object
Subclasses implement to generate a new random ID
:nocov:
53 54 55 |
# File 'lib/nose/backend.rb', line 53 def generate_id fail NotImplementedError end |
#index_empty?(_index) ⇒ Boolean
Subclasses implement to check if an index is empty
26 27 28 |
# File 'lib/nose/backend.rb', line 26 def index_empty?(_index) true end |
#index_exists?(_index) ⇒ Boolean
Subclasses implement to check if an index already exists
32 33 34 |
# File 'lib/nose/backend.rb', line 32 def index_exists?(_index) false end |
#index_insert_chunk(_index, _chunk) ⇒ void
Subclasses implement to allow inserting data into the backend database
This method returns an undefined value.
:nocov:
45 46 47 |
# File 'lib/nose/backend.rb', line 45 def index_insert_chunk(_index, _chunk) fail NotImplementedError end |
#indexes_ddl(_execute = false, _skip_existing = false, _drop_existing = false) ⇒ Enumerable
Subclasses should create indexes
:nocov:
61 62 63 64 |
# File 'lib/nose/backend.rb', line 61 def indexes_ddl(_execute = false, _skip_existing = false, _drop_existing = false) fail NotImplementedError end |
#indexes_sample(_index, _count) ⇒ Array<Hash>
Subclasses should return sample values from the index
:nocov:
70 71 72 |
# File 'lib/nose/backend.rb', line 70 def indexes_sample(_index, _count) fail NotImplementedError end |
#prepare(statement, plans = []) ⇒ Object
Prepare a statement to be executed with the given plans
87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/nose/backend.rb', line 87 def prepare(statement, plans = []) if statement.is_a? Query prepare_query statement, statement.all_fields, statement.conditions, plans elsif statement.is_a? Delete prepare_update statement, plans elsif statement.is_a? Disconnect prepare_update statement, plans elsif statement.is_a? Connection prepare_update statement, plans else prepare_update statement, plans end end |
#prepare_query(query, fields, conditions, plans = []) ⇒ PreparedQuery
Prepare a query to be executed with the given plans
77 78 79 80 81 82 83 84 |
# File 'lib/nose/backend.rb', line 77 def prepare_query(query, fields, conditions, plans = []) plan = plans.empty? ? find_query_plan(query) : plans.first state = Plans::QueryState.new(query, @model) unless query.nil? first_step = Plans::RootPlanStep.new state steps = [first_step] + plan.to_a + [nil] PreparedQuery.new query, prepare_query_steps(steps, fields, conditions) end |
#prepare_update(update, plans) ⇒ PreparedUpdate
Prepare an update for execution
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/nose/backend.rb', line 111 def prepare_update(update, plans) # Search for plans if they were not given plans = find_update_plans(update) if plans.empty? fail PlanNotFound if plans.empty? # Prepare each plan plans.map do |plan| delete = false insert = false plan.update_steps.each do |step| delete = true if step.is_a?(Plans::DeletePlanStep) insert = true if step.is_a?(Plans::InsertPlanStep) end steps = [] add_delete_step(plan, steps) if delete add_insert_step(plan, steps, plan.update_fields) if insert PreparedUpdate.new update, prepare_support_plans(plan), steps end end |
#query(query, plans = []) ⇒ Array<Hash>
Execute a query with the stored plans
104 105 106 107 |
# File 'lib/nose/backend.rb', line 104 def query(query, plans = []) prepared = prepare query, plans prepared.execute query.conditions end |
#update(update, plans = []) ⇒ void
This method returns an undefined value.
Execute an update with the stored plans
135 136 137 138 |
# File 'lib/nose/backend.rb', line 135 def update(update, plans = []) prepared = prepare_update update, plans prepared.each { |p| p.execute update.settings, update.conditions } end |