Skip to content

Commit

Permalink
bump new version
Browse files Browse the repository at this point in the history
  • Loading branch information
zookzook committed Jan 23, 2020
1 parent 1644467 commit 0d0a3dc
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## 0.6.3

* Enhancements
* basic support for inserting structs
* removed duplicated code
* Cursor-API raises a `Mongo.Error` instead of a `FunctionClauseError`

* Bugfixes
* `:appname` option (typo) #38
* fixed index creation in `Mongo.GridFs.Bucket`

## 0.6.2

* Enhancements
Expand Down
8 changes: 7 additions & 1 deletion lib/mongo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1093,8 +1093,14 @@ defmodule Mongo do
##
# Checks the validity of the document structure. that means either you use binaries or atoms as a key, but not in combination of both.
#
#
# todo support for structs
defp normalize_doc(doc) do

#doc = case Map.has_key?(doc, :__struct__) do
# true -> Map.to_list(doc)
# false -> doc
#end

Enum.reduce(doc, {:unknown, []}, fn
{key, _value}, {:binary, _acc} when is_atom(key) -> invalid_doc(doc)
{key, _value}, {:atom, _acc} when is_binary(key) -> invalid_doc(doc)
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Mongodb.Mixfile do
use Mix.Project

@version "0.6.2"
@version "0.6.3"

def project() do
[app: :mongodb_driver,
Expand Down
19 changes: 19 additions & 0 deletions test/mongo_test.exs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
defmodule TestUser do
defstruct name: "John", age: 27
end

defmodule Mongo.Test do
use ExUnit.Case

Expand Down Expand Up @@ -602,4 +606,19 @@ defmodule Mongo.Test do

end

test "save struct", c do

coll = unique_name()
value = %TestUser{}
{:ok, %Mongo.InsertOneResult{inserted_id: id}} = Mongo.insert_one(c.pid, coll, value)
assert id != nil

user = Mongo.find_one(c.pid, coll, %{_id: id})
|> Enum.into(%{}, fn {key, val} -> {String.to_atom(key), val} end)

user = struct(TestUser, user)

assert value == user
end

end

0 comments on commit 0d0a3dc

Please sign in to comment.