orm-database 0.3.7__py3-none-any.whl → 0.3.9__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- orm_database/orm_database.py +28 -56
- orm_database/orm_query.py +65 -0
- orm_database-0.3.9.dist-info/LICENSE +21 -0
- orm_database-0.3.9.dist-info/METADATA +111 -0
- orm_database-0.3.9.dist-info/RECORD +8 -0
- {orm_database-0.3.7.dist-info → orm_database-0.3.9.dist-info}/WHEEL +1 -1
- orm_database-0.3.7.dist-info/METADATA +0 -11
- orm_database-0.3.7.dist-info/RECORD +0 -6
- {orm_database-0.3.7.dist-info → orm_database-0.3.9.dist-info}/top_level.txt +0 -0
orm_database/orm_database.py
CHANGED
@@ -2,7 +2,7 @@ import motor.motor_asyncio
|
|
2
2
|
import asyncpg
|
3
3
|
import mariadb
|
4
4
|
import sys
|
5
|
-
|
5
|
+
from orm_database.orm_query import *
|
6
6
|
class MariaDB:
|
7
7
|
def __init__(self, host:str,port:int,user:str,password:str,database:str):
|
8
8
|
self.host=host
|
@@ -12,19 +12,37 @@ class MariaDB:
|
|
12
12
|
self.database=database
|
13
13
|
|
14
14
|
|
15
|
-
async def
|
15
|
+
async def start(self):
|
16
16
|
try:
|
17
|
-
self.
|
18
|
-
user=
|
19
|
-
password=
|
20
|
-
host=
|
21
|
-
database=
|
17
|
+
self.db = mariadb.connect(
|
18
|
+
user=self.user,
|
19
|
+
password=self.password,
|
20
|
+
host=self.host,
|
21
|
+
database=self.database)
|
22
22
|
|
23
23
|
except:
|
24
24
|
print("Error connecting maraidb")
|
25
25
|
sys.exit(1)
|
26
26
|
|
27
27
|
|
28
|
+
async def teble_create_BaseModel(self,table:str , class_BaseModel):
|
29
|
+
query = query_baseModel_create_table(table,class_BaseModel)
|
30
|
+
cur = self.db.cursor()
|
31
|
+
cur.execute(query)
|
32
|
+
cur.close()
|
33
|
+
|
34
|
+
|
35
|
+
async def teble_create(self, table: str, field: dict):
|
36
|
+
query = query_create_table(table,field)
|
37
|
+
cur = self.db.cursor()
|
38
|
+
cur.execute(query)
|
39
|
+
cur.close()
|
40
|
+
|
41
|
+
async def insert_value(self, table: str, value: dict):
|
42
|
+
query = query_insert_value(table,value)
|
43
|
+
await self.db.execute(query)
|
44
|
+
await self.db.close()
|
45
|
+
|
28
46
|
|
29
47
|
|
30
48
|
class PostgreSQL:
|
@@ -39,65 +57,19 @@ class PostgreSQL:
|
|
39
57
|
|
40
58
|
|
41
59
|
async def teble_create_BaseModel(self,table:str , class_BaseModel):
|
42
|
-
query
|
43
|
-
result=class_BaseModel.model_json_schema()
|
44
|
-
for a in result['required']:
|
45
|
-
data = result['properties'][a]
|
46
|
-
try :
|
47
|
-
maxLength = data['maxLength']
|
48
|
-
match data['type']:
|
49
|
-
case 'integer':
|
50
|
-
types = 'int'
|
51
|
-
case 'boolean':
|
52
|
-
types = 'bool'
|
53
|
-
case 'number':
|
54
|
-
types = 'float'
|
55
|
-
case 'string':
|
56
|
-
types = 'varchar'
|
57
|
-
uint = str(a)+" "+types+'('+str(maxLength)+')'
|
58
|
-
query = query + " " + uint + " ,"
|
59
|
-
except :
|
60
|
-
match data['type']:
|
61
|
-
case 'integer':
|
62
|
-
types = 'int'
|
63
|
-
case 'boolean':
|
64
|
-
types = 'bool'
|
65
|
-
case 'number':
|
66
|
-
types = 'float'
|
67
|
-
case 'string':
|
68
|
-
types = 'varchar'
|
69
|
-
uint = str(a)+" "+types
|
70
|
-
query = query + " " + uint + " ,"
|
71
|
-
query = query[:-1]
|
72
|
-
query = query + ")"
|
60
|
+
query=query_baseModel_create_table(table,class_BaseModel)
|
73
61
|
await self.db.execute(query)
|
74
62
|
await self.db.close()
|
75
63
|
|
76
64
|
|
77
65
|
async def teble_create(self, table: str, field: dict):
|
78
|
-
query
|
79
|
-
filed_key = list(field.keys())
|
80
|
-
for a in filed_key:
|
81
|
-
query = query + a + " " + field[a] + " ,"
|
82
|
-
query = query[:-1]
|
83
|
-
query = query + ")"
|
66
|
+
query=query_create_table(table,field)
|
84
67
|
await self.db.execute(query)
|
85
68
|
await self.db.close()
|
86
69
|
|
87
70
|
|
88
71
|
async def insert_value(self, table: str, value: dict):
|
89
|
-
query =
|
90
|
-
filed_key = list(value.keys())
|
91
|
-
for a in filed_key:
|
92
|
-
query = query + " " + a + " " + ","
|
93
|
-
query = query[:-1]
|
94
|
-
query = query + ")"
|
95
|
-
query = query + " VALUES ("
|
96
|
-
filed_value = list(value.values())
|
97
|
-
for a in filed_value:
|
98
|
-
query = query + " '" + str(a) + "' " + ","
|
99
|
-
query = query[:-1]
|
100
|
-
query = query + ")"
|
72
|
+
query = query_insert_value(table,value)
|
101
73
|
await self.db.execute(query)
|
102
74
|
await self.db.close()
|
103
75
|
|
@@ -0,0 +1,65 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
def query_baseModel_create_table(table,class_BaseModel):
|
4
|
+
query = f"CREATE TABLE {table} ("
|
5
|
+
result=class_BaseModel.model_json_schema()
|
6
|
+
for a in result['required']:
|
7
|
+
data = result['properties'][a]
|
8
|
+
try :
|
9
|
+
maxLength = data['maxLength']
|
10
|
+
match data['type']:
|
11
|
+
case 'integer':
|
12
|
+
types = 'int'
|
13
|
+
case 'boolean':
|
14
|
+
types = 'bool'
|
15
|
+
case 'number':
|
16
|
+
types = 'float'
|
17
|
+
case 'string':
|
18
|
+
types = 'varchar'
|
19
|
+
if types == 'varchar':
|
20
|
+
uint = str(a)+" "+types+"("+data["varchar"]+")"+'('+str(maxLength)+')'
|
21
|
+
query = query + " " + uint + " ,"
|
22
|
+
else:
|
23
|
+
uint = str(a)+" "+types+'('+str(maxLength)+')'
|
24
|
+
query = query + " " + uint + " ,"
|
25
|
+
except :
|
26
|
+
match data['type']:
|
27
|
+
case 'integer':
|
28
|
+
types = 'int'
|
29
|
+
case 'boolean':
|
30
|
+
types = 'bool'
|
31
|
+
case 'number':
|
32
|
+
types = 'float'
|
33
|
+
case 'string':
|
34
|
+
types = 'varchar'
|
35
|
+
uint = str(a)+" "+types +"("+str(data["varchar"])+")"
|
36
|
+
query = query + " " + uint + " ,"
|
37
|
+
query = query[:-1]
|
38
|
+
query = query + ")"
|
39
|
+
return query
|
40
|
+
|
41
|
+
def query_create_table(table:str,field:dict):
|
42
|
+
query = f"CREATE TABLE {table} ("
|
43
|
+
filed_key = list(field.keys())
|
44
|
+
for a in filed_key:
|
45
|
+
query = query + a + " " + field[a] + " ,"
|
46
|
+
query = query[:-1]
|
47
|
+
query = query + ")"
|
48
|
+
return query
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
def query_insert_value(table:str,value:dict):
|
53
|
+
uery = f"INSERT INTO {table} ( "
|
54
|
+
filed_key = list(value.keys())
|
55
|
+
for a in filed_key:
|
56
|
+
query = query + " " + a + " " + ","
|
57
|
+
query = query[:-1]
|
58
|
+
query = query + ")"
|
59
|
+
query = query + " VALUES ("
|
60
|
+
filed_value = list(value.values())
|
61
|
+
for a in filed_value:
|
62
|
+
query = query + " '" + str(a) + "' " + ","
|
63
|
+
query = query[:-1]
|
64
|
+
query = query + ")"
|
65
|
+
return query
|
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 sisrsis
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,111 @@
|
|
1
|
+
Metadata-Version: 2.2
|
2
|
+
Name: orm_database
|
3
|
+
Version: 0.3.9
|
4
|
+
Summary: This module is written to launch your programs with any database you want in the shortest time
|
5
|
+
Home-page: https://github.com/sisrsis/orm-database
|
6
|
+
Author: SISRSIS
|
7
|
+
Author-email: virussisrsis@gmail.com
|
8
|
+
License: MIT
|
9
|
+
Description-Content-Type: text/markdown
|
10
|
+
License-File: LICENSE
|
11
|
+
Requires-Dist: asyncpg
|
12
|
+
Requires-Dist: motor
|
13
|
+
Requires-Dist: mariadb
|
14
|
+
Dynamic: author
|
15
|
+
Dynamic: author-email
|
16
|
+
Dynamic: description
|
17
|
+
Dynamic: description-content-type
|
18
|
+
Dynamic: home-page
|
19
|
+
Dynamic: license
|
20
|
+
Dynamic: requires-dist
|
21
|
+
Dynamic: summary
|
22
|
+
|
23
|
+
# Create table
|
24
|
+
|
25
|
+
```python
|
26
|
+
from orm_database import PostgreSQL
|
27
|
+
from pydantic import BaseModel
|
28
|
+
import asyncio
|
29
|
+
|
30
|
+
|
31
|
+
class User(BaseModel):
|
32
|
+
username: str
|
33
|
+
password: str
|
34
|
+
email: str
|
35
|
+
|
36
|
+
|
37
|
+
async def main():
|
38
|
+
db = PostgreSQL(host="127.0.0.1", user="postgres", password="", database="your_database_name")
|
39
|
+
await db.start()
|
40
|
+
|
41
|
+
# ایجاد جدول
|
42
|
+
await db.table_create("users", {"username": "varchar", "password": "varchar", "email": "varchar"})
|
43
|
+
|
44
|
+
# ایجاد مدل پایه
|
45
|
+
await db.table_create_BaseModel(table="users", class_BaseModel=User)
|
46
|
+
|
47
|
+
|
48
|
+
if __name__ == "__main__":
|
49
|
+
asyncio.run(main())
|
50
|
+
```
|
51
|
+
|
52
|
+
## create table mariadb baseModel
|
53
|
+
|
54
|
+
|
55
|
+
```python
|
56
|
+
from orm_database import MariaDB
|
57
|
+
import asyncio
|
58
|
+
from pydantic import BaseModel , Field
|
59
|
+
|
60
|
+
|
61
|
+
db = MariaDB(host="127.0.0.1",database="login",password="",port=3306,user="root")
|
62
|
+
|
63
|
+
class users(BaseModel):
|
64
|
+
user_rt : str = Field(varchar=20)
|
65
|
+
password_rt : str = Field(varchar=20)
|
66
|
+
email_rt : str = Field(varchar=20)
|
67
|
+
|
68
|
+
|
69
|
+
async def main():
|
70
|
+
await db.start()
|
71
|
+
await db.teble_create_BaseModel("tes",users)
|
72
|
+
|
73
|
+
|
74
|
+
asyncio.run(main())
|
75
|
+
|
76
|
+
```
|
77
|
+
|
78
|
+
## create table mariadb
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
```python
|
83
|
+
from orm_database import MariaDB
|
84
|
+
import asyncio
|
85
|
+
|
86
|
+
|
87
|
+
db = MariaDB(host="127.0.0.1",database="",password="",port=3306,user="root")
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
async def main():
|
93
|
+
await db.start()
|
94
|
+
await db.teble_create("test",{"username":"varchar(250)","email":"varchar(250)","old":"int"})
|
95
|
+
|
96
|
+
|
97
|
+
asyncio.run(main())
|
98
|
+
```
|
99
|
+
|
100
|
+
`test` name table
|
101
|
+
|
102
|
+
| name | field |
|
103
|
+
| -------- | ----------- |
|
104
|
+
| username | varchar(250)|
|
105
|
+
| email | varchar(250)|
|
106
|
+
| old | int |
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
|
@@ -0,0 +1,8 @@
|
|
1
|
+
orm_database/__init__.py,sha256=q0A0dUBMacf_yaU5m4VWCDlP__pVAz3I1Bhn1RPkv9I,140
|
2
|
+
orm_database/orm_database.py,sha256=-_Szd81sZZPaL2uDcA7pCjBGuhSOy2cqMATgjDiJ56c,6595
|
3
|
+
orm_database/orm_query.py,sha256=-wGTwSda02iTR8Xd2mV_yTfjKD_i8Qe0HWM-vGMLSFg,2080
|
4
|
+
orm_database-0.3.9.dist-info/LICENSE,sha256=v33KAoqx5qhyUNlHOjYmBBKDtd9ymzWB7sR4cova190,1064
|
5
|
+
orm_database-0.3.9.dist-info/METADATA,sha256=Jw12OxGpV7cM-wCj_qFjRbs2lzVId9itbwh_VNANIKs,2173
|
6
|
+
orm_database-0.3.9.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
7
|
+
orm_database-0.3.9.dist-info/top_level.txt,sha256=dzcxzqcdsX4x3lqSkz1tVcu1qKX02rXOu6QN3cHggU4,13
|
8
|
+
orm_database-0.3.9.dist-info/RECORD,,
|
@@ -1,11 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.1
|
2
|
-
Name: orm_database
|
3
|
-
Version: 0.3.7
|
4
|
-
Summary: This module is written to launch your programs with any database you want in the shortest time
|
5
|
-
Home-page: https://github.com/sisrsis/orm-database
|
6
|
-
Author: SISRSIS
|
7
|
-
Author-email: virussisrsis@gmail.com
|
8
|
-
License: MIT
|
9
|
-
Requires-Dist: asyncpg
|
10
|
-
Requires-Dist: motor
|
11
|
-
Requires-Dist: mariadb
|
@@ -1,6 +0,0 @@
|
|
1
|
-
orm_database/__init__.py,sha256=q0A0dUBMacf_yaU5m4VWCDlP__pVAz3I1Bhn1RPkv9I,140
|
2
|
-
orm_database/orm_database.py,sha256=v3mY981JnaU5yGytklaFK1Hu00lv5N5QZOa5xuHXOdU,7698
|
3
|
-
orm_database-0.3.7.dist-info/METADATA,sha256=NoDRanHeemj4ZEJWFQoPTC6touYum1MBSCrkPGC88_U,345
|
4
|
-
orm_database-0.3.7.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
5
|
-
orm_database-0.3.7.dist-info/top_level.txt,sha256=dzcxzqcdsX4x3lqSkz1tVcu1qKX02rXOu6QN3cHggU4,13
|
6
|
-
orm_database-0.3.7.dist-info/RECORD,,
|
File without changes
|