-
Notifications
You must be signed in to change notification settings - Fork 0
DBFxSQL Wiki
DBFxSQL is a CLI tool that enables seamless data consistency between legacy DBF (dBase) files and modern SQL databases during migration projects.
- Multi-Engine Support: dBase, SQLite, and MSSQL
- Bidirectional Sync: Real-time synchronization between databases
- CLI Interface: Comprehensive command-line operations with embedded examples
- Configuration-Driven: TOML-based setup and relation mapping
The system uses a modular architecture with separate controllers for each database engine, unified through a common CLI interface that automatically detects target engines based on file extensions.
- Python: 3.12 or higher
- Operating System: Linux, Windows
- Dependencies: Managed via Poetry
- Clone the repository:
git clone https://github.com/joelabreurojas/DBFxSQL.git- Install the source code:
pip install DBFxSQL/- Verify installation:
dbfxsqlOn first execution, DBFxSQL automatically creates a default configuration file at ~/.config/DBFxSQL/config.toml. The system creates the directory structure if it doesn't exist.
The tool can be run both as dbfxsql and python -m dbfxsql.
The CLI provides unified access to all database operations through a consistent command structure with automatic engine detection and parameter validation.
-
create: Create DBF files or SQL databases/tables -
insert: Add records to databases -
read: Query data with optional conditions -
update: Modify existing records -
delete: Remove records -
drop: Delete files, databases, or tables (with confirmation prompts)
-
migrate: One-time data migration -
sync: Continuous synchronization with file monitoring
All commands follow a consistent parameter pattern:
-
-s, --source: Target file (required) -
-t, --table: Table name (SQL engines only) -
-f, --fields: Field definitions or values -
-c, --condition: Query/filter conditions (requires three separate values: field, operator, value) -
-n, --notify: Enable operation notifications
The system supports row_number as a virtual condition field for row-based operations. Use quoted operators for better shell compatibility:
dbfxsql read -s users.dbf -c row_number "<=" 10The CLI automatically includes relevant examples in help text using the @embed_examples decorator for all commands.
DBFxSQL uses a TOML configuration file with three main sections:
[engines.dBase]
folderpaths = ["."]
extensions = [".dbf", ".DBF"]
[engines.SQLite]
folderpaths = ["."]
extensions = [".sql", ".SQL", ".sqlite3", ".SQLite3", ".db", ".DB"]
[engines.MSSQL]
folderpaths = ["/var/opt/mssql/data/"]
extensions = [".mdf", ".MDF"]
db_server = "SERVER\\INSTANCE"
db_user = "username"
db_password = "password"[[relations]]
sources = ["users.dbf", "company.sql"]
tables = ["", "users"]
fields = [["id", "name"], ["id", "name"]]
priority = "users.dbf"The system automatically loads configuration using the file manager, creating default settings and directory structure if none exist.
-
Extensions:
.dbf,.DBF - Connection: Direct file access
- Operations: Full CRUD support
- Data Types: Character (C), Numeric (N), Date (D), Logical (L), Memo (M)
-
Extensions:
.sql,.sqlite3,.db - Connection: Local database file
- Operations: Full CRUD + Database management
- Data Types: INTEGER, REAL, TEXT, BLOB, NULL
-
Extensions:
.mdf - Connection: Network database server
- Operations: Full CRUD + Database management
- Data Types: Comprehensive SQL Server type support
- Known Issues: Connection issues in database manipulation commands
The system automatically detects target engines based on file extensions, throwing a click.UsageError for unknown extensions.
Transfers data based on configured priorities using the migrate command.
dbfxsql migrate --notifyMonitors file system changes and applies updates in real-time using the sync command.
dbfxsql sync --notifyThe synchronization follows a structured pipeline:
-
formatters.package_changes()- Package changes from source files -
_assign_rows()- Assign rows to sync tables -
formatters.compare_tables()- Compare tables to identify differences -
formatters.classify_operations()- Classify operations (insert, update, delete) -
_execute_operations()- Execute operations on destination databases
# Create DBF file
dbfxsql create -s users.dbf -f id "N(20,0)" -f name "C(20)"
# Insert data
dbfxsql insert -s users.dbf -f id 1 -f name "John Doe"
# Query data (condition format: field operator value)
dbfxsql read -s users.dbf -c id == 1
# Query by row number (use quotes for operators)
dbfxsql read -s users.dbf -c row_number "<=" 10# Create database and table
dbfxsql create -s company.sql -t users -f id 'integer primary key' -f name text
# Insert data
dbfxsql insert -s company.sql -t users -f id 1 -f name "John Doe"
# Update records (condition format: field operator value)
dbfxsql update -s company.sql -t users -f name "Jane Doe" -c id == 1
# Query by row number
dbfxsql read -s company.sql -t users -c row_number "<=" 5The system includes embedded examples through the @embed_examples decorator for all CLI commands.
The CLI implements comprehensive database operations through a unified interface with automatic engine detection and parameter validation.
- Engine Detection: Automatic database engine identification
- Parameter Validation: Engine-specific parameter checking with detailed error messages
- Operation Routing: Command routing to appropriate controllers
- Error Handling: Comprehensive exception management with confirmation prompts for destructive operations
The condition system supports all standard comparison operators and special fields:
- Standard operators:
==,!=,<,>,<=,>= - Special field:
row_number(virtual field for row position) - Value quoting:
row_numberconditions bypass automatic type quoting
Issue: "Unknown extension for 'filename' source" Solution: Ensure file extensions match configured engine extensions.
Issue: "No such option '-t' / '--table' for DBF" Solution: Remove table parameter when working with DBF files
Issue: "Missing option '-t' / '--table' for SQL" Solution: Always specify table name for SQL operations
Issue: Condition parameter format errors Solution: Use three separate values for conditions: field, operator, value
- MSSQL connection issues in database manipulation commands
- Requires local file system access
- Some advanced features are still under development
The project includes comprehensive test suites for both DBF and SQL operations, validating CLI operations and database functionality across all supported engines. Tests require the default config file and use subprocess calls to test CLI commands end-to-end.
- Fork and clone the repository
- Install development dependencies with Poetry
- Run tests to verify setup (requires default config file)
- Follow the project's coding standards
The project uses pytest for comprehensive testing with separate test suites for DBF and SQL operations. Tests validate CLI commands through subprocess calls and verify database operations across all supported engines.
Q: When should I use migration vs continuous sync? A: Use migration for one-time data transfers; use sync for ongoing synchronization needs.
Q: What databases are supported? A: dBase (.dbf), SQLite (.sql, .sqlite3, .db), and MSSQL (.mdf) databases.
Q: How does conflict resolution work?
A: Priority-based resolution uses the priority field in relation configurations.
Q: How do I format condition parameters?
A: Use three separate values: field, operator, value (e.g., -c id == 1). For operators with special characters, use quotes (e.g., -c row_number "<=" 10).
Q: What is the row_number field?
A: A virtual field that represents the row position (1-based) in the data, useful for row-based operations.
Q: What are the known limitations? A: MSSQL connection issues in database manipulation commands, requires local file system access, and some advanced features are under development.