collections-cache 0.1.4__py3-none-any.whl → 0.1.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,11 @@
1
1
  import sqlite3
2
- from multiprocessing import Pool
2
+ #from multiprocessing import Pool
3
3
  from os import cpu_count, path, makedirs, scandir
4
4
  from itertools import chain
5
5
  from random import choice
6
6
  #from threading import Thread as task
7
7
  import pickle
8
+ from concurrent.features import ProcessPoolExecutor as Pool
8
9
 
9
10
  class Collection_Cache:
10
11
  def __init__(self, collection_name):
@@ -28,7 +29,8 @@ class Collection_Cache:
28
29
 
29
30
  def initialize_databases(self, db_path):
30
31
  conn = sqlite3.connect(db_path)
31
- conn.execute("PRAGMA journal_mode=WAL;")
32
+ self.configure_connection(conn)
33
+ #conn.execute("PRAGMA journal_mode=WAL;")
32
34
  conn.execute("""
33
35
  CREATE TABLE IF NOT EXISTS data(
34
36
  key TEXT,
@@ -48,8 +50,9 @@ class Collection_Cache:
48
50
 
49
51
  def get_all_keys(self, database):
50
52
  conn = sqlite3.connect(database)
53
+ self.configure_connection(conn)
51
54
  cursor = conn.cursor()
52
- cursor.execute("PRAGMA journal_mode=WAL;")
55
+ #cursor.execute("PRAGMA journal_mode=WAL;")
53
56
  cursor.execute("SELECT key FROM data;")
54
57
  result = cursor.fetchall()
55
58
  keys = [(line[0], database) for line in result]
@@ -62,8 +65,9 @@ class Collection_Cache:
62
65
  database_to_insert = choice(self.databases_list)
63
66
  #print(f"Inserting in {database_to_insert}")
64
67
  conn = sqlite3.connect(database_to_insert)
68
+ self.configure_connection(conn)
65
69
  cursor = conn.cursor()
66
- cursor.execute("PRAGMA journal_mode=WAL;")
70
+ #cursor.execute("PRAGMA journal_mode=WAL;")
67
71
  cursor.execute("INSERT INTO data(key, value) VALUES (?, ?);", (key, pickle.dumps(value)))
68
72
  conn.commit()
69
73
  conn.close()
@@ -73,8 +77,9 @@ class Collection_Cache:
73
77
  #print(f"Updating key '{key}' in {self.keys_databases[key]}...")
74
78
  database_to_update = self.keys_databases[key]
75
79
  conn = sqlite3.connect(database_to_update)
80
+ self.configure_connection(conn)
76
81
  cursor = conn.cursor()
77
- cursor.execute("PRAGMA journal_mode=WAL;")
82
+ #cursor.execute("PRAGMA journal_mode=WAL;")
78
83
  cursor.execute("UPDATE data SET value = ? WHERE key = ?;", (pickle.dumps(value), key))
79
84
  conn.commit()
80
85
  conn.close()
@@ -96,8 +101,9 @@ class Collection_Cache:
96
101
  #print(database_to_search)
97
102
 
98
103
  conn = sqlite3.connect(database_to_search)
104
+ self.configure_connection(conn)
99
105
  cursor = conn.cursor()
100
- cursor.execute("PRAGMA journal_mode=WAL;")
106
+ #cursor.execute("PRAGMA journal_mode=WAL;")
101
107
  cursor.execute("SELECT value FROM data WHERE key = ?", (key,))
102
108
  result = cursor.fetchall()
103
109
  conn.close()
@@ -113,8 +119,9 @@ class Collection_Cache:
113
119
  #print(database_to_search)
114
120
 
115
121
  conn = sqlite3.connect(database_to_delete)
122
+ self.configure_connection(conn)
116
123
  cursor = conn.cursor()
117
- cursor.execute("PRAGMA journal_mode=WAL;")
124
+ #cursor.execute("PRAGMA journal_mode=WAL;")
118
125
  cursor.execute("DELETE FROM data WHERE key = ?", (key,))
119
126
  conn.commit()
120
127
  conn.close()
@@ -125,3 +132,8 @@ class Collection_Cache:
125
132
 
126
133
  except Exception as error:
127
134
  return error
135
+
136
+ def configure_connection(self, conn):
137
+ conn.execute("PRAGMA journal_mode = WAL;")
138
+ conn.execute("PRAGMA synchronous = NORMAL;")
139
+ conn.execute("PRAGMA wal_autocheckpoint = 1000;")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: collections-cache
3
- Version: 0.1.4
3
+ Version: 0.1.6
4
4
  Summary: Collection Cache is a Python package for managing data collections across multiple SQLite databases. It allows efficient storage, retrieval, and updating of key-value pairs, supporting various data types serialized with pickle. The package uses parallel processing for fast access and manipulation of large collections.
5
5
  License: MIT
6
6
  Author: Luiz-Trindade
@@ -0,0 +1,6 @@
1
+ collections_cache/__init__.py,sha256=uUp8lhp-HnZRumnU_8MT6qVq95t0pOzn7oLW7ARbnvc,48
2
+ collections_cache/collections_cache.py,sha256=VMLBJpmYeLZOGaamgPjpfe4yMd76_nyu8CiLxcfxy9U,5349
3
+ collections_cache-0.1.6.dist-info/LICENSE,sha256=RAIL-FmXSiNRgyiVlfhm2SvVI4XDVsN0jDt9207SJ8o,1168
4
+ collections_cache-0.1.6.dist-info/METADATA,sha256=BtaiOJVjY5mUOfuLO18WGRgXjEW-B6AoQrNYpUc8NZc,3199
5
+ collections_cache-0.1.6.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
6
+ collections_cache-0.1.6.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- collections_cache/__init__.py,sha256=uUp8lhp-HnZRumnU_8MT6qVq95t0pOzn7oLW7ARbnvc,48
2
- collections_cache/collections_cache.py,sha256=8ZB0y8eJS1SFx8GEv-DQLlCyeqSL9VrNjRJz94gW_PE,4821
3
- collections_cache-0.1.4.dist-info/LICENSE,sha256=RAIL-FmXSiNRgyiVlfhm2SvVI4XDVsN0jDt9207SJ8o,1168
4
- collections_cache-0.1.4.dist-info/METADATA,sha256=uBO0-VHiAmD9shxP_9e4y6TI5Wi3gbvB6dGkodrtH_8,3199
5
- collections_cache-0.1.4.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
6
- collections_cache-0.1.4.dist-info/RECORD,,