Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/anonimongo/core/bson.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1011,11 +1011,11 @@ proc decode*(strbytes: string): BsonDocument =
encoded: true
)

proc newBson*(table: varargs[(string, BsonBase)]): BsonDocument =
proc newBson*(first: (string, BsonBase), table: varargs[(string, BsonBase)]): BsonDocument =
var tableres = newOrderedTable[string, BsonBase]()
## Overload newBson with table definition only and stream default to
## StringStream. In most case, use `bson macro<#bson.m,untyped>`_.
for t in table:
for t in @[first] & table.toSeq:
tableres[t[0]] = t[1]
BsonDocument(
table: tableres,
Expand Down Expand Up @@ -1081,4 +1081,4 @@ converter ofTimestamp*(b: BsonBase): TimestampInternal =
bsonFetcher(b, bkTimestamp, BsonTimestamp, TimestampInternal)

template bson*(): untyped = bson({})
## Convenience for empty bson.
## Convenience for empty bson.
4 changes: 4 additions & 0 deletions src/anonimongo/core/macroto_v2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,10 @@ proc assignObj(info: NodeInfo): NimNode =
else: immediateParent
bodyif.add quote do:
var `resvar`: `parentSym`
elif targetSym.kind == nnkPostfix:
let target = targetSym[1]
bodyif.add quote do:
var `resvar`: `target`
else:
bodyif.add quote do:
var `resvar`: `targetSym`
Expand Down
9 changes: 4 additions & 5 deletions src/anonimongo/core/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,11 @@ proc newMongo*[S: Multisock](muri: MongoUri, poolconn = poolconn, dnsserver = "8
template raiseInvalidSep: untyped =
raise newException(MongoError,
&"Whether invalid URI {uri} or missing trailing '/'")
type URLUri = uri.Uri
let uri = muri.string
if uri.count('/') < 3:
raiseInvalidSep()
let uriobj = parseUri uri
type URLUri = Uri
var uris: seq[URLUri]
if uriobj.scheme == "":
raise newException(MongoError, &"No scheme protocol provided at \"{uri}\" uri")
Expand All @@ -328,7 +327,7 @@ proc newMongo*[S: Multisock](muri: MongoUri, poolconn = poolconn, dnsserver = "8
raise newException(MongoError, errmsg)
for i, ans in resp.answers:
let srvrec = ans as SRVRecord
uris[i] = Uri(
uris[i] = URLUri(
scheme: "mongodb",
hostname: srvrec.target,
port: $srvrec.port,
Expand Down Expand Up @@ -367,7 +366,7 @@ proc newMongo*[S: Multisock](muri: MongoUri, poolconn = poolconn, dnsserver = "8
if hdom.len > 1:
port = hdom[1]
hostname = hdom[0]
uris[i] = Uri(
uris[i] = URLUri(
scheme: scheme,
hostname: hostname,
port: port,
Expand Down Expand Up @@ -600,4 +599,4 @@ proc toCursor*[S: MultiSock](b: BsonDocument): Cursor[S] =
firstBatch: if "firstBatch" in b: b["firstBatch"].ofArray.map(ofEmbedded) else: @[],
nextBatch: if "nextBatch" in b: b["nextBatch"].ofArray.map(ofEmbedded) else: @[],
ns: b["ns"],
)
)