Bear Module
This module provides Bear.app database operations for schema extraction, data querying, and validation.
Module Overview
- Purpose: Bear.app database operations for schema extraction, data querying, and validation
- Architecture: Three-file design
validation.sh: Database path and table existence validationschema.sh: Schema extraction and DROP statement preparationdata.sh: Data extraction and row count queries
- Dependencies:
- External commands:
sqlite3,perl(with Encode module) - Internal modules:
src/lib/logging/logger.sh:log()functionsrc/lib/utils/timing.sh:print_section()functionsrc/lib/utils/core.sh:die()function
- External commands:
Available Functions
Validation Functions (src/lib/bear/validation.sh)
validate_bear_db_path(): Validates Bear database exists and is readablevalidate_bear_tables(tables_array): Validates table existence in Bear database
Schema Functions (src/lib/bear/schema.sh)
extract_bear_schema(tables_array): Extracts CREATE TABLE and CREATE INDEX statements for specified tablesprepare_schema_with_drop(schema, tables_array): Prepends DROP TABLE IF EXISTS statements to schema
Data Functions (src/lib/bear/data.sh)
extract_table_data(table_name, limit, offset, where_clause): Generates INSERT statements from Bear SQLite tablequery_bear_table_count(table_name, where_clause): Queries row count from Bear table
Bear Database Structure
Database Location
- Path:
~/Library/Group Containers/9K33E3U3T4.net.shinyfrog.bear/Application Data/database.sqlite - Variable:
BEAR_DB_PATH - Validation: File existence and readability checks via
validate_bear_db_path()
Table Structure
Bear.app uses Core Data with SQLite backend. Common tables include:
ZSFNOTE: Main notes tableZSFNOTETAG: Tags tableZ_5TAGS: Many-to-many relationship tableZSFNOTEFILE: File attachments table
Integration Guidelines
Sourcing Order
- Source
validation.shfirst (used early in script) - Source
schema.shsecond (used for schema extraction) - Source
data.shthird (used for data extraction)
Global Variable Initialization
Caller must initialize these variables before using module functions:
BEAR_DB_PATH="${HOME}/Library/Group Containers/9K33E3U3T4.net.shinyfrog.bear/Application Data/database.sqlite"
Navigation
- Architecture Overview - High-level architecture
- Modular Architecture - Module hierarchy and dependencies
- Sync Module - Sync orchestration
- Data Module - Data batching and transformations