Skip to main content

sqlhere is made with an intention to help you create and use sql data locally. For Data Science Uses.

Project description

Certainly! Below is an updated README.md file with more examples for SQL queries:

SQLHere | A library to help Data Handling, Locally

SQLHere is a Python library developed by Mayank Dwivedi, a Data Scientist. This library is designed to streamline data storage for data science tasks, providing a fast and efficient way to create a local database, load data using various formats, and perform essential database operations.


Key Features

Latest version: 0.2.0

  • Efficient Data Loading: SQLHere offers fast data loading times, making it a superior choice compared to traditional methods such as CSV, text, and simple variables like lists, tuples, sets, and dictionaries.

  • Versatile Data Formats: Users can load data into the local database using a variety of formats, including lists, dictionaries, sets, CSV files, and even from another database.

  • Database Operations: SQLHere supports essential database operations, including reading data from the database, deleting data, and creating a local database if it does not exist.


Installation

You can install SQLHere using pip:

pip install sqlhere

Overview


from sqlhere import DataAdderDB

# Example usage
obj = DataAdderDB(
    db_path='sample/extra/test.db',
    table_name='table',
)

Usage

To get started, import the DataAdderDB class from the sqlhere package and initialize it with the required parameters. Use the provided methods to perform various operations. Below are descriptions and example code for each function:To get started, import the DataAdderDB class from the sqlhere package and initialize it with the required parameters. Use the provided methods to perform various operations. Below are descriptions and example code for each function:

Class: DataAdderDB

Initialization

DataAdderDB(db_path, table_name)
  • db_path (str): Path to the SQLite database file.
  • table_name (str): Name of the table in the database.

Example:

from sqlhere import DataAdderDB

# Initialize DataAdderDB with the necessary parameters
obj = DataAdderDB(
    db_path='sample/extra/test.db',
    table_name='table',
)

Methods


query(q)

Executes the provided SQL query and returns the results.

query(q)

Example 1: Select (Retrieve) Data

select_query = "SELECT * FROM table;"
query_results = obj.query(select_query)
print(query_results)

Example 2: Insert Data

insert_query = "INSERT INTO table (column1, column2) VALUES ('value1', 'value2');"
obj.query(insert_query)

Example 3: Update Data

update_query = "UPDATE table SET column1 = 'new_value' WHERE condition;"
obj.query(update_query)

Example 4: Delete Data

delete_query = "DELETE FROM table WHERE condition;"
obj.query(delete_query)

Supported Raw File Types

  • JSON
  • CSV
  • TXT
  • List
  • Set
  • Dictionary
  • SQL

Example Usage

from sqlhere import DataAdderDB

# Initialize DataAdderDB with the necessary parameters
obj = DataAdderDB(
    db_path='sample/extra/test.db',
    table_name='table',
)

# Perform the data addition operation
obj.load_data({'item1', 'item2', 'item3'}, 'Example Data Source')

# Execute SQL queries
select_query = "SELECT * FROM table;"
query_results = obj.query(select_query)
print(query_results)

insert_query = "INSERT INTO table (column1, column2) VALUES ('value1', 'value2');"
obj.query(insert_query)

update_query = "UPDATE table SET column1 = 'new_value' WHERE condition;"
obj.query(update_query)

delete_query = "DELETE FROM table WHERE condition;"
obj.query(delete_query)

Certainly! Here's the updated README.md with only the new feature:

SQLHere | New Feature: Recycle Bin and Undo Delete

SQLHere now includes a Recycle Bin feature, allowing users to move deleted tables to a designated database before permanent deletion. The Undo Delete function has been introduced to restore tables from the Recycle Bin to their original databases.

Usage

delete_data_from_db(table_name)

Moves the specified table to the Recycle Bin and then deletes it from the database.

delete_data_from_db(table_name)

Example:

obj.delete_data_from_db('table')

undo_delete(table_name)

Restores the specified table from the Recycle Bin to the original database.

undo_delete(table_name)

Example:

obj.undo_delete('table')

The Recycle Bin database is named 'recycle_bin.db' and is created automatically if it doesn't exist. Each deleted table is stored in the Recycle Bin for potential restoration.

Disclaimer

If the provided db_path directory does not have the database, SQLHere will create the necessary directories and an empty SQLite database at the specified path. Beware of deleting any table, well even if you that I got your back, there is an undo_delete() function as well.

Connect with Mayank Dwivedi

LinkedIn: Mayank Dwivedi

Happy coding!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

sqlhere-0.1.4-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file sqlhere-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: sqlhere-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for sqlhere-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ccd16bb746ea1b7ebe6a508239b34d9c7c43aae26f7747ac41887edc74c42d20
MD5 c1a9275f0b95ccd698ab5b99c93c4e8b
BLAKE2b-256 8ff7745c6f9311aaa0a36839cca4616c99e4a5e55c007e46a374ccbc18227e0e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page