SQLiteCls


NameSQLiteCls JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/TheMatjaz/SQLiteCls
SummarySQLite API wrapped into a class with automatic DB schema initialisation and PRAGMA execution upon connection
upload_time2021-04-21 15:26:44
maintainer
docs_urlNone
authorMatjaž Guštin
requires_python>=3
licenseBSD
keywords sqlite sqlite3 database wrapper class with
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            SQLite Class wrapper with auto-initialisation of empty DB and PRAGMAs
===============================================================================

SQLiteDb class wrapping the operations from the `sqlite3` module,
providing better support for the `with` operator and automatic
initialisation of an empty DB upon first creation of the DB
and setting of the per-connection pragmas.

Additional wrappers are available as a utility, including
extraction of a list of tables, extraction of the list of columns
of a `SELECT` query, commit, rollback, start of a transaction,
check if the DB is in memory and if it's empty. Executions of SQL script
files is also made easy.


Example usage
----------------------------------------

```python
import sqlitecls

with sqlitecls.SqliteDb('mydata.db', 'mydbschema.sql', 'mypragmas.sql') as db:
    # Now the DB connection is established. If the DB did not exist before,
    # its schema is initialised by running the 'mydbschema.sql' script,
    # preparing it for whatever your application has to do.
    #
    # The 'mypragmas.sql' script is also run EVERY time a connection is
    # opened or re-opened, to ensure each connection to the same file has
    # the correct per-connection PRAGMA settings.
    # For example, imagine we have `PRAGMA synchronous = 3;` in the script
    assert db.pragma('synchronous') == 3

    # You can easily check which tables are available
    tables = db.tables_names()
    # and what columns they have
    columns = db.columns_names('some_table')
    # Otherwise use as any other DB API from now on
    cursor = db.execute('SELECT * FROM mytable')
    # Simplified extraction of the column names from the SELECT query
    columns = sqlitecls.cursor_column_names(cursor)
    # Use as any other DB API from now on
    for row in cursor:
        pass  # Do something with each row
    db.connection, db.cursor  # Accessible for custom operations
    # More utility functions!
    db.start_transaction()
    db.commit()
    db.rollback()
    db.vacuum()
    db.size_bytes()
    db.is_in_memory()
    # Have existing SQL script files? Just run them as they are!
    db.execute_sql_file('myotherfile.sql')  # Load WHOLE file in memory
# Connection automatically closed now
```


Installation
----------------------------------------

```
pip install SQLteCls
```

or just include the `sqlitecls.py` file in your project (copy-paste).
It's self-contained and has no dependencies other than the standard
Python library.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/TheMatjaz/SQLiteCls",
    "name": "SQLiteCls",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3",
    "maintainer_email": "",
    "keywords": "sqlite,sqlite3,database,wrapper,class,with",
    "author": "Matja\u017e Gu\u0161tin",
    "author_email": "dev@matjaz.it",
    "download_url": "https://files.pythonhosted.org/packages/6e/9d/5cabe99c28ee58ea4f22b59f27fa3b4d0afe0ca654ead503deaecdd870ff/SQLiteCls-1.0.0.tar.gz",
    "platform": "",
    "description": "SQLite Class wrapper with auto-initialisation of empty DB and PRAGMAs\n===============================================================================\n\nSQLiteDb class wrapping the operations from the `sqlite3` module,\nproviding better support for the `with` operator and automatic\ninitialisation of an empty DB upon first creation of the DB\nand setting of the per-connection pragmas.\n\nAdditional wrappers are available as a utility, including\nextraction of a list of tables, extraction of the list of columns\nof a `SELECT` query, commit, rollback, start of a transaction,\ncheck if the DB is in memory and if it's empty. Executions of SQL script\nfiles is also made easy.\n\n\nExample usage\n----------------------------------------\n\n```python\nimport sqlitecls\n\nwith sqlitecls.SqliteDb('mydata.db', 'mydbschema.sql', 'mypragmas.sql') as db:\n    # Now the DB connection is established. If the DB did not exist before,\n    # its schema is initialised by running the 'mydbschema.sql' script,\n    # preparing it for whatever your application has to do.\n    #\n    # The 'mypragmas.sql' script is also run EVERY time a connection is\n    # opened or re-opened, to ensure each connection to the same file has\n    # the correct per-connection PRAGMA settings.\n    # For example, imagine we have `PRAGMA synchronous = 3;` in the script\n    assert db.pragma('synchronous') == 3\n\n    # You can easily check which tables are available\n    tables = db.tables_names()\n    # and what columns they have\n    columns = db.columns_names('some_table')\n    # Otherwise use as any other DB API from now on\n    cursor = db.execute('SELECT * FROM mytable')\n    # Simplified extraction of the column names from the SELECT query\n    columns = sqlitecls.cursor_column_names(cursor)\n    # Use as any other DB API from now on\n    for row in cursor:\n        pass  # Do something with each row\n    db.connection, db.cursor  # Accessible for custom operations\n    # More utility functions!\n    db.start_transaction()\n    db.commit()\n    db.rollback()\n    db.vacuum()\n    db.size_bytes()\n    db.is_in_memory()\n    # Have existing SQL script files? Just run them as they are!\n    db.execute_sql_file('myotherfile.sql')  # Load WHOLE file in memory\n# Connection automatically closed now\n```\n\n\nInstallation\n----------------------------------------\n\n```\npip install SQLteCls\n```\n\nor just include the `sqlitecls.py` file in your project (copy-paste).\nIt's self-contained and has no dependencies other than the standard\nPython library.\n\n\n",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "SQLite API wrapped into a class with automatic DB schema initialisation and PRAGMA execution upon connection",
    "version": "1.0.0",
    "split_keywords": [
        "sqlite",
        "sqlite3",
        "database",
        "wrapper",
        "class",
        "with"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "0a138fcdbb5ff56496933cce43e5092a",
                "sha256": "d02c50dfb4dcb19c7cd90a8af398d45ab0110b93bcf5670d376ba4a46e2cde1c"
            },
            "downloads": -1,
            "filename": "SQLiteCls-1.0.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0a138fcdbb5ff56496933cce43e5092a",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3",
            "size": 5883,
            "upload_time": "2021-04-21T15:26:42",
            "upload_time_iso_8601": "2021-04-21T15:26:42.970462Z",
            "url": "https://files.pythonhosted.org/packages/85/32/aa63ed266036c10402fed904f7f867cf660f7aa4f7fdbfba8cf57f294395/SQLiteCls-1.0.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "466fe4a907f8744ad05816c626bc6cef",
                "sha256": "237ba2ede7b956c47b02412c4cac9fc72c24142930bcc9fcc6599ad79d29be9b"
            },
            "downloads": -1,
            "filename": "SQLiteCls-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "466fe4a907f8744ad05816c626bc6cef",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3",
            "size": 7422,
            "upload_time": "2021-04-21T15:26:44",
            "upload_time_iso_8601": "2021-04-21T15:26:44.611998Z",
            "url": "https://files.pythonhosted.org/packages/6e/9d/5cabe99c28ee58ea4f22b59f27fa3b4d0afe0ca654ead503deaecdd870ff/SQLiteCls-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-04-21 15:26:44",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": null,
    "github_project": "TheMatjaz",
    "error": "Could not fetch GitHub repository",
    "lcname": "sqlitecls"
}
        
Elapsed time: 0.28806s