- database.view now raises SimplyBased::UnsupportedView when a declared view carries CouchDB-era options the N1QL translation silently ignored before: :conditions (a JS fragment) and :emit_value, plus CouchDB list functions. Silently dropping :conditions was the worst of these — a 'view :completed, key: :name, conditions: ...' query returned *unfiltered* results with no hint anything was wrong. Covered by unsupported_view_spec. - All column/property names interpolated into N1QL are now routed through quote_ident, which rejects backticks/backslashes. These names come from the model DSL rather than user input, but a smuggled backtick must never become query text. Class names in index predicates go through a proper string literal quoting helper for the same reason. - ensure_index: failures are still swallowed (an index build in progress must not take down queries) but now emit a warning naming the index, because the silent version left every subsequent query on a primary-index scan with no trace. The ensured-indexes bookkeeping is mutex-guarded for multithreaded servers (Puma). - bulk_load / bulk_destroy now actually batch (collection.get_multi / remove_multi — one KV round trip). The README already advertised 'bulk (batched KV)' but the code looped one get/remove per id. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
46 lines
1.7 KiB
Ruby
46 lines
1.7 KiB
Ruby
# Please move me to a proper location
|
|
class String
|
|
def property_name
|
|
underscore.gsub('/','__').gsub('::','__')
|
|
end
|
|
end
|
|
|
|
# Guard on a sentinel that only this file defines (SimplyBased::VERSION), not on
|
|
# the bare SimplyBased constant. A plugin gem (e.g. simply_couch-couchbase) may
|
|
# open `module SimplyBased` for its own version/namespace before this file loads;
|
|
# guarding on the bare module would then skip the library's whole initialization.
|
|
unless defined?(SimplyBased::VERSION)
|
|
$:<<(File.expand_path(File.dirname(__FILE__) + "/lib"))
|
|
require 'simply_based/instance_methods'
|
|
require 'simply_based/class_methods_base'
|
|
|
|
module SimplyBased
|
|
VERSION = '0.1.0'
|
|
class Error < RuntimeError; end
|
|
class RecordNotFound < RuntimeError; end
|
|
class NotImplementedError < RuntimeError; end
|
|
class ModelNotInstantiatedError < RuntimeError; end
|
|
class NotFound < RuntimeError; end
|
|
# Raised when a declared view carries options the N1QL translation cannot
|
|
# honour (e.g. :conditions / :emit_value / list functions). Failing loudly
|
|
# beats silently returning unfiltered results.
|
|
class UnsupportedView < Error; end
|
|
|
|
# No-op retained for source compatibility with SimplyCouch. SimplyBased
|
|
# never interpolates values into JavaScript views — queries are N1QL with
|
|
# bound parameters — so there is nothing to sanitize. Returns its tokens.
|
|
def self.assert_safe_view_token!(*tokens)
|
|
tokens
|
|
end
|
|
end
|
|
|
|
require 'simply_based/document_codec'
|
|
require 'simply_based/database_config'
|
|
require 'simply_based/model'
|
|
require 'simply_based/store'
|
|
require 'simply_based/redis'
|
|
require 'core_ext/time'
|
|
require 'core_ext/date'
|
|
end
|
|
class SimplyBased::Conflict < StandardError; end
|