collections-cache 0.1.4__tar.gz → 0.1.5__tar.gz

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,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: collections-cache
3
- Version: 0.1.4
3
+ Version: 0.1.5
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
@@ -28,7 +28,8 @@ class Collection_Cache:
28
28
 
29
29
  def initialize_databases(self, db_path):
30
30
  conn = sqlite3.connect(db_path)
31
- conn.execute("PRAGMA journal_mode=WAL;")
31
+ self.configure_connection(conn)
32
+ #conn.execute("PRAGMA journal_mode=WAL;")
32
33
  conn.execute("""
33
34
  CREATE TABLE IF NOT EXISTS data(
34
35
  key TEXT,
@@ -48,8 +49,9 @@ class Collection_Cache:
48
49
 
49
50
  def get_all_keys(self, database):
50
51
  conn = sqlite3.connect(database)
52
+ self.configure_connection(conn)
51
53
  cursor = conn.cursor()
52
- cursor.execute("PRAGMA journal_mode=WAL;")
54
+ #cursor.execute("PRAGMA journal_mode=WAL;")
53
55
  cursor.execute("SELECT key FROM data;")
54
56
  result = cursor.fetchall()
55
57
  keys = [(line[0], database) for line in result]
@@ -62,8 +64,9 @@ class Collection_Cache:
62
64
  database_to_insert = choice(self.databases_list)
63
65
  #print(f"Inserting in {database_to_insert}")
64
66
  conn = sqlite3.connect(database_to_insert)
67
+ self.configure_connection(conn)
65
68
  cursor = conn.cursor()
66
- cursor.execute("PRAGMA journal_mode=WAL;")
69
+ #cursor.execute("PRAGMA journal_mode=WAL;")
67
70
  cursor.execute("INSERT INTO data(key, value) VALUES (?, ?);", (key, pickle.dumps(value)))
68
71
  conn.commit()
69
72
  conn.close()
@@ -73,8 +76,9 @@ class Collection_Cache:
73
76
  #print(f"Updating key '{key}' in {self.keys_databases[key]}...")
74
77
  database_to_update = self.keys_databases[key]
75
78
  conn = sqlite3.connect(database_to_update)
79
+ self.configure_connection(conn)
76
80
  cursor = conn.cursor()
77
- cursor.execute("PRAGMA journal_mode=WAL;")
81
+ #cursor.execute("PRAGMA journal_mode=WAL;")
78
82
  cursor.execute("UPDATE data SET value = ? WHERE key = ?;", (pickle.dumps(value), key))
79
83
  conn.commit()
80
84
  conn.close()
@@ -96,8 +100,9 @@ class Collection_Cache:
96
100
  #print(database_to_search)
97
101
 
98
102
  conn = sqlite3.connect(database_to_search)
103
+ self.configure_connection(conn)
99
104
  cursor = conn.cursor()
100
- cursor.execute("PRAGMA journal_mode=WAL;")
105
+ #cursor.execute("PRAGMA journal_mode=WAL;")
101
106
  cursor.execute("SELECT value FROM data WHERE key = ?", (key,))
102
107
  result = cursor.fetchall()
103
108
  conn.close()
@@ -113,8 +118,9 @@ class Collection_Cache:
113
118
  #print(database_to_search)
114
119
 
115
120
  conn = sqlite3.connect(database_to_delete)
121
+ self.configure_connection(conn)
116
122
  cursor = conn.cursor()
117
- cursor.execute("PRAGMA journal_mode=WAL;")
123
+ #cursor.execute("PRAGMA journal_mode=WAL;")
118
124
  cursor.execute("DELETE FROM data WHERE key = ?", (key,))
119
125
  conn.commit()
120
126
  conn.close()
@@ -125,3 +131,8 @@ class Collection_Cache:
125
131
 
126
132
  except Exception as error:
127
133
  return error
134
+
135
+ def configure_connection(self, conn):
136
+ conn.execute("PRAGMA journal_mode = WAL;")
137
+ conn.execute("PRAGMA synchronous = NORMAL;")
138
+ conn.execute("PRAGMA wal_autocheckpoint = 1000;")
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "collections-cache"
3
- version = "0.1.4"
3
+ version = "0.1.5"
4
4
  description = "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
  authors = ["Luiz-Trindade <luiz.gabriel.m.trindade@gmail.com>"]
6
6
  license = "MIT"