sqrl


Namesqrl JSON
Version 0.2.0 PyPI version JSON
download
home_pageNone
Summarya lightweight sqlite API that can do just about everything you need and allows you to fill in any gaps
upload_time2024-08-02 16:16:48
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # SQrL 🐿️
a lightweight sqlite API for Python

### Getting Started
```python
from sqrl import SQL # database API
db = SQL("sample.db")
```
### Quick Intro
#### Select Statements
```python
from sqrl import SQL

db = SQL("sample.db")

db.select(
    "track", ["title", "duration", "artist_id"], order_by="track_number"
)  # SELECT title, duration, artist_id FROM track ORDER BY track_number;

db.select("album")  # SELECT * FROM album;

# get as funky as you want with it
db.select(
    "album ab join artist ar on ab.artist_id = ar.id",
    ["ab.title", "ar.name"],
    order_by="year",
    asc=False,
    where="ab.genre = 'soul'",
    limit=10,
    return_as_dict=True
)
# set 'row_factory' to None to get value tuples
# or return_as_dict to get dictionary objects


# and of course, writing completely raw sql still available
# reccomended for parameterization at the moment
db.fetch("SELECT * FROM album WHERE year >= ? AND artist_id = ?;", 2000, 57)

# you specify whether fetchall, fetchone or fetchmany is used with 'n'
db.fetch("SELECT * FROM artist WHERE id = ?", 57, n=1, return_as_dict=True)
```
#### CrUD
insert, update and delete from tables using dedicated methods.
built with Flask and JSON REST APIs in mind.
```python
from sqrl import SQL

db = SQL("sample.db")

# insert into database
db.insert(
    table_name="album",
    data={
        "id": 1,
        "title": "myalbum",
        "artist_id": 10,
        "year": 2024,
        "genre": "alternative"
    }
)
# parameterization safe! generated under the hood ->
db.execute(
    "INSERT INTO album (id, title, artist_id, year, genre) VALUES (?, ?, ?, ?, ?);",
    1, "myalbum", 10, 2024, "alternative",
    as_transaction=True
)

# update something in a table
db.update(
    table_name="album",
    data={
        "title": "a new title"
    },
    where=f"id = {1}"
)
# delete from table
db.delete(
    table_name="album", where=f"id = {1}"
)
# although the param dictionary for update is parameterized, the where clause is not. so you can use db.execute
# to execute full SQL statements i.e. db.execute("DELETE FROM album WHERE id = ?", 1)
```

#### Aggregations
perform aggregations on a chosen table with dedicated methods
```python
from sqrl import SQL

db = SQL("sample.db")
db.max(table_name="invoice", column="amount")
db.min("invoice", "amount")
db.avg("invoice", "amount", 2)  # ROUND(AVG(amount), 2)
db.count("invoice")
db.sum("invoice", "amount")
```

