Metadata-Version: 2.1
Name: dbsplitsql
Version: 0.0.11
Summary: It will split all the table and views of a schema in a file, into its respective files
Home-page: https://github.com/balagdivya/dbsplitsql
Author: Divya Goteti
Author-email: balagdivya@gmail.com
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Requires-Dist: argparse

# dbsplitsql

A lightweight Python utility package to split and process large SQL scripts into manageable SQL statements.

## Overview

`dbsplitsql` is a Python package designed to help developers and database engineers split large SQL files into individual executable SQL statements. It is useful for:

* Database migration scripts
* SQL deployment automation
* ETL workflows
* SQL parsing utilities
* Handling large SQL dump files

This package was originally created and published on PyPI in 2019.

---

## Features

* Split large SQL scripts into separate queries
* Lightweight and easy to use
* Supports automation workflows
* Useful for database maintenance and migrations
* Open-source Python utility package

---

## Installation

Install directly from PyPI:

```bash
pip install dbsplitsql
```

---

## Usage
## Usage

### Process a Single SQL File

```bash
python main.py -f hr.sql
```

This generates object-wise DDL files inside the `DDLS` folder.

Example output:

```text
DDLS/
    hr/
        departments.sql
        employees.sql
        vw_employee_details.sql
        fn_get_employee_count.sql
        trg_employee_insert.sql
```

---

### Process Multiple SQL Files from a Directory

Suppose your directory structure is:

```text
testddl/
    hr.sql
    sales.sql
```

Run:

```bash
python main.py -d testddl
```

Generated output:

```text
DDLS/
    hr/
        departments.sql
        employees.sql
        vw_employee_details.sql
        fn_get_employee_count.sql
        trg_employee_insert.sql

    sales/
        customers.sql
        orders.sql
        vw_order_summary.sql
        fn_total_orders.sql
        trg_order_insert.sql
```

---

## Supported Database Objects

The utility currently supports splitting:

* TABLES
* VIEWS
* FUNCTIONS
* TRIGGERS
* PROCEDURES

It also preserves associated:

* ALTER TABLE constraints
* PRIMARY KEYS
* FOREIGN KEYS
* CHECK constraints

until the next CREATE object statement is encountered.

---

## Features

* Supports enterprise-style DDL extracts
* Handles multiple schemas in a single file
* Handles multiple schema files in a directory
* Automatically creates schema-wise folders
* Splits database objects into separate SQL files
* Removes:

  * GO statements
  * separator comments
  * extraction headers
* Preserves ALTER TABLE constraints with parent object

---

## Output Structure

Generated DDLs are organized schema-wise:

```text
DDLS/
    schema_name/
        object_name.sql
```

---

## Example Supported DDL

```sql
CREATE TABLE hr.employee
(
    employee_id INT
)
GO

ALTER TABLE hr.employee
ADD CONSTRAINT pk_employee
PRIMARY KEY(employee_id)
GO
```

Generated file:

```text
employee.sql
```

Content:

```sql
CREATE TABLE hr.employee
(
    employee_id INT
)

ALTER TABLE hr.employee
ADD CONSTRAINT pk_employee
PRIMARY KEY(employee_id)
```


## Project Links

* GitHub Repository: [https://github.com/balagdivya/dbsplitsql](https://github.com/balagdivya/dbsplitsql)
* PyPI Package: [https://pypi.org/project/dbsplitsql/](https://pypi.org/project/dbsplitsql/)

---

## Technologies Used

* Python
* SQL
* PyPI Packaging
* GitHub

---

## Contributing

Contributions are welcome.

### Steps to Contribute

1. Fork the repository

```bash
git clone https://github.com/balagdivya/dbsplitsql.git
```

2. Create a new branch

```bash
git checkout -b feature-name
```

3. Make your changes

4. Commit changes

```bash
git commit -m "Added new feature"
```

5. Push the branch

```bash
git push origin feature-name
```

6. Create a Pull Request on GitHub

---

## Publishing to PyPI

### Build the package

```bash
python setup.py sdist bdist_wheel
```

### Install Twine

```bash
pip install twine
```

### Upload to PyPI

```bash
twine upload dist/*
```

---


## License

MIT License

---

## Author

Divya Goteti
