Skip to main content

package for creating simple text based db

Project description

TextDb - RASSD(Read, Add, Save, Search, Delete)

License: MIT Build codecov

This package allows you to create simple text storage by using python.

  • Main functionality is Read, Add, Save, Search, Delete,
  • TextDb can not update existing data !!!⚠️ONLY ADD OR DELETE⚠️!!!. Of course if you would like to update you can use a combination of Add and Delete. TextDb has built-in functionality for this but it does not come out of the package.
  • TextDb was created with the idea of storing large data which is not supposed to be updated.
  • TextDb can be corrupted if a user tries to update change data directly in a text file and makes a mistake during the process.(!!!⚠️Do not try to update large files directly⚠️!!!)

Installation

pip install TextDB-lunfman

API REF

  • Notes if a db file does not exist it will be created automatically.
  • To initialized database just provide a path to the file
from text_db import TextDb
db = TextDb(path)

API methods

db.get_data() - method return a full hash_table of the db class

db.add(row) - method for adding new entries to db

  • takes dictionary as an argument with key and value
  • key will be used as label in formatted data when save db

db.save() - method which saves data to the file.

db.delete_by_index(index) - method for deleting entries from db by using index

db.sort_by(category, is_float_base = False, is_reverse = True)

  • method which sorts db data by using category name as a flag/indicator
  • by default sorted higher first lower last
  • if category do not present in some objects they will be passed
  • return sorted hash-table with required category
  • by default is_float_base = False it means it is sorting content as a string it can be used with pairs of numbers which can be converted from string to the float NB!! if number has ',' inside is_float_base will through an error cause it can not convert to the number. Good - '131.2312' Bad - '12312,122'
  • is_reverse by default is true. if change to false it will sort in opposite way.

db.find_by_index(index) - method allows finding object/row from db by its index

  • return full object/row

db.find_objects(category_name) - method which returns a hash with indexes and categories values

db.get_position(pattern) - method which uses pattern to find first match in db

  • return first found match object index, if not found return 0

db.get_obj_by_pattern(pattern) - method return first object with found pattern as an object {}

db.get_all_cat_values(category) - method return all values of the match category as a list

db.find_objs_where_value_match(category, value) - method which returns a list with objects which matches with required value in category

db.find_all_objs_by_pattern(pattern) - method which returns all rows witch match with pattern. if not found return {}

db.check_if_exists(pattern) - method return boolean True if pattern present otherwise False

db.filter_all_queries(patterns_arr - method return a hash with all results of passed queries -patterns_arr - an array with valid queries

db.get_filtered_object() - this method return TextDb object where data equals to the latest results of filter_all_queries(patterns_arr) method Why does this method exist? After a while I found out that I want to sort the filtered data but to achieve this goal I had to write the same code again somewhere else. Of course, it was a bad solution. So I came up with the idea of this method. This allows me to use all methods from this class if needed.

db.filter_by_almost_equal(category_name, arr_of_values) - this method returns a hash where category values almost equal to the arr_of_values. Nb! use this method if the category has comma separated values. '1,2' or 's,x,m' Basically it checks if values of one array present in the second arr if so add to filtered_object.

Project details


Download files

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

Source Distribution

TextDB-lunfman-0.0.7.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

TextDB_lunfman-0.0.7-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file TextDB-lunfman-0.0.7.tar.gz.

File metadata

  • Download URL: TextDB-lunfman-0.0.7.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for TextDB-lunfman-0.0.7.tar.gz
Algorithm Hash digest
SHA256 b6413e2f263fc9baf403994ee48651249d4e3d3fa9bc5503bcd33865667182e0
MD5 0c554e934645bafcfbcb963c243d767f
BLAKE2b-256 09cdde241ee6fdbb9e8e7bc3415ed8b6ee07ef953bb36c77de270be211aa32f0

See more details on using hashes here.

File details

Details for the file TextDB_lunfman-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: TextDB_lunfman-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for TextDB_lunfman-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 b657e035f13c976cdad7966fb3a5011569cf3cd81c8ce32802afd81eac37adb1
MD5 4608976cebc63706300d3c5b229298c9
BLAKE2b-256 a8360fac62609756252673bb4effcdaf15acd3d64f18832d44809d8c91934c96

See more details on using hashes here.

Supported by

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