DBbeginners


NameDBbeginners JSON
Version 1.0.0 PyPI version JSON
download
home_pageNone
SummaryA lightweight SQLite database utility module
upload_time2024-10-05 14:14:29
maintainerNone
docs_urlNone
authorVollo
requires_python>=3.7
licenseMIT
keywords sqlite sql database utility
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            DataBase Class Documentation
The DataBase class is designed to interact with SQLite databases, providing methods for creating tables, inserting data, querying data, updating data, deleting data, and managing transactions. It also offers utility methods for getting affected rows count, table columns, and table rows count.

Table of Contents

def __init__(self, db_name: str, table_name: str, columns: List[str]):
    self.db_name = db_name
    self.table_name = table_name
    self.columns = columns
    self.conn = None

Initializes the DataBase object with the given database name, table name, and column names. The connection to the database is established when needed.

Connecting and Closing Database
def connect(self) -> None:
    # ...

def close(self) -> None:
    # ...

The connect method establishes a connection to the database if it's not already connected. The close method closes the database connection if it's open.

Creating Table
def create_table(self) -> None:
    # ...

Creates a table in the database with the specified name and columns. If the table already exists, it does nothing.

Inserting Data
def insert_data(self, data: List[Tuple]) -> None:
    # ...

Inserts the given data into the table. The data should be a list of tuples, where each tuple represents a row of data.

Querying Data
def select_data(self, query: str) -> List[Tuple]:
    # ...

Executes the given SQL query and returns the result as a list of tuples. If the query is invalid or fails to execute, it returns an empty list.

Updating Data
def update_data(self, query: str) -> None:
    # ...

Executes the given SQL query to update data in the table. If the query is invalid or fails to execute, it prints an error message.

Deleting Data
def delete_data(self, query: str) -> None:
    # ...

Executes the given SQL query to delete data from the table. If the query is invalid or fails to execute, it prints an error message.

Transaction Management
def begin_transaction(self) -> None:
    # ...

def commit_transaction(self) -> None:
    # ...

def rollback_transaction(self) -> None:
    # ...

The begin_transaction method starts a new transaction. The commit_transaction method commits the current transaction. The rollback_transaction method rolls back the current transaction.

Executing Raw Query
def execute_raw_query(self, query: str) -> None:
    # ...

Executes the given raw SQL query and commits the transaction. If the query is invalid or fails to execute, it prints an error message.

Getting Affected Rows Count
def get_affected_rows(self) -> int:
    # ...

Returns the number of rows affected by the last SQL statement.

Getting Table Columns
def get_table_columns(self) -> List[str]:
    # ...

Returns a list of column names in the table. If there's an error retrieving the columns, it returns an empty list.

Getting Table Rows Count
def get_table_rows_count(self) -> int:
    # ...

Returns the number of rows in the table. If there's an error retrieving the row count, it returns 0.

Example Usage
db = DataBase('example.db', 'users', ['id', 'name', 'email'])

# Create table
db.create_table()

# Insert data
data = [(1, 'John Doe', 'john.doe@example.com'), (2, 'Jane Smith', 'jane.smith@example.com')]
db.insert_data(data)

# Query data
result = db.select_data('SELECT * FROM users')
print(result)

# Update data
db.update_data('UPDATE users SET email = "john.doe.updated@example.com" WHERE id = 1')

# Delete data
db.delete_data('DELETE FROM users WHERE id = 2')

# Get affected rows count
affected_rows = db.get_affected_rows()
print(f"Affected rows: {affected_rows}")

# Get table columns
columns = db.get_table_columns()
print(f"Table columns: {columns}")

# Get table rows count
rows_count = db.get_table_rows_count()
print(f"Table rows count: {rows_count}")

