Skip to main content

Library to manage a sqlite database

Project description

python3-sqlite

This library provides an easy way to manage a sqlite database. To do this, use the sqlite3 library to connect to the database and the logging library to display information about errors and debugging.

Installation

Installation can be done through the pip3 command:

pip3 install procamora-sqlite3 --user

You can also update the library with:

python3 -m pip install --user --upgrade procamora-sqlite3

Basic Usage

To use this class the first thing to do is import the library:

from procamora_sqlite3.logger import get_logger, logging
from procamora_sqlite3.interface_sqlite import *

The interface_sqlite file when doing an import * we are importing three functions, these are:

__all__ = ['conection_sqlite', 'execute_script_sqlite', 'dump_database']

conection_sqlite

This function is responsible for carrying out the main SQL operations, such as: SELECT, INSERT, UPDATE or DELETE.

An example of some of these functions would be:

def select_all_hosts() -> List[Dict[Text, Any]]:
    query: Text = "SELECT * FROM Hosts"
    response_query: List[Dict[Text, Any]] = conection_sqlite(self.db, query, is_dict=True)
    return response_query

def update_host_offline(date: Text):
    query: Text = f"UPDATE Hosts SET active=0 WHERE date <> '{date}';"
    conection_sqlite(self.db, query)

execute_script_sqlite

This function allows you to run a script or dump that you receive in string format. With this function, databases could be created.

execute_script_sqlite(self.db, self.dump.read_text())

dump_database

This function allows you to perform a complete dump of the database.

response = dump_database(self.db)

Project details


Download files

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

Files for procamora-sqlite3, version 1.1
Filename, size File type Python version Upload date Hashes
Filename, size procamora-sqlite3-1.1.tar.gz (16.8 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page