sqla-fancy-core


Namesqla-fancy-core JSON
Version 0.2.0 PyPI version JSON
download
home_page
SummarySQLAlchemy core, but fancier
upload_time2023-03-20 04:33:17
maintainer
docs_urlNone
authorArijit Basu
requires_python>=3.7,<4.0
licenseMIT
keywords sql sqlalchemy sqlalchemy-core
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # sqla-fancy-core

SQLAlchemy core, but fancier.

```python
import sqlalchemy as sa

from sqla_fancy_core import TableFactory

metadata = sa.MetaData()
tf = TableFactory()

# Define a table
class Author:

    id = tf.auto_id()
    name = tf.string("name")
    created_at = tf.created_at()
    updated_at = tf.updated_at()

    Table = tf("author", metadata)

# Define a table
class Book:

    id = tf.auto_id()
    title = tf.string("title")
    author_id = tf.foreign_key("author_id", Author.id)
    created_at = tf.created_at()
    updated_at = tf.updated_at()

    Table = tf("book", metadata)

# Create the tables
engine = sa.create_engine("sqlite:///:memory:")
metadata.create_all(engine)

with engine.connect() as conn:
    # Insert author
    qry = (
        sa.insert(Author.Table)
        .values({Author.name: "John Doe"})
        .returning(Author.id)
    )
    author = next(conn.execute(qry))
    (author_id,) = author
    assert author_id == 1

    # Insert book
    qry = (
        sa.insert(Book.Table)
        .values({Book.title: "My Book", Book.author_id: author_id})
        .returning(Book.id)
    )
    book = next(conn.execute(qry))
    (book_id,) = book
    assert book_id == 1

    # Query the data
    qry = sa.select(Author.name, Book.title).join(
        Book.Table,
        Book.author_id == Author.id,
    )
    result = conn.execute(qry).fetchall()
    assert result == [("John Doe", "My Book")], result
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "sqla-fancy-core",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7,<4.0",
    "maintainer_email": "",
    "keywords": "sql,sqlalchemy,sqlalchemy-core",
    "author": "Arijit Basu",
    "author_email": "sayanarijit@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/15/7a/cc02299d29f5bae3c3011b093bfa0dd0ff5c139a781c63cdc9083eb28f85/sqla_fancy_core-0.2.0.tar.gz",
    "platform": null,
    "description": "# sqla-fancy-core\n\nSQLAlchemy core, but fancier.\n\n```python\nimport sqlalchemy as sa\n\nfrom sqla_fancy_core import TableFactory\n\nmetadata = sa.MetaData()\ntf = TableFactory()\n\n# Define a table\nclass Author:\n\n    id = tf.auto_id()\n    name = tf.string(\"name\")\n    created_at = tf.created_at()\n    updated_at = tf.updated_at()\n\n    Table = tf(\"author\", metadata)\n\n# Define a table\nclass Book:\n\n    id = tf.auto_id()\n    title = tf.string(\"title\")\n    author_id = tf.foreign_key(\"author_id\", Author.id)\n    created_at = tf.created_at()\n    updated_at = tf.updated_at()\n\n    Table = tf(\"book\", metadata)\n\n# Create the tables\nengine = sa.create_engine(\"sqlite:///:memory:\")\nmetadata.create_all(engine)\n\nwith engine.connect() as conn:\n    # Insert author\n    qry = (\n        sa.insert(Author.Table)\n        .values({Author.name: \"John Doe\"})\n        .returning(Author.id)\n    )\n    author = next(conn.execute(qry))\n    (author_id,) = author\n    assert author_id == 1\n\n    # Insert book\n    qry = (\n        sa.insert(Book.Table)\n        .values({Book.title: \"My Book\", Book.author_id: author_id})\n        .returning(Book.id)\n    )\n    book = next(conn.execute(qry))\n    (book_id,) = book\n    assert book_id == 1\n\n    # Query the data\n    qry = sa.select(Author.name, Book.title).join(\n        Book.Table,\n        Book.author_id == Author.id,\n    )\n    result = conn.execute(qry).fetchall()\n    assert result == [(\"John Doe\", \"My Book\")], result\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "SQLAlchemy core, but fancier",
    "version": "0.2.0",
    "split_keywords": [
        "sql",
        "sqlalchemy",
        "sqlalchemy-core"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "056997e982e61bcdfb570ba04b0265d59ac558d55ecb1ae6cadc8b7dc6fcb2b1",
                "md5": "54a90acd32006d744cabe497d8c4dfdb",
                "sha256": "61b4bcb6221c0304aecef7c84c83f98ec62ec24fbf6a20df1d4f463015823cc6"
            },
            "downloads": -1,
            "filename": "sqla_fancy_core-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "54a90acd32006d744cabe497d8c4dfdb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<4.0",
            "size": 3303,
            "upload_time": "2023-03-20T04:33:15",
            "upload_time_iso_8601": "2023-03-20T04:33:15.212981Z",
            "url": "https://files.pythonhosted.org/packages/05/69/97e982e61bcdfb570ba04b0265d59ac558d55ecb1ae6cadc8b7dc6fcb2b1/sqla_fancy_core-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "157acc02299d29f5bae3c3011b093bfa0dd0ff5c139a781c63cdc9083eb28f85",
                "md5": "a26121200ba35a35e88f8beed3e0f34f",
                "sha256": "6a8c65a354750099b9e5dc59a4a249b883810cf1bd8d73d4c71381686bf8b117"
            },
            "downloads": -1,
            "filename": "sqla_fancy_core-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a26121200ba35a35e88f8beed3e0f34f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7,<4.0",
            "size": 3270,
            "upload_time": "2023-03-20T04:33:17",
            "upload_time_iso_8601": "2023-03-20T04:33:17.203466Z",
            "url": "https://files.pythonhosted.org/packages/15/7a/cc02299d29f5bae3c3011b093bfa0dd0ff5c139a781c63cdc9083eb28f85/sqla_fancy_core-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-20 04:33:17",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "sqla-fancy-core"
}
        
Elapsed time: 0.04903s