VibeD - undefinded identifier
holo via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jul 23 11:23:12 PDT 2017
On Sunday, 23 July 2017 at 17:16:44 UTC, Seb wrote:
> On Sunday, 23 July 2017 at 16:37:19 UTC, holo wrote:
>> On Sunday, 23 July 2017 at 16:27:40 UTC, Mike Parker wrote:
>>> On Sunday, 23 July 2017 at 15:23:25 UTC, holo wrote:
>>>
>>>> this(auto tmp)
>>>
>>> You need to specify a type here instead of using auto.
>>
>> Thanks for reply i fix it. But right now im getting:
>>
>> ../../.dub/packages/vibe-d-0.7.31/vibe-d/source/vibe/http/server.d(286,33): Deprecation: alias diet.traits.FilterCallback is deprecated - Use SafeFilterCallback instead.
>> source/service/frontpage.d(28,30): Error: template
>> std.array.byPair cannot deduce function from argument types
>> !()(MongoCursor!(Bson, Bson, typeof(null))), candidates are:
>> /usr/include/dlang/dmd/std/array.d(419,6):
>> std.array.byPair(Key, Value)(Value[Key] aa)
>
> What are you trying to do with byPair?
> It's only defined for the MongoCursor:
> http://vibed.org/api/vibe.db.mongo.cursor/MongoCursor.byPair
>
> That std.array.byPair shows up means that you are using it for
> something else?
>
>> source/service/frontpage.d(21,10): Error: function
>> frontpage.FrontPageAPI.getHome no return exp; or assert(0); at
>> end of function
>
> I guess you forgot a return here?
> Maybe it's easier to post your code again?
I took this code from example:
https://github.com/rejectedsoftware/vibe.d/blob/master/examples/mongodb/source/app.d
And it is looking right now like below:
import vibe.d;
import std.algorithm, std.array;
@path("/api")
interface IFrontPageAPI
{
Json getHome();
}
class FrontPageAPI : IFrontPageAPI
{
this(MongoCollection tmp)
{
collect = tmp;
}
private:
MongoCollection collect;
public:
Json getHome()
{
logInfo("Getting HomePage from DB");
Bson query = Bson(["_id" : Bson("homepage")]);
auto result = collect.find(query);
logInfo("Iterating results...");
foreach (i, doc; result.byPair)
logInfo("Item %d: %s", i, doc.toJson().toString());
logInfo("Sending Json");
return Json(result.map!(a => a.toJson).array);
}
}
When i remove this piece of code:
logInfo("Iterating results...");
foreach (i, doc; result.byPair)
logInfo("Item %d: %s", i, doc.toJson().toString());
everything is working as expecting.
One more question, what it does mean:
return Json(result.map!(a => a.toJson).array);
Why we cant just use something like result.toJson?
When i
More information about the Digitalmars-d-learn
mailing list