Skip to content

Commit

Permalink
Version 1.1
Browse files Browse the repository at this point in the history
Merge pull request #10 from Djcharles26/work
  • Loading branch information
Djcharles26 authored Aug 1, 2021
2 parents c7c59a9 + 005d4fa commit 5d791a5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
15 changes: 2 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,2 @@
## Major Updates
- Updated how schemas and database is registered in methods
- Updated how primitive mongo functions are called
- Updated MongoException print and message override
- Updated how schema init function creates attributes of class
- Added mongo primitive call methods as classmethods in Schema class
- Updated validation methods of schema against objects
- Updated pymongoose snippet with new design of model
- Updated README.md

## Minor Updates
- Updated test models with new design
- Updated main test file to respect new design of package
## Minor updates
- Added validation of sort is None to avoid sorting with id in find
24 changes: 16 additions & 8 deletions pymongoose/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ def find(schema: str, query: dict, select = {}, populate=None, one=False, skip =
if "_id" in query and type(query["_id"]) is not dict:
query["_id"] = _convert_id_to_object_id(query["_id"])


sort_key, sort_value = "_id", ASCENDING
if sort is not None:
sort_key = list(sort.keys())[0]
Expand All @@ -275,10 +276,16 @@ def find(schema: str, query: dict, select = {}, populate=None, one=False, skip =
if one:
retval = database[schema_name].find_one(query, select)
else:
if limit is None:
retval = database[schema_name].find(query, select).skip(skip).sort(sort_key, sort_value)
if sort is not None:
if limit is None:
retval = database[schema_name].find(query, select).skip(skip).sort(sort_key, sort_value)
else:
retval = database[schema_name].find(query, select).skip(skip).limit(limit).sort(sort_key, sort_value)
else:
retval = database[schema_name].find(query, select).skip(skip).limit(limit).sort(sort_key, sort_value)
if limit is None:
retval = database[schema_name].find(query, select).skip(skip)
else:
retval = database[schema_name].find(query, select).skip(skip).limit(limit)
else:
aggregate = [
{"$match" : query}
Expand All @@ -300,11 +307,12 @@ def find(schema: str, query: dict, select = {}, populate=None, one=False, skip =
"$limit": limit
})

aggregate.append({
"$sort": {
f"{sort_key}": sort_value
}
})
if(sort is not None):
aggregate.append({
"$sort": {
f"{sort_key}": sort_value
}
})


retval = database[schema_name].aggregate(aggregate)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = pymongoose
version = 1.0
version = 1.1
author = Juan Carlos Lara
author_email = jlaraanaya@gmail.com
description = A pymongo helper with methods and classes
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0
1.1

0 comments on commit 5d791a5

Please sign in to comment.