orm-database 0.3.17__py3-none-any.whl → 0.3.26__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.
- orm_database/orm_database.py +36 -5
- orm_database/orm_query.py +53 -1
- {orm_database-0.3.17.dist-info → orm_database-0.3.26.dist-info}/METADATA +95 -2
- orm_database-0.3.26.dist-info/RECORD +8 -0
- {orm_database-0.3.17.dist-info → orm_database-0.3.26.dist-info}/WHEEL +1 -1
- orm_database-0.3.17.dist-info/RECORD +0 -8
- {orm_database-0.3.17.dist-info → orm_database-0.3.26.dist-info/licenses}/LICENSE +0 -0
- {orm_database-0.3.17.dist-info → orm_database-0.3.26.dist-info}/top_level.txt +0 -0
orm_database/orm_database.py
CHANGED
@@ -58,11 +58,9 @@ class MariaDB:
|
|
58
58
|
query = query_select(table=table,filed=filed,all=all)
|
59
59
|
cur.execute(query)
|
60
60
|
result = cur.fetchall()
|
61
|
-
print(result)
|
62
61
|
data = {}
|
63
62
|
data_row = []
|
64
63
|
for a in result:
|
65
|
-
print(a)
|
66
64
|
conter = 0
|
67
65
|
for b in a:
|
68
66
|
data[filed[conter]] = b
|
@@ -119,6 +117,16 @@ class PostgreSQL:
|
|
119
117
|
query = query_insert_values(table=table,value=value)
|
120
118
|
await self.db.execute(query)
|
121
119
|
|
120
|
+
|
121
|
+
async def insert_values_truple(self, table: str, key:dict,value:list):
|
122
|
+
query = query_insert_values_truple(table=table,key=key)
|
123
|
+
await self.db.executemany(query,value)
|
124
|
+
|
125
|
+
async def copy_records_to_table(self, table: str, value:list):
|
126
|
+
await self.db.copy_records_to_table(table,records=value)
|
127
|
+
|
128
|
+
|
129
|
+
|
122
130
|
async def select_all(self, table: str, filed: list, all: bool = False):
|
123
131
|
if all == True:
|
124
132
|
query = "SELECT * FROM " + table
|
@@ -129,7 +137,6 @@ class PostgreSQL:
|
|
129
137
|
query = query[:-1]
|
130
138
|
query = query + " FROM " + table
|
131
139
|
|
132
|
-
print(query)
|
133
140
|
stmt = await self.db.prepare(query)
|
134
141
|
# for a in stmt:
|
135
142
|
result = list(await stmt.fetch())
|
@@ -141,7 +148,6 @@ class PostgreSQL:
|
|
141
148
|
data[filed[conter]] = b
|
142
149
|
conter += 1
|
143
150
|
data_row.append(dict(data))
|
144
|
-
print(data_row)
|
145
151
|
return data_row
|
146
152
|
|
147
153
|
|
@@ -158,6 +164,32 @@ class PostgreSQL:
|
|
158
164
|
return None
|
159
165
|
|
160
166
|
|
167
|
+
async def delete_one(self,table:str,filed:dict):
|
168
|
+
query = query_delete_one(table=table,filed=filed)
|
169
|
+
try:
|
170
|
+
await self.db.execute(query)
|
171
|
+
return True
|
172
|
+
except:
|
173
|
+
return False
|
174
|
+
|
175
|
+
|
176
|
+
async def update_one(self,table:str,find:dict,value:dict):
|
177
|
+
query = query_update_one(table=table,find=find,value=value)
|
178
|
+
try:
|
179
|
+
await self.db.execute(query)
|
180
|
+
return True
|
181
|
+
except:
|
182
|
+
return False
|
183
|
+
|
184
|
+
|
185
|
+
async def find_list(self,table:str,find:dict):
|
186
|
+
query = query_find_list(table=table,find=find)
|
187
|
+
data = await self.db.fetch(query)
|
188
|
+
result = []
|
189
|
+
for a in data:
|
190
|
+
result.append(dict(a))
|
191
|
+
return result
|
192
|
+
|
161
193
|
class Mongodb:
|
162
194
|
def __init__(self, url, name):
|
163
195
|
self.url = url
|
@@ -231,4 +263,3 @@ class Mongodb:
|
|
231
263
|
async def delete_one(self, find: dict, collection: str):
|
232
264
|
coll = self.database[collection]
|
233
265
|
result = coll.delete_one(find)
|
234
|
-
print(result)
|
orm_database/orm_query.py
CHANGED
@@ -24,7 +24,7 @@ def query_baseModel_create_table(table,class_BaseModel):
|
|
24
24
|
except:
|
25
25
|
match data["type"]:
|
26
26
|
case "string":
|
27
|
-
type = f"varchar({data[
|
27
|
+
type = f"varchar({data['varchar']})"
|
28
28
|
case "number":
|
29
29
|
type = "float"
|
30
30
|
case "integer":
|
@@ -80,6 +80,26 @@ def query_insert_values(table:str,value:dict):
|
|
80
80
|
return query
|
81
81
|
|
82
82
|
|
83
|
+
|
84
|
+
def query_insert_values_truple(table:str,key:dict):
|
85
|
+
query = f"INSERT INTO {table} ( "
|
86
|
+
filed_key = list(key.keys())
|
87
|
+
for a in filed_key:
|
88
|
+
query = query + " " + a + " " + ","
|
89
|
+
query = query[:-1]
|
90
|
+
query = query + ")"
|
91
|
+
query = query + " VALUES ("
|
92
|
+
|
93
|
+
filed_value = list(key.values())
|
94
|
+
namber = 1
|
95
|
+
for a in filed_value:
|
96
|
+
|
97
|
+
query = query + " " + "$" + str(namber) + " " + ","
|
98
|
+
namber = namber + 1
|
99
|
+
query = query[:-1]
|
100
|
+
query = query + ")"
|
101
|
+
return query
|
102
|
+
|
83
103
|
# print output SELECT * FROM tes
|
84
104
|
# print output SELECT user_rt FROM tes
|
85
105
|
def query_select(table:str,filed:list,all:bool=False):
|
@@ -102,4 +122,36 @@ def select_columns(table:str,filed:dict):
|
|
102
122
|
query = query + table + " WHERE "
|
103
123
|
fileds = list(filed.keys())
|
104
124
|
query = query + fileds[0]+"="+"%s"
|
125
|
+
return query
|
126
|
+
|
127
|
+
|
128
|
+
# DELETE FROM pending_order WHERE users='s1';
|
129
|
+
def query_delete_one(table:str,filed:dict):
|
130
|
+
query = f"DELETE FROM {table} WHERE"
|
131
|
+
key = filed.keys()
|
132
|
+
key = list(key)
|
133
|
+
key = key[0]
|
134
|
+
query = query + " " + str(key) + "="+ str(filed[key])
|
135
|
+
return query
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
def query_update_one(table:str,find:dict,value:dict):
|
140
|
+
query = f"UPDATE {table} SET"
|
141
|
+
key = find.keys()
|
142
|
+
key = list(key)
|
143
|
+
key = key[0]
|
144
|
+
key_v = value.keys()
|
145
|
+
key_v = list(key_v)
|
146
|
+
key_v = key_v[0]
|
147
|
+
query = query+ " " + str(key_v)+ "='" + str(value[key_v]) + "' " +"WHERE" + " " + str(key) + "="+ str(find[key])
|
148
|
+
return query
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
def query_find_list(table:str,find:dict):
|
153
|
+
query = f"SELECT * FROM {table} WHERE"
|
154
|
+
key = list(find.keys())
|
155
|
+
key = key[0]
|
156
|
+
query = f"{query} {key}='{find[key]}'"
|
105
157
|
return query
|
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.4
|
2
2
|
Name: orm_database
|
3
|
-
Version: 0.3.
|
3
|
+
Version: 0.3.26
|
4
4
|
Summary: This module is written to launch your programs with any database you want in the shortest time
|
5
5
|
Home-page: https://github.com/sisrsis/orm-database
|
6
6
|
Author: SISRSIS
|
@@ -17,6 +17,7 @@ Dynamic: description
|
|
17
17
|
Dynamic: description-content-type
|
18
18
|
Dynamic: home-page
|
19
19
|
Dynamic: license
|
20
|
+
Dynamic: license-file
|
20
21
|
Dynamic: requires-dist
|
21
22
|
Dynamic: summary
|
22
23
|
|
@@ -73,6 +74,7 @@ async def main():
|
|
73
74
|
asyncio.run(main())
|
74
75
|
|
75
76
|
```
|
77
|
+
**Tip: When using MariaDB, you must specify a varchar value, otherwise you will get an error.**
|
76
78
|
|
77
79
|
## create table mariadb
|
78
80
|
|
@@ -252,4 +254,95 @@ output
|
|
252
254
|
```
|
253
255
|
|
254
256
|
|
257
|
+
## edit delete postgres
|
258
|
+
```python
|
259
|
+
from orm_database import PostgreSQL
|
260
|
+
import asyncio
|
261
|
+
|
262
|
+
|
263
|
+
postgres = PostgreSQL(host="127.0.0.1",user="postgres",database="wallet",password="123412341234")
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
async def main():
|
270
|
+
|
271
|
+
await postgres.start()
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
await postgres.delete_one("pending_order",{"id":1})
|
276
|
+
|
277
|
+
await postgres.update_one("pending_order1",{"id":1},{"users":"sis"})
|
278
|
+
|
279
|
+
```
|
280
|
+
|
281
|
+
## find list
|
282
|
+
|
283
|
+
```python
|
284
|
+
data = await postgres.find_list("test",{'username':'s1'})
|
285
|
+
```
|
286
|
+
### output
|
287
|
+
```json
|
288
|
+
[
|
289
|
+
{'id': 13, 'username': 's1', 'market': 'BTC', 'price':97596.33},
|
290
|
+
{'id': 14, 'username': 's1', 'market': 'BTC', 'price':97596.33}
|
291
|
+
]
|
292
|
+
|
293
|
+
```
|
294
|
+
|
295
|
+
## insert value list truple
|
296
|
+
|
297
|
+
|
298
|
+
```python
|
299
|
+
from orm_database import PostgreSQL
|
300
|
+
import asyncio
|
301
|
+
from pydantic import BaseModel , Field
|
302
|
+
|
303
|
+
|
304
|
+
db = PostgreSQL(host="127.0.0.1",database="test",password="12341234",user="postgres")
|
305
|
+
|
306
|
+
class users(BaseModel):
|
307
|
+
user_rt : str = Field(varchar=20)
|
308
|
+
password_rt : str = Field(varchar=20)
|
309
|
+
email_rt : str = Field(varchar=20)
|
310
|
+
|
311
|
+
|
312
|
+
async def main():
|
313
|
+
data = [("test1","12342","test4@mail.com"),("test2","12342","test2@mail.com"),("test3","12343","test3@mail.com")]
|
314
|
+
key = {"user_rt":"","password_rt":"","email_rt":""}
|
315
|
+
await db.start()
|
316
|
+
await db.teble_create_BaseModel("tes",users)
|
317
|
+
await db.insert_values_truple("tes",key=key,value=data)
|
318
|
+
|
319
|
+
|
320
|
+
asyncio.run(main())
|
321
|
+
```
|
322
|
+
|
323
|
+
|
324
|
+
## copy records to table
|
325
|
+
```python
|
326
|
+
from orm_database import PostgreSQL
|
327
|
+
import asyncio
|
328
|
+
from pydantic import BaseModel , Field
|
329
|
+
|
330
|
+
|
331
|
+
db = PostgreSQL(host="127.0.0.1",database="test",password="12341234",user="postgres")
|
332
|
+
|
333
|
+
class users(BaseModel):
|
334
|
+
user_rt : str = Field(varchar=20)
|
335
|
+
password_rt : str = Field(varchar=20)
|
336
|
+
email_rt : str = Field(varchar=20)
|
255
337
|
|
338
|
+
|
339
|
+
async def main():
|
340
|
+
data = [("test1","12342","test4@mail.com"),("test2","12342","test2@mail.com"),("test3","12343","test3@mail.com")]
|
341
|
+
key = {"user_rt":"","password_rt":"","email_rt":""}
|
342
|
+
await db.start()
|
343
|
+
await db.teble_create_BaseModel("tes",users)
|
344
|
+
await db.copy_records_to_table(table="tes",value=data)
|
345
|
+
|
346
|
+
|
347
|
+
asyncio.run(main())
|
348
|
+
```
|
@@ -0,0 +1,8 @@
|
|
1
|
+
orm_database/__init__.py,sha256=q0A0dUBMacf_yaU5m4VWCDlP__pVAz3I1Bhn1RPkv9I,140
|
2
|
+
orm_database/orm_database.py,sha256=Ez1JjvMD13ZIvenxgk1DRKmFaTgj1VuIbXaLWGlTgPU,8260
|
3
|
+
orm_database/orm_query.py,sha256=tT8SY-dJPb_W33W-ofLFPr5HEnJY6pHWYGdjmvftFfY,4420
|
4
|
+
orm_database-0.3.26.dist-info/licenses/LICENSE,sha256=v33KAoqx5qhyUNlHOjYmBBKDtd9ymzWB7sR4cova190,1064
|
5
|
+
orm_database-0.3.26.dist-info/METADATA,sha256=28u0XTvPIhmK6zSqG8mjHaySR2tv4sQTsHjM4WqnMS0,7201
|
6
|
+
orm_database-0.3.26.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
7
|
+
orm_database-0.3.26.dist-info/top_level.txt,sha256=dzcxzqcdsX4x3lqSkz1tVcu1qKX02rXOu6QN3cHggU4,13
|
8
|
+
orm_database-0.3.26.dist-info/RECORD,,
|
@@ -1,8 +0,0 @@
|
|
1
|
-
orm_database/__init__.py,sha256=q0A0dUBMacf_yaU5m4VWCDlP__pVAz3I1Bhn1RPkv9I,140
|
2
|
-
orm_database/orm_database.py,sha256=orJWFQzHY_YO26JHUyjQZWM9C-f1YH4GsYDMV7gHzk4,7258
|
3
|
-
orm_database/orm_query.py,sha256=EdXZed7__PztNryr3F0hNc5bBuS0gNKMsZc1E4Wg4Y0,3085
|
4
|
-
orm_database-0.3.17.dist-info/LICENSE,sha256=v33KAoqx5qhyUNlHOjYmBBKDtd9ymzWB7sR4cova190,1064
|
5
|
-
orm_database-0.3.17.dist-info/METADATA,sha256=2SxUHftsfwFxfIwaU3XFjeHzITbXp9Ge6nr9Es5jeM4,5032
|
6
|
-
orm_database-0.3.17.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
7
|
-
orm_database-0.3.17.dist-info/top_level.txt,sha256=dzcxzqcdsX4x3lqSkz1tVcu1qKX02rXOu6QN3cHggU4,13
|
8
|
-
orm_database-0.3.17.dist-info/RECORD,,
|
File without changes
|
File without changes
|