Module: Dbwatcher::Storage

Defined in:
lib/dbwatcher/storage.rb,
lib/dbwatcher/storage/errors.rb,
lib/dbwatcher/storage/session.rb,
lib/dbwatcher/storage/date_helper.rb,
lib/dbwatcher/storage/api/base_api.rb,
lib/dbwatcher/storage/base_storage.rb,
lib/dbwatcher/storage/file_manager.rb,
lib/dbwatcher/storage/null_session.rb,
lib/dbwatcher/storage/api/query_api.rb,
lib/dbwatcher/storage/api/table_api.rb,
lib/dbwatcher/storage/query_storage.rb,
lib/dbwatcher/storage/session_query.rb,
lib/dbwatcher/storage/table_storage.rb,
lib/dbwatcher/storage/api/session_api.rb,
lib/dbwatcher/storage/query_validator.rb,
lib/dbwatcher/storage/session_storage.rb,
lib/dbwatcher/storage/change_processor.rb,
lib/dbwatcher/storage/session_operations.rb,
lib/dbwatcher/storage/system_info_storage.rb,
lib/dbwatcher/storage/concerns/validatable.rb,
lib/dbwatcher/storage/concerns/error_handler.rb,
lib/dbwatcher/storage/concerns/timestampable.rb,
lib/dbwatcher/storage/concerns/data_normalizer.rb,
lib/dbwatcher/storage/api/concerns/table_analyzer.rb

Overview

Storage module provides the main interface for database monitoring data persistence

This module acts as a facade for different storage backends and provides clean API entry points for sessions, queries, and tables. It manages storage instances and provides cleanup operations.

Examples:

Basic usage

Dbwatcher::Storage.sessions.create("My Session")
Dbwatcher::Storage.sessions.recent.with_changes
Dbwatcher::Storage.queries.save(query_data)
Dbwatcher::Storage.tables.changes_for("users")

Cleanup operations

Dbwatcher::Storage.cleanup_old_sessions
Dbwatcher::Storage.clear_all

See Also:

  • SessionAPI
  • QueryAPI
  • TableAPI

Defined Under Namespace

Modules: Api, Concerns, DateHelper, ErrorHandler Classes: BaseStorage, ChangeProcessor, CorruptedDataError, FileManager, NullSession, PermissionError, QueryNotFoundError, QueryStorage, QueryValidator, Session, SessionNotFoundError, SessionOperations, SessionQuery, SessionStorage, StorageError, SystemInfoStorage, TableNotFoundError, TableStorage, ValidationError

Class Method Summary collapse

Class Method Details

.cleanup_old_sessionsvoid

This method returns an undefined value.

Removes old session files based on configuration

Automatically removes session files that exceed the configured retention period. This helps manage storage space usage.



109
110
111
# File 'lib/dbwatcher/storage.rb', line 109

def cleanup_old_sessions
  session_storage.cleanup_old_sessions
end

.clear_allInteger

Clears all storage data

Returns:

  • (Integer)

    total number of files removed



142
143
144
145
146
# File 'lib/dbwatcher/storage.rb', line 142

def clear_all
  session_count = session_storage.clear_all
  query_count = query_storage.clear_all
  session_count + query_count
end

.queriesQueryAPI

Provides access to query operations

Examples:

Dbwatcher::Storage.queries.save(query_data)
Dbwatcher::Storage.queries.for_date(Date.today)

Returns:

  • (QueryAPI)

    query API interface



58
59
60
# File 'lib/dbwatcher/storage.rb', line 58

def queries
  @queries ||= Api::QueryAPI.new(query_storage)
end

.query_storageQueryStorage

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the query storage instance

Returns:



127
128
129
# File 'lib/dbwatcher/storage.rb', line 127

def query_storage
  @query_storage ||= QueryStorage.new
end

.reset_storage_instances!void

This method returns an undefined value.

Resets all cached storage instances (primarily for testing)

This method clears all memoized storage instances, forcing them to be recreated on next access. Useful for testing scenarios.

Examples:

Dbwatcher::Storage.reset_storage_instances!


90
91
92
93
94
95
96
97
98
# File 'lib/dbwatcher/storage.rb', line 90

def reset_storage_instances!
  @session_storage = nil
  @query_storage = nil
  @table_storage = nil
  @system_info = nil
  @sessions = nil
  @queries = nil
  @tables = nil
end

.session_storageSessionStorage

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the session storage instance

Returns:



119
120
121
# File 'lib/dbwatcher/storage.rb', line 119

def session_storage
  @session_storage ||= SessionStorage.new
end

.sessionsSessionAPI

Provides access to session operations

Examples:

Dbwatcher::Storage.sessions.create("My Session")
Dbwatcher::Storage.sessions.all
Dbwatcher::Storage.sessions.recent.with_changes

Returns:

  • (SessionAPI)

    session API interface



48
49
50
# File 'lib/dbwatcher/storage.rb', line 48

def sessions
  @sessions ||= Api::SessionAPI.new(session_storage)
end

.system_infoSystemInfoStorage

Provides access to system information operations

Examples:

Dbwatcher::Storage.system_info.cached_info
Dbwatcher::Storage.system_info.refresh_info

Returns:



78
79
80
# File 'lib/dbwatcher/storage.rb', line 78

def system_info
  @system_info ||= SystemInfoStorage.new
end

.table_storageTableStorage

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the table storage instance

Returns:



135
136
137
# File 'lib/dbwatcher/storage.rb', line 135

def table_storage
  @table_storage ||= TableStorage.new(session_storage)
end

.tablesTableAPI

Provides access to table operations

Examples:

Dbwatcher::Storage.tables.changes_for("users")
Dbwatcher::Storage.tables.recent_changes

Returns:

  • (TableAPI)

    table API interface



68
69
70
# File 'lib/dbwatcher/storage.rb', line 68

def tables
  @tables ||= Api::TableAPI.new(table_storage)
end