pydal2sql-core


Namepydal2sql-core JSON
Version 0.4.0 PyPI version JSON
download
home_pageNone
SummaryCLI-agnostic pydal2sql code; Convert pydal define_tables to SQL using pydal's CREATE TABLE logic.
upload_time2024-08-05 16:10:52
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseNone
keywords databases pydal sql
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pydal2sql-core

[![PyPI - Version](https://img.shields.io/pypi/v/pydal2sql-core.svg)](https://pypi.org/project/pydal2sql-core)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pydal2sql-core.svg)](https://pypi.org/project/pydal2sql-core)  
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)  
[![su6 checks](https://github.com/robinvandernoord/pydal2sql-core/actions/workflows/su6.yml/badge.svg?branch=development)](https://github.com/robinvandernoord/pydal2sql-core/actions)
![coverage.svg](coverage.svg)

-----

Companion library for [`pydal2sql`](https://github.com/robinvandernoord/pydal2sql) containing the actual logic.
The other library only serves as a Typer-based CLI front-end.

_More Documentation coming soon!_

## Table of Contents

- [Installation](#installation)
- [As a Python Library](#as-a-python-library)
- [License](#license)

## Installation

```bash
pip install pydal2sql-core
```

## As a Python Library

`pydal2sql-core` also exposes a `generate_sql` method that can perform the same actions on one (for CREATE) or two (for
ALTER) `pydal.Table` objects when used within Python.

```python
from pydal import DAL, Field
from pydal2sql_core import generate_sql

db = DAL(None, migrate=False)  # <- without running database or with a different type of database

person_initial = db.define_table(
    "person",
    Field(
        "name",
        "string",
        notnull=True,
    ),
    Field("age", "integer", default=18),
    Field("float", "decimal(2,3)"),
    Field("nicknames", "list:string"),
    Field("obj", "json"),
)

print(
    generate_sql(
        db.person, db_type="psql"  # or sqlite, or mysql; Optional with fallback to currently using database type.
    )
)
```

```sql
CREATE TABLE person
(
    id        INTEGER PRIMARY KEY AUTOINCREMENT,
    name      VARCHAR(512),
    age       INTEGER,
    float     NUMERIC(2, 3),
    nicknames TEXT,
    obj       TEXT
);
```

```python
person_new = db.define_table(
    "person",
    Field(
        "name",
        "text",
    ),
    Field("birthday", "datetime"),
    redefine=True
)

generate_sql(
    person_initial,
    person_new,
    db_type="psql"
)
```

```sql
ALTER TABLE person
    ADD "name__tmp" TEXT;
UPDATE person
SET "name__tmp"=name;
ALTER TABLE person DROP COLUMN name;
ALTER TABLE person
    ADD name TEXT;
UPDATE person
SET name="name__tmp";
ALTER TABLE person DROP COLUMN "name__tmp";
ALTER TABLE person
    ADD birthday TIMESTAMP;
ALTER TABLE person DROP COLUMN age;
ALTER TABLE person DROP COLUMN float;
ALTER TABLE person DROP COLUMN nicknames;
ALTER TABLE person DROP COLUMN obj;
```

## License

`pydal2sql-core` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pydal2sql-core",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "databases, pydal, sql",
    "author": null,
    "author_email": "Robin van der Noord <robinvandernoord@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/b3/07/a9b83d700896861ba3f1b396df2771efecad51aca51b6197ac90b5d31ff9/pydal2sql_core-0.4.0.tar.gz",
    "platform": null,
    "description": "# pydal2sql-core\n\n[![PyPI - Version](https://img.shields.io/pypi/v/pydal2sql-core.svg)](https://pypi.org/project/pydal2sql-core)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pydal2sql-core.svg)](https://pypi.org/project/pydal2sql-core)  \n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)  \n[![su6 checks](https://github.com/robinvandernoord/pydal2sql-core/actions/workflows/su6.yml/badge.svg?branch=development)](https://github.com/robinvandernoord/pydal2sql-core/actions)\n![coverage.svg](coverage.svg)\n\n-----\n\nCompanion library for [`pydal2sql`](https://github.com/robinvandernoord/pydal2sql) containing the actual logic.\nThe other library only serves as a Typer-based CLI front-end.\n\n_More Documentation coming soon!_\n\n## Table of Contents\n\n- [Installation](#installation)\n- [As a Python Library](#as-a-python-library)\n- [License](#license)\n\n## Installation\n\n```bash\npip install pydal2sql-core\n```\n\n## As a Python Library\n\n`pydal2sql-core` also exposes a `generate_sql` method that can perform the same actions on one (for CREATE) or two (for\nALTER) `pydal.Table` objects when used within Python.\n\n```python\nfrom pydal import DAL, Field\nfrom pydal2sql_core import generate_sql\n\ndb = DAL(None, migrate=False)  # <- without running database or with a different type of database\n\nperson_initial = db.define_table(\n    \"person\",\n    Field(\n        \"name\",\n        \"string\",\n        notnull=True,\n    ),\n    Field(\"age\", \"integer\", default=18),\n    Field(\"float\", \"decimal(2,3)\"),\n    Field(\"nicknames\", \"list:string\"),\n    Field(\"obj\", \"json\"),\n)\n\nprint(\n    generate_sql(\n        db.person, db_type=\"psql\"  # or sqlite, or mysql; Optional with fallback to currently using database type.\n    )\n)\n```\n\n```sql\nCREATE TABLE person\n(\n    id        INTEGER PRIMARY KEY AUTOINCREMENT,\n    name      VARCHAR(512),\n    age       INTEGER,\n    float     NUMERIC(2, 3),\n    nicknames TEXT,\n    obj       TEXT\n);\n```\n\n```python\nperson_new = db.define_table(\n    \"person\",\n    Field(\n        \"name\",\n        \"text\",\n    ),\n    Field(\"birthday\", \"datetime\"),\n    redefine=True\n)\n\ngenerate_sql(\n    person_initial,\n    person_new,\n    db_type=\"psql\"\n)\n```\n\n```sql\nALTER TABLE person\n    ADD \"name__tmp\" TEXT;\nUPDATE person\nSET \"name__tmp\"=name;\nALTER TABLE person DROP COLUMN name;\nALTER TABLE person\n    ADD name TEXT;\nUPDATE person\nSET name=\"name__tmp\";\nALTER TABLE person DROP COLUMN \"name__tmp\";\nALTER TABLE person\n    ADD birthday TIMESTAMP;\nALTER TABLE person DROP COLUMN age;\nALTER TABLE person DROP COLUMN float;\nALTER TABLE person DROP COLUMN nicknames;\nALTER TABLE person DROP COLUMN obj;\n```\n\n## License\n\n`pydal2sql-core` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "CLI-agnostic pydal2sql code; Convert pydal define_tables to SQL using pydal's CREATE TABLE logic.",
    "version": "0.4.0",
    "project_urls": {
        "Documentation": "https://github.com/robinvandernoord/pydal2sql-core#readme",
        "Issues": "https://github.com/robinvandernoord/pydal2sql-core/issues",
        "Source": "https://github.com/robinvandernoord/pydal2sql-core"
    },
    "split_keywords": [
        "databases",
        " pydal",
        " sql"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "2603839eebc3578d8d35c20676090408026f948811a32a8373e8c77faa6978ef",
                "md5": "976830b0027cdbf626cfc567e285f4f3",
                "sha256": "eef5a67691ac72cb8f7b36a030071ba96c23eaef4fba3f684966786056c79364"
            },
            "downloads": -1,
            "filename": "pydal2sql_core-0.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "976830b0027cdbf626cfc567e285f4f3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 20664,
            "upload_time": "2024-08-05T16:10:54",
            "upload_time_iso_8601": "2024-08-05T16:10:54.984688Z",
            "url": "https://files.pythonhosted.org/packages/26/03/839eebc3578d8d35c20676090408026f948811a32a8373e8c77faa6978ef/pydal2sql_core-0.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "b307a9b83d700896861ba3f1b396df2771efecad51aca51b6197ac90b5d31ff9",
                "md5": "8c3ead11ed98835dd9dbf2f7ca69d7d6",
                "sha256": "eb3058d820be202845b5c63a34af58f2c71ec89614b79459bd7f470d87e5bc3c"
            },
            "downloads": -1,
            "filename": "pydal2sql_core-0.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "8c3ead11ed98835dd9dbf2f7ca69d7d6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 151698,
            "upload_time": "2024-08-05T16:10:52",
            "upload_time_iso_8601": "2024-08-05T16:10:52.884624Z",
            "url": "https://files.pythonhosted.org/packages/b3/07/a9b83d700896861ba3f1b396df2771efecad51aca51b6197ac90b5d31ff9/pydal2sql_core-0.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-05 16:10:52",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "robinvandernoord",
    "github_project": "pydal2sql-core#readme",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pydal2sql-core"
}
        
Elapsed time: 4.50315s