ezlocaldb


Nameezlocaldb JSON
Version 0.0.1 PyPI version JSON
download
home_page
SummaryEasy local SQL databases for no-sweat persistence
upload_time2023-09-18 03:28:14
maintainer
docs_urlNone
author
requires_python>=3.8
licenseMIT License Copyright (c) 2023 sterlingcollins 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.
keywords database sql persistence
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ezlocaldb

Version 0.0.1

Easy, local databases for no-sweat persistence. This convinience package wraps
small parts of `appdirs`, `sqlite3`, and `sqlalchemy`, to easily create
databases for local applications. The package saves about 15 lines of code, but
it's 15 lines I find myself writting at the start of many projects, so maybe it
will save you some time too.

## Installation

### PIP
The easiest way to install `ezlocaldb` is with pip
```bash
  pip install ezlocaldb
```

## Usage/Examples

### Quick Start
To work with `sqlalchemy` use `get_engine` to get an `engine` object for
database access. The first argument to `get_engine` is the name of your
application, which is used to uniquely specify the database.

```python
from ezlocaldb import get_engine
from sqlalchemy import Session

# Get an sqlalchemy engine to use with sqlalchemy.Session
engine = get_engine(app_name="MyAmazingApp")

with Session(engine) as session:
    # Now work with session to initalize database,
    # or execute other CRUD operations.
    pass
```

When you call `get_engine`, ezlocaldb checks to see if your database was created
previously. If it wasn't it creates a new `sqlite` database. Either way, it
returns an `engine` which can be used to access the database.

### Removing or refreshing databases
If you want to remove or refresh the database, use

```python
from ezlocaldb import remove_database, get_engine

remove_database("MyAmazingApp")

# To recreate the database (with no data in it) use
engine = get_engine("MyAmazingApp")
```

### Initializing the Schema
Usually, getting tables and such setup is just a little tricky. When should you
emit `CREATE TABLE` commands? Is everything in place? Did you just overwrite
your data?

With `ezlocaldb` you can pass a `sqlalchemy.MetaData` instance as a keyword
argument to `get_engine`. If you're using the ORM, it's as simple as this:

```python
from sqlalchemy.orm import DeclarativeBase
from ezlocaldb import get_engine

class Base(DeclarativeBase):
   pass

# More ORM classes derived from Base
# ...

engine = get_engine('MyAmazingApp',metadata=Base.metadata)
```

If your database file hasn't been created, `get_engine` will `create_all` the
tables, etc. represented in your ORM tree. If the file was previously created,
the metadata argument is ignored. This way you can quickly get a database setup
for orm operations, and not worry about accidentally overwritting all your data.

If you make changes to your ORM structure, you can use `remove_database` from a
repl or other function, and call `get_engine` with the `metadata` argument again,
and the new database will reflect all your new structure.

> **A note on migrations**.
> Database migrations are a complicated subject. If you want to keep your data
> while you revise your ORM structure or Database Schema, you're probably ready
> to graduate to using full `SQLAlchemy`, and look at `Alembic`.

