Metadata-Version: 2.3
Name: sa-dump-engine
Version: 0.3.0
Summary: a mock engine to output SQL statements generated by SQLAlchemy
Project-URL: Repository, https://github.com/mitszo/sa-dump-engine
Author-email: Mitsumasa IMAZU <mits.imaz@gmail.com>
License: MIT License
        
        Copyright (c) 2024 mitszo
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Requires-Python: >=3.9
Requires-Dist: sqlalchemy>=2.0.36
Description-Content-Type: text/markdown

# sa-dump-engine

This module provides a mock engine to output SQL statements generated by SQLAlchemy.


## Installation

You can install this library using pip:

```bash
pip install sa-dump-engine
```

or

```bash
pip install git+https://github.com/mitszo/sa-dump-engine.git
```


## Usage

Here's a simple example of how to use the library:

```python
from sa_dump_engine import create_dump_engine

# create a mock engine to dump SQL statements with dialect_name like 'sqlite', 'mysql', 'postgresql'
engine = create_dump_engine(dialect_name, literal_binds=False)

# do some with dump-engine, then you can get SQL statement
# to get CREATE TABLE statement
metadata_obj.create_all(engine)

# to get INSERT Statement
conn = engine.connect()
conn.execute(
    insert(user).
    values(user_name="user1", email="user1@example.com", nickname="user1")
)
```

then, you'll get the SQL statement like below:

```sql
CREATE TABLE user (
        user_id INTEGER NOT NULL,
        user_name VARCHAR(16) NOT NULL,
        email_address VARCHAR(60),
        nickname VARCHAR(50) NOT NULL,
        PRIMARY KEY (user_id)
);

CREATE TABLE user_prefs (
        pref_id INTEGER NOT NULL,
        user_id INTEGER NOT NULL,
        pref_name VARCHAR(40) NOT NULL,
        pref_value VARCHAR(100),
        PRIMARY KEY (pref_id),
        FOREIGN KEY(user_id) REFERENCES user (user_id)
);

INSERT INTO user (user_name, email_address, nickname) VALUES (?, ?, ?);
```

If you want to ouput the SQL statement to a file, you can call `create_dump_engine` with `output` parameter like below:

```python
with open('output.sql', 'w') as f:
    engine = create_dump_engine(dialect_name, output=f)
    metadata_obj.create_all(engine)
```


## Dependencies

This library requires the following Python packages:

- SQLAlchemy

see [pyproject.toml](pyproject.toml) for more details.


## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.


## Author

- @mitszo
