{"id":26260478,"url":"https://github.com/ronpinkas/dbbridge","last_synced_at":"2025-04-30T07:05:11.414Z","repository":{"id":174818526,"uuid":"652805813","full_name":"ronpinkas/dbBridge","owner":"ronpinkas","description":"dbBridge is an 'SQL Migration Tool' - enabling import of SQL Databases from any supported Dialect (MsSql, MySql, Oracle, PostgreSQL, Sqlite) to any of these supported dialects with just three lines of PHP code.","archived":false,"fork":false,"pushed_at":"2023-12-22T23:30:03.000Z","size":83,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-30T07:04:58.191Z","etag":null,"topics":["data-integration","data-migration","data-transfer","data-transformation","database-conversion","db-migrate","db-migration","etl","migration","minimal","mssql","mysql","open-source","oracle","php","postgresql","simple","sql","sqlite"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ronpinkas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-06-12T20:46:27.000Z","updated_at":"2025-04-23T16:07:53.000Z","dependencies_parsed_at":"2023-12-23T01:24:17.069Z","dependency_job_id":"272984b3-0782-4671-962d-aaa2bd853a2c","html_url":"https://github.com/ronpinkas/dbBridge","commit_stats":null,"previous_names":["ronpinkas/dbbridge"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronpinkas%2FdbBridge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronpinkas%2FdbBridge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronpinkas%2FdbBridge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronpinkas%2FdbBridge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ronpinkas","download_url":"https://codeload.github.com/ronpinkas/dbBridge/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251658200,"owners_count":21622819,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-integration","data-migration","data-transfer","data-transformation","database-conversion","db-migrate","db-migration","etl","migration","minimal","mssql","mysql","open-source","oracle","php","postgresql","simple","sql","sqlite"],"created_at":"2025-03-13T23:15:02.312Z","updated_at":"2025-04-30T07:05:11.387Z","avatar_url":"https://github.com/ronpinkas.png","language":"PHP","readme":"# dbBridge\n\n![Version](https://img.shields.io/badge/version-0.8.0-brightgreen.svg?style=flat-square)\n![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square)\n\ndbBridge is an 'SQL Migration Tool' - enabling import of SQL Databases from any supported Dialect (MsSql, MySql, Oracle, PostgreSQL, Sqlite) to any of these supported dialects with just three lines of PHP code.\n\n## Prerequisites\n\n- PHP \u003e= 8.0\n\n## Installation\n\n### Using Composer\n\nIf you are using Composer, you can add `dbBridge` to your project by running:\n\n    composer require ronpinkas/dbbridge\n\n\n### Manual Installation\n\nIf you prefer not to use Composer, you can download the library and include it in your project manually.\n\n   ```php\n   require_once 'path-to-dbBridge/dbAbstractor.php';\n   ```\n\n## Usage\n   The dbAbstractor class serves as the core of the dbBridge library, facilitating the transfer of \n   database data between different SQL dialects.\n\n   ```php\n   require_once 'vendor/autoload.php';\n\n   use dbBridge\\dbAbstractor;\n\n   // Example of setting PDO connection for source database\n   $pdoMsSql = new PDO(\"dblib:host=your_hostname;dbname=your_db;charset=utf8\", \"your_username\", \"your_password\");\n\n   // Example of setting PDO connection for target database\n   $pdoMySql = new PDO(\"mysql:host=your_hostname;dbname=your_db;charset=utf8\", \"your_username\", \"your_password\");\n\n   // Create dbBridge wrapper instances for the source and target databases\n   $dbSource = new dbAbstractor($pdoMsSql, 'YourDB-Name');\n   $dbTarget = new dbAbstractor($pdoMySql);\n\n   // Import the database\n   $dbTarget-\u003eimportDb($dbSource);\n   ```\n\n## Known Limitations\n\nThis library is an educational proof of concept prototype, and has the following known limitations:\n\nNo support for Stored Procedures.\nNo support for Triggers.\nNo support for Indexes.\nNo support for Constraints.\nNo support for Sequences.\nNo support for Foreign Keys.\nNo support for Views.\nNo support for Functions.\nNo support for User-defined Types.\nNo support for User-defined Aggregates.\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a pull request or create issues for anything you think could be improved.\n\n## License\n\nThis project is licensed under the MIT License. See the LICENSE file for details.\n\n## Contact\n\nAuthor: Ron[ny] Pinkas\nEmail: ron@ronpinkas.com\nWebsite: https://github.com/ronpinkas/dbBridge\n\n## Acknowledgments\n\n- Special thanks to https://www.omie.com.br for supporting the research time which contributed\n  to the development of this project.\n\n- Thanks to OpenAI's GPT model for assistance with PHP documentation and code samples, \n  as well as advice and assistance in generating documentation reading the project for\n  distribution with Composer.\n\nA big thank you to the community for your support!\n\n## The log_dbBridge function\n\nThe log_dbBridge function in the dbBridge library is responsible for logging and \ndisplaying progress and log messages during the database import process. It takes two \narguments, a message string and a context flag which determines the type of message.\n\nHere's an example of how the log_dbBridge function is typically being used:\n   \n   ```php\n   log_dbBridge(\"This is a transformation message\", debugFlags::DEBUG_TRANSFORM_ALL );\n   ```\n\nIn this example, the message \"This is a transformation message\" is associated with the \nDEBUG_TRANSFORM_ALL flag. Whether or not this message gets logged or displayed depends\non the bitmask settings in debugFlags::$debugLogFlags and debugFlags::$debugShowFlags.\n\nYou can control the bitmask settings like this:\n\n   ```php\n   // To enable logging of transformation messages\n   debugFlags::$debugLogFlags |= debugFlags::DEBUG_TRANSFORM_ALL;\n\n   // To enable displaying of transformation messages\n   debugFlags::$debugShowFlags |= debugFlags::DEBUG_TRANSFORM_ALL;\n\n   // To disable logging of transformation messages\n   debugFlags::$debugLogFlags \u0026= ~debugFlags::DEBUG_TRANSFORM_ALL;\n\n   // To disable displaying of transformation messages\n   debugFlags::$debugShowFlags \u0026= ~debugFlags::DEBUG_TRANSFORM_ALL;\n   ```\n\nThis provides you with the flexibility to control which messages are logged or displayed based on their context.\n\n## Debug Flags\n\nThe debugFlags class contains constants that can be used to control the behavior of the log_dbBridge() function.\nThese constants can be used as a bitmask to specify the debug level for logging and displaying messages by means \nof the class' ::$debugLogFlags and ::$debugShowFlags static properties which can be set using the \n::setDebugLogFlags() and ::setDebugShowFlags() static methods. \n\nHere is a description of each flag:\n\nDEBUG_ALWAYS (1): Indicates that the message should always be logged and displayed, regardless of the mask\nlevel specified by debugFlags::$debugLogFlags and debugFlags::$debugShowFlags.\n\nDEBUG_TRANSFORM_RESERVED (4): Indicates that a warning about the usage of a reserved name as a column name,\nwhich results in a '_' prefix being added should be logged or displayed.\n\nDEBUG_TRANSFORM_SOURCE (8): Indicates that the source data in a transformation should be logged or displayed.\n\nDEBUG_TRANSFORM_TARGET (16): Indicates that the target data in a transformation should be logged or displayed.\n\nDEBUG_TRANSFORM_TRANSFORMED (32): Indicates that the transformed data should be logged or displayed.\n\nDEBUG_TRANSFORM_ALL (60): A combination of all transformation-related flags (DEBUG_TRANSFORM_RESERVED,\nDEBUG_TRANSFORM_SOURCE, DEBUG_TRANSFORM_TARGET, DEBUG_TRANSFORM_TRANSFORMED). Use this flag to log or\ndisplay any transformation-related messages.\n\nDEBUG_QUERY_CREATE (64): Indicates that messages related to query creation should be logged or displayed.\n\nDEBUG_QUERY_SELECT (128): Indicates that messages related to SELECT queries should be logged or displayed.\n\nDEBUG_QUERY_INSERT (256): Indicates that messages related to INSERT queries should be logged or displayed.\n\nDEBUG_QUERY_ALL (448): A combination of all query-related flags (DEBUG_QUERY_CREATE, DEBUG_QUERY_SELECT, \nDEBUG_QUERY_INSERT). Use this flag to log or display any query-related messages.\n\nDEBUG_OVERWRITE (512): Indicates that messages related to data overwrites should be logged or displayed.\n\nDEBUG_BIND (1024): Indicates that messages related to data binding in queries should be logged or displayed.\n\nDEBUG_EXECUTE (2048): Indicates that messages related to query execution should be logged or displayed.\n\nDEBUG_FETCH (4096): Indicates that messages related to data fetching should be logged or displayed.\n\nDEBUG_FIXME (8192): Indicates that messages related to items marked for fixing or review should be logged\nor displayed.\n\nDEBUG_IMPORT_ROW (16384): Indicates that messages related to data row imports should be logged or displayed.\n\nDEBUG_GC (32768): Indicates that messages related to garbage collection should be logged or displayed.\n\nYou can combine these flags by using the bitwise OR operator to specify messages at multiple levels.\n\n## The importDb function\n\nThe importDb function is responsible for importing a database from a given source.\n\n### Parameters\ndbAbstractor $dbSource: The source database abstractor.\n\n### Process\n1. Retrieve column definitions: getTableColums() retrieves the column definitions for the source table by\ncalling the native function fetchTableColumnDefinitions(). The result is an array of column definitions\nincluding column_name, data_type, and is_nullable. Additional dialect-specific column definition tags\nmay be included.\n\n2. Transform column definitions: transformTableColumnDefs() is used to convert the native source \ndialect-specific data_type to its respective standard type. This is done by calling\n{source-dialect}TypeTo_stdType(). It then converts the standard type to the target dialect's data_type\nby calling stdTypeTo_{target-dialect}(). This results in an extended table column definitions including\nan additional original_type as well as a deduced pdo_type.\n\n3. Compile create table query: compileCreateTableQuery() uses the information gathered from the extended\ntarget definitions in transformTableColumnDefs() to compile an appropriate CREATE TABLE statement for the\nspecific dialect server. It allows for dialect-specific customization of the table creation statement.\n\n4. Compile select query: compileSelectQuery() compiles a SELECT statement to generate the named source values\nin the desired format.\n\n5. Compile insert query: compileInsertQuery() compiles an INSERT INTO statement so that values retrieved\nfrom the source table can be saved correctly to the target table. The extended column definitions are used\nto determine the correct PDO parameter type for each column.\n\n## FAQ\n\n### What is the purpose of the dbBridge library?\nThe dbBridge library is an educational proof-of-concept PHP library that facilitates the transfer of\ndatabase data between different SQL dialects using PDO drivers. It is particularly useful for importing\ndatabases from one SQL dialect to another.\n\n### Which SQL dialects are supported by dbBridge?\nAs of the current version, dbBridge supports SQL dialects that are compatible with PHP's PDO drivers,\nincluding MySQL, MSSQL, Oracle, PostgreSQL, and Sqlite through native and/or ODBC drivers. The library's capabilities might be extended in the future.\n\n### Are there any limitations on the database structures that can be imported using dbBridge?\nYes, the current version of dbBridge has some limitations. It does not support the import of Stored\nProcedures, Triggers, Indexes, Constraints, Sequences, Foreign Keys, Views, Functions, User-defined\nTypes, or User-defined Aggregates. (This is on the TODO list)\n\n### Can I use dbBridge with PHP versions older than 8.0?\ndbBridge requires PHP version 8.0 or higher. It is recommended to use the latest stable version of PHP\nto ensure compatibility and security.\n\n### Can I use dbBridge without Composer?\nYes, you can manually include the library in your project by downloading it and requiring the\ndbAbstractor.php file in your script. However, using Composer is recommended as it simplifies the\ninstallation process.\n\n### How can I contribute to the development of dbBridge?\nContributions to dbBridge are welcome! You can submit a pull request on the repository or create issues\nfor anything you think could be improved.\n\n### What should I do if I encounter a problem or bug while using dbBridge?\nIf you encounter a problem or bug, it's recommended to check if the issue is already known. If not, you\ncan create an issue on the repository describing the problem, the steps to reproduce it, and any error\nmessages.\n\n### How can I control the logging and display of messages during the database import process?\nThe library provides the log_dbBridge function along with debug flags to control logging and display of\nmessages during the import process. You can set the bitmask settings of debugFlags::$debugLogFlags and\ndebugFlags::$debugShowFlags to control which messages get logged or displayed.\n\n### Is there any support or community around dbBridge?\nAs an educational proof-of-concept project, dbBridge may not have official support. However, you can\ncontact the author or participate in discussions and contribute via the repository.\n\n### Can I use dbBridge in a commercial project?\nYes, dbBridge is licensed under the MIT License, which allows for use in both private and commercial\nprojects as long as the dbBridge's original license is included.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fronpinkas%2Fdbbridge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fronpinkas%2Fdbbridge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fronpinkas%2Fdbbridge/lists"}