### Thank You!

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "ezlocaldb",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "Database,SQL,Persistence",
    "author": "",
    "author_email": "Sterling Collins <sterlingcollins@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/ef/c7/d4c9a527b8e758ceeb516ba034c24673c5e7ed5bedd7e97c635179b2db8f/ezlocaldb-0.0.1.tar.gz",
    "platform": null,
    "description": "# ezlocaldb\n\nVersion 0.0.1\n\nEasy, local databases for no-sweat persistence. This convinience package wraps\nsmall parts of `appdirs`, `sqlite3`, and `sqlalchemy`, to easily create\ndatabases for local applications. The package saves about 15 lines of code, but\nit's 15 lines I find myself writting at the start of many projects, so maybe it\nwill save you some time too.\n\n## Installation\n\n### PIP\nThe easiest way to install `ezlocaldb` is with pip\n```bash\n  pip install ezlocaldb\n```\n\n## Usage/Examples\n\n### Quick Start\nTo work with `sqlalchemy` use `get_engine` to get an `engine` object for\ndatabase access. The first argument to `get_engine` is the name of your\napplication, which is used to uniquely specify the database.\n\n```python\nfrom ezlocaldb import get_engine\nfrom sqlalchemy import Session\n\n# Get an sqlalchemy engine to use with sqlalchemy.Session\nengine = get_engine(app_name=\"MyAmazingApp\")\n\nwith Session(engine) as session:\n    # Now work with session to initalize database,\n    # or execute other CRUD operations.\n    pass\n```\n\nWhen you call `get_engine`, ezlocaldb checks to see if your database was created\npreviously. If it wasn't it creates a new `sqlite` database. Either way, it\nreturns an `engine` which can be used to access the database.\n\n### Removing or refreshing databases\nIf you want to remove or refresh the database, use\n\n```python\nfrom ezlocaldb import remove_database, get_engine\n\nremove_database(\"MyAmazingApp\")\n\n# To recreate the database (with no data in it) use\nengine = get_engine(\"MyAmazingApp\")\n```\n\n### Initializing the Schema\nUsually, getting tables and such setup is just a little tricky. When should you\nemit `CREATE TABLE` commands? Is everything in place? Did you just overwrite\nyour data?\n\nWith `ezlocaldb` you can pass a `sqlalchemy.MetaData` instance as a keyword\nargument to `get_engine`. If you're using the ORM, it's as simple as this:\n\n```python\nfrom sqlalchemy.orm import DeclarativeBase\nfrom ezlocaldb import get_engine\n\nclass Base(DeclarativeBase):\n   pass\n\n# More ORM classes derived from Base\n# ...\n\nengine = get_engine('MyAmazingApp',metadata=Base.metadata)\n```\n\nIf your database file hasn't been created, `get_engine` will `create_all` the\ntables, etc. represented in your ORM tree. If the file was previously created,\nthe metadata argument is ignored. This way you can quickly get a database setup\nfor orm operations, and not worry about accidentally overwritting all your data.\n\nIf you make changes to your ORM structure, you can use `remove_database` from a\nrepl or other function, and call `get_engine` with the `metadata` argument again,\nand the new database will reflect all your new structure.\n\n> **A note on migrations**.\n> Database migrations are a complicated subject. If you want to keep your data\n> while you revise your ORM structure or Database Schema, you're probably ready\n> to graduate to using full `SQLAlchemy`, and look at `Alembic`.\n\n### Thank You!\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 sterlingcollins  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. ",
    "summary": "Easy local SQL databases for no-sweat persistence",
    "version": "0.0.1",
    "project_urls": null,
    "split_keywords": [
        "database",
        "sql",
        "persistence"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bb7a1cadc379ffd6697ba6ed10e9f69a2833f7d0a0ee7f3e0088ec48d31f574d",
                "md5": "eda21964a52da660658dd32360f4646d",
                "sha256": "696217c2b7fa83496fc9d6e6e0ede9a8ee129fff695fdb1022e31f666a2095b4"
            },
            "downloads": -1,
            "filename": "ezlocaldb-0.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "eda21964a52da660658dd32360f4646d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 5006,
            "upload_time": "2023-09-18T03:28:12",
            "upload_time_iso_8601": "2023-09-18T03:28:12.776856Z",
            "url": "https://files.pythonhosted.org/packages/bb/7a/1cadc379ffd6697ba6ed10e9f69a2833f7d0a0ee7f3e0088ec48d31f574d/ezlocaldb-0.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "efc7d4c9a527b8e758ceeb516ba034c24673c5e7ed5bedd7e97c635179b2db8f",
                "md5": "091d24d978e3f16c2bf24f8db903e5a0",
                "sha256": "d99c30c4310361bcbf030f1937c6d3dc969fc11385d8b94fbff0e6959e38a56c"
            },
            "downloads": -1,
            "filename": "ezlocaldb-0.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "091d24d978e3f16c2bf24f8db903e5a0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 8301,
            "upload_time": "2023-09-18T03:28:14",
            "upload_time_iso_8601": "2023-09-18T03:28:14.635383Z",
            "url": "https://files.pythonhosted.org/packages/ef/c7/d4c9a527b8e758ceeb516ba034c24673c5e7ed5bedd7e97c635179b2db8f/ezlocaldb-0.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-18 03:28:14",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "ezlocaldb"
}
        
Elapsed time: 0.11574s