devdb-sql 1.0.9__py3-none-any.whl → 1.0.11__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.
devdb_sql/db.py CHANGED
@@ -1,5 +1,4 @@
1
1
  import sqlite3
2
- import threading
3
2
  from pathlib import Path
4
3
 
5
4
  from .schema import compile_schema
@@ -14,27 +13,11 @@ class DB:
14
13
  self.path = path
15
14
 
16
15
  parent = Path(path).parent
17
-
18
16
  if str(parent) not in ("", "."):
19
- parent.mkdir(
20
- parents=True,
21
- exist_ok=True,
22
- )
23
-
24
- # SQLite connection can now be accessed
25
- # from different threads.
26
- self.sqlite = sqlite3.connect(
27
- path,
28
- check_same_thread=False,
29
- timeout=30,
30
- )
17
+ parent.mkdir(parents=True, exist_ok=True)
31
18
 
19
+ self.sqlite = sqlite3.connect(path)
32
20
  self.sqlite.row_factory = sqlite3.Row
33
-
34
- # RLock is important because methods like insert()
35
- # acquire the lock and then call find_by_id().
36
- self.lock = threading.RLock()
37
-
38
21
  self._tables = {}
39
22
 
40
23
  def create(self, name, schema):
@@ -42,63 +25,37 @@ class DB:
42
25
  raise ValueError("Table name is required")
43
26
 
44
27
  if not isinstance(schema, dict):
45
- raise ValueError(
46
- f'Schema is required for table "{name}"'
47
- )
48
-
49
- with self.lock:
50
- if name in self._tables:
51
- raise ValueError(
52
- f'Table "{name}" is already registered'
53
- )
54
-
55
- sql = compile_schema(name, schema)
28
+ raise ValueError(f'Schema is required for table "{name}"')
56
29
 
57
- self.sqlite.executescript(sql)
58
- self.sqlite.commit()
30
+ if name in self._tables:
31
+ raise ValueError(f'Table "{name}" is already registered')
59
32
 
60
- table = Table(
61
- self,
62
- name,
63
- schema,
64
- )
33
+ sql = compile_schema(name, schema)
34
+ self.sqlite.executescript(sql)
35
+ self.sqlite.commit()
65
36
 
66
- self._tables[name] = table
67
-
68
- return table
37
+ table = Table(self, name, schema)
38
+ self._tables[name] = table
39
+ return table
69
40
 
70
41
  def drop(self, name):
71
- with self.lock:
72
- self.sqlite.execute(
73
- f"DROP TABLE IF EXISTS {name}"
74
- )
75
-
76
- self.sqlite.commit()
77
-
78
- self._tables.pop(name, None)
79
-
80
- return True
42
+ self.sqlite.execute(f"DROP TABLE IF EXISTS {name}")
43
+ self.sqlite.commit()
44
+ self._tables.pop(name, None)
45
+ return True
81
46
 
82
47
  def tables(self):
83
- with self.lock:
84
- rows = self.sqlite.execute(
85
- """
86
- SELECT name
87
- FROM sqlite_master
88
- WHERE type = 'table'
89
- AND name NOT LIKE 'sqlite_%'
90
- ORDER BY name
91
- """
92
- ).fetchall()
93
-
94
- return [
95
- row["name"]
96
- for row in rows
97
- ]
48
+ rows = self.sqlite.execute("""
49
+ SELECT name
50
+ FROM sqlite_master
51
+ WHERE type = 'table'
52
+ AND name NOT LIKE 'sqlite_%'
53
+ ORDER BY name
54
+ """).fetchall()
55
+ return [row["name"] for row in rows]
98
56
 
99
57
  def show_tables(self):
100
58
  return self.tables()
101
59
 
102
60
  def close(self):
103
- with self.lock:
104
- self.sqlite.close()
61
+ self.sqlite.close()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: devdb-sql
3
- Version: 1.0.9
3
+ Version: 1.0.11
4
4
  Summary: Lightweight SQLite SDK with a MongoDB-like developer experience
5
5
  Author: Mahadev
6
6
  License: MIT
@@ -0,0 +1,9 @@
1
+ devdb_sql/__init__.py,sha256=urwb10Wi5ANRZgrNLod1P_6EOZ-xzlxf3JFN82As-ZI,93
2
+ devdb_sql/db.py,sha256=UreboRsTMiuG6dUFaFCv1pkBXGbVK9na1ur4g7sU6Y8,1605
3
+ devdb_sql/schema.py,sha256=UNTO_Cj5be8G3fkc4fTW7BZ-2SUdTJJ7ifxTUhIox8M,2528
4
+ devdb_sql/table.py,sha256=z5VvcdywKYIjXrUE4GME7V_-FzlZCoDgRKoLdHKAJzI,9641
5
+ devdb_sql-1.0.11.dist-info/licenses/LICENSE,sha256=5dz_6Da27IpY5JJBm1UOZfuMvcMIUDl55drLM6x-o7c,3
6
+ devdb_sql-1.0.11.dist-info/METADATA,sha256=xC3zj2SssHrrXsk79cx3CECPR-m3-PAbHxZqxkE5Fn8,2516
7
+ devdb_sql-1.0.11.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
8
+ devdb_sql-1.0.11.dist-info/top_level.txt,sha256=vXU4aBnHEniSprgTNOkiou3d99EgBlZY1lfSfparXkw,10
9
+ devdb_sql-1.0.11.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- devdb_sql/__init__.py,sha256=urwb10Wi5ANRZgrNLod1P_6EOZ-xzlxf3JFN82As-ZI,93
2
- devdb_sql/db.py,sha256=iv0uTK5RblG0wslpnOZEH1p5ddo1pbjlpZ83_x2Dj2M,2418
3
- devdb_sql/schema.py,sha256=UNTO_Cj5be8G3fkc4fTW7BZ-2SUdTJJ7ifxTUhIox8M,2528
4
- devdb_sql/table.py,sha256=z5VvcdywKYIjXrUE4GME7V_-FzlZCoDgRKoLdHKAJzI,9641
5
- devdb_sql-1.0.9.dist-info/licenses/LICENSE,sha256=5dz_6Da27IpY5JJBm1UOZfuMvcMIUDl55drLM6x-o7c,3
6
- devdb_sql-1.0.9.dist-info/METADATA,sha256=AF1nrn8gPqFx0wuLIjzaqRDlBVZESAnCYkOIHKT9fl4,2515
7
- devdb_sql-1.0.9.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
8
- devdb_sql-1.0.9.dist-info/top_level.txt,sha256=vXU4aBnHEniSprgTNOkiou3d99EgBlZY1lfSfparXkw,10
9
- devdb_sql-1.0.9.dist-info/RECORD,,