# Close the database connection
db.close()

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "DBbeginners",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "sqlite sql database utility",
    "author": "Vollo",
    "author_email": "p300x5@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/e5/17/3904f151a286699c04a2cdeb8fa937391854a4b147d28b40a7258a9a7192/dbbeginners-1.0.0.tar.gz",
    "platform": null,
    "description": "DataBase Class Documentation\r\nThe DataBase class is designed to interact with SQLite databases, providing methods for creating tables, inserting data, querying data, updating data, deleting data, and managing transactions. It also offers utility methods for getting affected rows count, table columns, and table rows count.\r\n\r\nTable of Contents\r\n\r\ndef __init__(self, db_name: str, table_name: str, columns: List[str]):\r\n    self.db_name = db_name\r\n    self.table_name = table_name\r\n    self.columns = columns\r\n    self.conn = None\r\n\r\nInitializes the DataBase object with the given database name, table name, and column names. The connection to the database is established when needed.\r\n\r\nConnecting and Closing Database\r\ndef connect(self) -> None:\r\n    # ...\r\n\r\ndef close(self) -> None:\r\n    # ...\r\n\r\nThe connect method establishes a connection to the database if it's not already connected. The close method closes the database connection if it's open.\r\n\r\nCreating Table\r\ndef create_table(self) -> None:\r\n    # ...\r\n\r\nCreates a table in the database with the specified name and columns. If the table already exists, it does nothing.\r\n\r\nInserting Data\r\ndef insert_data(self, data: List[Tuple]) -> None:\r\n    # ...\r\n\r\nInserts the given data into the table. The data should be a list of tuples, where each tuple represents a row of data.\r\n\r\nQuerying Data\r\ndef select_data(self, query: str) -> List[Tuple]:\r\n    # ...\r\n\r\nExecutes the given SQL query and returns the result as a list of tuples. If the query is invalid or fails to execute, it returns an empty list.\r\n\r\nUpdating Data\r\ndef update_data(self, query: str) -> None:\r\n    # ...\r\n\r\nExecutes the given SQL query to update data in the table. If the query is invalid or fails to execute, it prints an error message.\r\n\r\nDeleting Data\r\ndef delete_data(self, query: str) -> None:\r\n    # ...\r\n\r\nExecutes the given SQL query to delete data from the table. If the query is invalid or fails to execute, it prints an error message.\r\n\r\nTransaction Management\r\ndef begin_transaction(self) -> None:\r\n    # ...\r\n\r\ndef commit_transaction(self) -> None:\r\n    # ...\r\n\r\ndef rollback_transaction(self) -> None:\r\n    # ...\r\n\r\nThe begin_transaction method starts a new transaction. The commit_transaction method commits the current transaction. The rollback_transaction method rolls back the current transaction.\r\n\r\nExecuting Raw Query\r\ndef execute_raw_query(self, query: str) -> None:\r\n    # ...\r\n\r\nExecutes the given raw SQL query and commits the transaction. If the query is invalid or fails to execute, it prints an error message.\r\n\r\nGetting Affected Rows Count\r\ndef get_affected_rows(self) -> int:\r\n    # ...\r\n\r\nReturns the number of rows affected by the last SQL statement.\r\n\r\nGetting Table Columns\r\ndef get_table_columns(self) -> List[str]:\r\n    # ...\r\n\r\nReturns a list of column names in the table. If there's an error retrieving the columns, it returns an empty list.\r\n\r\nGetting Table Rows Count\r\ndef get_table_rows_count(self) -> int:\r\n    # ...\r\n\r\nReturns the number of rows in the table. If there's an error retrieving the row count, it returns 0.\r\n\r\nExample Usage\r\ndb = DataBase('example.db', 'users', ['id', 'name', 'email'])\r\n\r\n# Create table\r\ndb.create_table()\r\n\r\n# Insert data\r\ndata = [(1, 'John Doe', 'john.doe@example.com'), (2, 'Jane Smith', 'jane.smith@example.com')]\r\ndb.insert_data(data)\r\n\r\n# Query data\r\nresult = db.select_data('SELECT * FROM users')\r\nprint(result)\r\n\r\n# Update data\r\ndb.update_data('UPDATE users SET email = \"john.doe.updated@example.com\" WHERE id = 1')\r\n\r\n# Delete data\r\ndb.delete_data('DELETE FROM users WHERE id = 2')\r\n\r\n# Get affected rows count\r\naffected_rows = db.get_affected_rows()\r\nprint(f\"Affected rows: {affected_rows}\")\r\n\r\n# Get table columns\r\ncolumns = db.get_table_columns()\r\nprint(f\"Table columns: {columns}\")\r\n\r\n# Get table rows count\r\nrows_count = db.get_table_rows_count()\r\nprint(f\"Table rows count: {rows_count}\")\r\n\r\n# Close the database connection\r\ndb.close()\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A lightweight SQLite database utility module",
    "version": "1.0.0",
    "project_urls": null,
    "split_keywords": [
        "sqlite",
        "sql",
        "database",
        "utility"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8e030bce5ab943f6e5db7c38a1b4c1689a7cf63b21afece8ca09a0f43693a0b8",
                "md5": "1637a7c1fa9daf5e7d58adb7e12219a0",
                "sha256": "a0bf8fe481d34ec4971cbe58ebae7eed08b36e381906bb9735ea551b9aa721c6"
            },
            "downloads": -1,
            "filename": "DBbeginners-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1637a7c1fa9daf5e7d58adb7e12219a0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 2695,
            "upload_time": "2024-10-05T14:14:28",
            "upload_time_iso_8601": "2024-10-05T14:14:28.031513Z",
            "url": "https://files.pythonhosted.org/packages/8e/03/0bce5ab943f6e5db7c38a1b4c1689a7cf63b21afece8ca09a0f43693a0b8/DBbeginners-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e5173904f151a286699c04a2cdeb8fa937391854a4b147d28b40a7258a9a7192",
                "md5": "79b5003d991dfa3f6108f63b00ec93aa",
                "sha256": "37aef5863959cb949933755b0ced35b78af70a0af05ff0fd6962d83f3de52809"
            },
            "downloads": -1,
            "filename": "dbbeginners-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "79b5003d991dfa3f6108f63b00ec93aa",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 2879,
            "upload_time": "2024-10-05T14:14:29",
            "upload_time_iso_8601": "2024-10-05T14:14:29.818533Z",
            "url": "https://files.pythonhosted.org/packages/e5/17/3904f151a286699c04a2cdeb8fa937391854a4b147d28b40a7258a9a7192/dbbeginners-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-05 14:14:29",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "dbbeginners"
}
        
Elapsed time: 0.70341s