#### Exporting
```python
from sqrl import SQL

db = SQL("sample.db")

db.export_to_csv()  # exports every table in database to csv as [tablename].csv
db.export_table_to_csv("tracks")  # export just a single table
db.dump()  # writes the entire database schema to .sql, can specify 'out_file' by default will by named after database file
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "sqrl",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "Oliver <oliverbcontact@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/15/58/b8856d061d94e0e64ada6b2fa293780cd6f0114a9c2377bc7852896800e8/sqrl-0.2.0.tar.gz",
    "platform": null,
    "description": "# SQrL \ud83d\udc3f\ufe0f\r\na lightweight sqlite API for Python\r\n\r\n### Getting Started\r\n```python\r\nfrom sqrl import SQL # database API\r\ndb = SQL(\"sample.db\")\r\n```\r\n### Quick Intro\r\n#### Select Statements\r\n```python\r\nfrom sqrl import SQL\r\n\r\ndb = SQL(\"sample.db\")\r\n\r\ndb.select(\r\n    \"track\", [\"title\", \"duration\", \"artist_id\"], order_by=\"track_number\"\r\n)  # SELECT title, duration, artist_id FROM track ORDER BY track_number;\r\n\r\ndb.select(\"album\")  # SELECT * FROM album;\r\n\r\n# get as funky as you want with it\r\ndb.select(\r\n    \"album ab join artist ar on ab.artist_id = ar.id\",\r\n    [\"ab.title\", \"ar.name\"],\r\n    order_by=\"year\",\r\n    asc=False,\r\n    where=\"ab.genre = 'soul'\",\r\n    limit=10,\r\n    return_as_dict=True\r\n)\r\n# set 'row_factory' to None to get value tuples\r\n# or return_as_dict to get dictionary objects\r\n\r\n\r\n# and of course, writing completely raw sql still available\r\n# reccomended for parameterization at the moment\r\ndb.fetch(\"SELECT * FROM album WHERE year >= ? AND artist_id = ?;\", 2000, 57)\r\n\r\n# you specify whether fetchall, fetchone or fetchmany is used with 'n'\r\ndb.fetch(\"SELECT * FROM artist WHERE id = ?\", 57, n=1, return_as_dict=True)\r\n```\r\n#### CrUD\r\ninsert, update and delete from tables using dedicated methods.\r\nbuilt with Flask and JSON REST APIs in mind.\r\n```python\r\nfrom sqrl import SQL\r\n\r\ndb = SQL(\"sample.db\")\r\n\r\n# insert into database\r\ndb.insert(\r\n    table_name=\"album\",\r\n    data={\r\n        \"id\": 1,\r\n        \"title\": \"myalbum\",\r\n        \"artist_id\": 10,\r\n        \"year\": 2024,\r\n        \"genre\": \"alternative\"\r\n    }\r\n)\r\n# parameterization safe! generated under the hood ->\r\ndb.execute(\r\n    \"INSERT INTO album (id, title, artist_id, year, genre) VALUES (?, ?, ?, ?, ?);\",\r\n    1, \"myalbum\", 10, 2024, \"alternative\",\r\n    as_transaction=True\r\n)\r\n\r\n# update something in a table\r\ndb.update(\r\n    table_name=\"album\",\r\n    data={\r\n        \"title\": \"a new title\"\r\n    },\r\n    where=f\"id = {1}\"\r\n)\r\n# delete from table\r\ndb.delete(\r\n    table_name=\"album\", where=f\"id = {1}\"\r\n)\r\n# although the param dictionary for update is parameterized, the where clause is not. so you can use db.execute\r\n# to execute full SQL statements i.e. db.execute(\"DELETE FROM album WHERE id = ?\", 1)\r\n```\r\n\r\n#### Aggregations\r\nperform aggregations on a chosen table with dedicated methods\r\n```python\r\nfrom sqrl import SQL\r\n\r\ndb = SQL(\"sample.db\")\r\ndb.max(table_name=\"invoice\", column=\"amount\")\r\ndb.min(\"invoice\", \"amount\")\r\ndb.avg(\"invoice\", \"amount\", 2)  # ROUND(AVG(amount), 2)\r\ndb.count(\"invoice\")\r\ndb.sum(\"invoice\", \"amount\")\r\n```\r\n\r\n#### Exporting\r\n```python\r\nfrom sqrl import SQL\r\n\r\ndb = SQL(\"sample.db\")\r\n\r\ndb.export_to_csv()  # exports every table in database to csv as [tablename].csv\r\ndb.export_table_to_csv(\"tracks\")  # export just a single table\r\ndb.dump()  # writes the entire database schema to .sql, can specify 'out_file' by default will by named after database file\r\n```\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "a lightweight sqlite API that can do just about everything you need and allows you to fill in any gaps",
    "version": "0.2.0",
    "project_urls": {
        "Homepage": "https://github.com/olivesnake/sqrl",
        "Issues": "https://github.com/olivesnake/sqrl/issues"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "691f2d7813e4f36ad079998f2c977e8ff1b62fc0e11aebeaddccc52e96c34a21",
                "md5": "a572c98a005001c1329ecf110f4d64c3",
                "sha256": "324ddeb82669104e79e4dfe84b80b1d591c036ec9eb9fa7863ae0d79f8a41c7b"
            },
            "downloads": -1,
            "filename": "sqrl-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a572c98a005001c1329ecf110f4d64c3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 22361,
            "upload_time": "2024-08-02T16:16:47",
            "upload_time_iso_8601": "2024-08-02T16:16:47.272649Z",
            "url": "https://files.pythonhosted.org/packages/69/1f/2d7813e4f36ad079998f2c977e8ff1b62fc0e11aebeaddccc52e96c34a21/sqrl-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1558b8856d061d94e0e64ada6b2fa293780cd6f0114a9c2377bc7852896800e8",
                "md5": "559fc9b50bda5ca19a6985d00dac3fbe",
                "sha256": "65a71395c10ff33e451bbcd2a243d84038fad04e444822f96ec0cd5383382a4b"
            },
            "downloads": -1,
            "filename": "sqrl-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "559fc9b50bda5ca19a6985d00dac3fbe",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 22865,
            "upload_time": "2024-08-02T16:16:48",
            "upload_time_iso_8601": "2024-08-02T16:16:48.675724Z",
            "url": "https://files.pythonhosted.org/packages/15/58/b8856d061d94e0e64ada6b2fa293780cd6f0114a9c2377bc7852896800e8/sqrl-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-02 16:16:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "olivesnake",
    "github_project": "sqrl",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "sqrl"
}
        
Elapsed time: 0.46751s