forked from kaiiyer/UBA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
69 lines (63 loc) · 2.21 KB
/
Copy pathdatabase.py
File metadata and controls
69 lines (63 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
'''
Copyright 2019-Present The OpenUB Platform Authors
This file is part of the OpenUB Platform library.
The OpenUB Platform is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
The OpenUB Platform is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the OpenUB Platform. If not, see <http://www.gnu.org/licenses/>.
'''
import logging
from pymongo import MongoClient
'''
@name DB
@description fundamental database parent class
'''
class DB():
def __init__(self):
print("db initiated")
#db_connect = Connector()
#client = MongoClient()
try:
client = MongoClient('localhost', 27017)
#client = MongoClient('mongodb://localhost:27017')
db = client['pymongo_test']
posts = db.posts
post_data = {
'title': 'Python and MongoDB',
'content': 'PyMongo is fun, you guys',
'author': 'Scott'
}
result = posts.insert_one(post_data)
print('One post: {0}'.format(result.inserted_id))
scott_post = posts.find_one({'author': 'Scott'})
print(scott_post)
except Exception as e:
logging.error(e)
'''
@name connector
@description this should enable the database, to be invoked using Query
'''
class Connector():
def __init__(self, type):
print("connector made")
if type == "mongodb":
self.type = MongoDBConnectorType()
else:
raise Exception("Unsupported Connector type")
def connect(self):
self.type.attempt_to_connect()
'''
@name MongoDBConnector
@description connect to mongo
'''
class MongoDBConnector(Connector):
def __init__(self):
print("Mongo db type made")
def attempt_to_connect(self):
print("Connecting to mongo")