This repository was archived by the owner on Aug 16, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Original file line number Diff line number Diff line change 1+ # Import MongoClient from PyMongo
2+ from pymongo import MongoClient
3+
4+ # Base Class aka raw database
5+ class Base ():
6+
7+ # Constructor Class
8+ def __init__ (self , client , options : dict = {}):
9+ self .client = client
10+ self .db = self .client [options ['db_name' ]]
11+ self .options = options
12+ self .collection = self .db [self .options ['collection_name' ]]
13+
14+ def set (self , key , value ):
15+ self .collection .delete_many ({
16+ 'key' : key
17+ })
18+
19+ self .collection .insert_one ({
20+ 'key' : key ,
21+ 'value' : value
22+ })
23+ return
24+
25+ def get (self , key ):
26+ try :
27+ try :
28+ return self .collection .find ({ 'key' : key })[0 ]['value' ]
29+ except :
30+ return self .collection .find ({ 'key' : key })[0 ]
31+ except :
32+ return None
33+
34+ def all (self ):
35+ data = self .collection .find ({})
36+ res = []
37+
38+ for doc in list (data ):
39+ try :
40+ res .append ({
41+ 'key' : doc ['key' ],
42+ 'value' : doc ['value' ]
43+ })
44+ except :
45+ return list (data )
46+
47+ return res
48+
49+ def drop (self ):
50+ self .collection .drop ()
51+
52+ def delete (self , key : str ):
53+ self .collection .delete_many ({
54+ 'key' : key
55+ })
56+ return
You can’t perform that action at this time.
0 commit comments