Skip to main content

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 validation
    • schema.sh: Schema extraction and DROP statement preparation
    • data.sh: Data extraction and row count queries
  • Dependencies:
    • External commands: sqlite3, perl (with Encode module)
    • Internal modules:
      • src/lib/logging/logger.sh: log() function
      • src/lib/utils/timing.sh: print_section() function
      • src/lib/utils/core.sh: die() function

Available Functions

Validation Functions (src/lib/bear/validation.sh)

  • validate_bear_db_path(): Validates Bear database exists and is readable
  • validate_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 tables
  • prepare_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 table
  • query_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 table
  • ZSFNOTETAG: Tags table
  • Z_5TAGS: Many-to-many relationship table
  • ZSFNOTEFILE: File attachments table

Integration Guidelines

Sourcing Order

  1. Source validation.sh first (used early in script)
  2. Source schema.sh second (used for schema extraction)
  3. Source data.sh third (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"