commit 8638609fb0d4e32b40b0d53b73c9841ef824e1f9
parent 50fa4b495956362589b481606e1cac0a00abfdc4
Author: Nikolas Mazur <nikolas@pop-os.localdomain>
Date: Thu, 26 Jan 2023 14:47:29 -0700
Debug seeds and db files
Diffstat:
M | db.py | | | 16 | +++++++++------- |
M | seeds.py | | | 52 | +++++++++++++++++++++++++++++----------------------- |
2 files changed, 38 insertions(+), 30 deletions(-)
diff --git a/db.py b/db.py
@@ -1,17 +1,18 @@
import bson
+import pymongo
from flask import current_app, g
from werkzeug.local import LocalProxy
-from flask_pymongo import PyMongo
+from pymongo import MongoClient
from pymongo.errors import DuplicateKeyError, OperationFailure
from bson.objectid import ObjectId
from bson.errors import InvalidId
-def get_db():
- db = getattr(g, "_database", None)
- if db is None:
- db = g._database = PyMongo(current_app).db
- return db
-db = LocalProxy(get_db)
+def get_database():
+ client = pymongo.MongoClient('localhost', 27017)
+ return client['simple_resource_management_software']
+
+if __name__ == '__main__':
+ dbname = get_database()
+\ No newline at end of file
diff --git a/seeds.py b/seeds.py
@@ -1,29 +1,35 @@
+import pymongo
+
+client = pymongo.MongoClient('mongodb://localhost:27017/simple_resource_management_software')
+db = client.get_database('simple_resource_management_software')
+collection = db.get_collection('user_collection')
+
# Database collections/documents
-# collection = db['users-collection'] # Make aditional user info single document/array
-post = {'name': 'Nikolas Mazur',
- 'role': 'Backend Developer',
- 'location': 'Remote',
+user1 = {
+ 'username': 'Nikolas',
+ 'password': 'password',
+ 'role': 'Developer',
+ 'location': 'Lander',
'phone': 3074380460,
'email': 'kolemazur@gmail.com',
- 'active': 1,
- 'pay_period': 'Monthly',
- 'pay_value': 10}
-
-# collection = db['time-data-collection']
-
-post = {'time': datetime.datetime.utcnow(),
- 'clocked_in': datetime.datetime.utcnow(),
- 'edited_by_user': 'Nikolas Mazur',
- 'edit_time': datetime.datetime.utcnow(),
- 'day': '29',
- 'month': '3',
- 'project': ['Timecard'],
- 'Perdium': 0}
-
-# collection = db['fleet-collection']
+ 'pay_period': 'salaried',
+ 'pay_value': 43000,
+ }
+user2 = {
+ '_id': '2',
+ 'username': 'Brennen',
+ 'password': 'password',
+ 'role': 'Developer',
+ 'location': 'Dillon',
+ 'phone': 3074380491,
+ 'email': 'brennen.mazur@gmail.com',
+ 'pay_period': 'salaried',
+ 'pay_value': 43000,
+ }
+collection.insert_many([user1, user2])
-# collection = db['agreement-collection']
-# Database collections/documents
-\ No newline at end of file
+for x in collection.find():
+ print(x)
+\ No newline at end of file