devdb-sql 1.0.4__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.
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: devdb-sql
|
|
3
|
+
Version: 1.0.4
|
|
4
|
+
Summary: Lightweight SQLite SDK with a MongoDB-like developer experience
|
|
5
|
+
Author: Mahadev
|
|
6
|
+
License: MIT
|
|
7
|
+
Requires-Python: >=3.9
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Dynamic: license-file
|
|
11
|
+
|
|
12
|
+
# Dev SQL — Python
|
|
13
|
+
|
|
14
|
+
Python port of the Dev SQL JavaScript SDK.
|
|
15
|
+
|
|
16
|
+
It provides a MongoDB-like API while using SQLite internally. Application code does not need to write SQL.
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install devdb-dql
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
from devdb import DB
|
|
28
|
+
|
|
29
|
+
db = DB("./data/file.db")
|
|
30
|
+
|
|
31
|
+
User = db.create("users", {
|
|
32
|
+
"id": {
|
|
33
|
+
"type": "integer",
|
|
34
|
+
"primary": True,
|
|
35
|
+
"autoIncrement": True
|
|
36
|
+
},
|
|
37
|
+
"name": {
|
|
38
|
+
"type": "string",
|
|
39
|
+
"required": True
|
|
40
|
+
},
|
|
41
|
+
"email": {
|
|
42
|
+
"type": "string",
|
|
43
|
+
"unique": True
|
|
44
|
+
},
|
|
45
|
+
"age": {
|
|
46
|
+
"type": "integer",
|
|
47
|
+
"default": 18
|
|
48
|
+
},
|
|
49
|
+
"active": {
|
|
50
|
+
"type": "boolean"
|
|
51
|
+
},
|
|
52
|
+
"metadata": {
|
|
53
|
+
"type": "json"
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
user = User.insert({
|
|
58
|
+
"name": "Mahadev",
|
|
59
|
+
"email": "mahadev@gmail.com",
|
|
60
|
+
"age": 20,
|
|
61
|
+
"active": True,
|
|
62
|
+
"metadata": {"role": "student"}
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
print(user)
|
|
66
|
+
|
|
67
|
+
print(User.find())
|
|
68
|
+
print(User.find({"age": {"$gte": 18}}))
|
|
69
|
+
print(User.find_by_id(user["id"]))
|
|
70
|
+
|
|
71
|
+
User.update_by_id(user["id"], {"age": 21})
|
|
72
|
+
User.delete_by_id(user["id"])
|
|
73
|
+
|
|
74
|
+
print(db.tables())
|
|
75
|
+
|
|
76
|
+
db.close()
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Supported types
|
|
80
|
+
|
|
81
|
+
- `string` -> SQLite `TEXT`
|
|
82
|
+
- `integer` -> SQLite `INTEGER`
|
|
83
|
+
- `number` -> SQLite `REAL`
|
|
84
|
+
- `boolean` -> SQLite `INTEGER`
|
|
85
|
+
- `date` -> SQLite `TEXT`
|
|
86
|
+
- `json` -> SQLite `TEXT`
|
|
87
|
+
|
|
88
|
+
## Query operators
|
|
89
|
+
|
|
90
|
+
- `$eq`
|
|
91
|
+
- `$ne`
|
|
92
|
+
- `$gt`
|
|
93
|
+
- `$gte`
|
|
94
|
+
- `$lt`
|
|
95
|
+
- `$lte`
|
|
96
|
+
- `$in`
|
|
97
|
+
|
|
98
|
+
Example:
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
User.find({
|
|
102
|
+
"age": {"$gt": 18},
|
|
103
|
+
"name": "Mahadev"
|
|
104
|
+
})
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Query options
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
User.find(
|
|
111
|
+
{"age": {"$gte": 18}},
|
|
112
|
+
{
|
|
113
|
+
"orderBy": "age",
|
|
114
|
+
"order": "desc",
|
|
115
|
+
"limit": 10,
|
|
116
|
+
"offset": 0
|
|
117
|
+
}
|
|
118
|
+
)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Methods
|
|
122
|
+
|
|
123
|
+
### DB
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
DB(path)
|
|
127
|
+
db.create(name, schema)
|
|
128
|
+
db.tables()
|
|
129
|
+
db.show_tables()
|
|
130
|
+
db.drop(name)
|
|
131
|
+
db.close()
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Table
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
table.insert(data)
|
|
138
|
+
table.find()
|
|
139
|
+
table.find(query)
|
|
140
|
+
table.find(query, options)
|
|
141
|
+
table.find_by_id(id)
|
|
142
|
+
table.find_all()
|
|
143
|
+
table.update_by_id(id, data)
|
|
144
|
+
table.delete_by_id(id)
|
|
145
|
+
table.drop()
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
JavaScript-style aliases are also available:
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
table.findById()
|
|
152
|
+
table.findAll()
|
|
153
|
+
table.updateById()
|
|
154
|
+
table.deleteById()
|
|
155
|
+
```
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
devdb_sql-1.0.4.dist-info/licenses/LICENSE,sha256=5dz_6Da27IpY5JJBm1UOZfuMvcMIUDl55drLM6x-o7c,3
|
|
2
|
+
devdb_sql-1.0.4.dist-info/METADATA,sha256=6QoTG5vHGA9zV1E2gmqmTTuXiPjKOckRtNujgy2zTrI,2515
|
|
3
|
+
devdb_sql-1.0.4.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
4
|
+
devdb_sql-1.0.4.dist-info/top_level.txt,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
5
|
+
devdb_sql-1.0.4.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|