VibeD - undefinded identifier

holo via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jul 23 09:25:43 PDT 2017


On Sunday, 23 July 2017 at 15:43:31 UTC, Seb wrote:
> On Sunday, 23 July 2017 at 15:23:25 UTC, holo wrote:
>> Hello
>>
>> Im trying to create REST api for my simple web page. My code 
>> is looking like below:
>>
>> module service.frontpage;
>>
>> import vibe.d;
>>
>> @path("/api")
>> interface IFrontPageAPI
>> {
>>   Json getHome();
>> }
>>
>> class FrontPageAPI : IFrontPageAPI
>> {
>>
>>
>>   this(auto tmp)
>>   {
>>     auto collect = tmp;
>>   }
>>
>>   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());
>>
>>     return result.toJson();
>>   }
>> }
>>
>> But when i try to compile it im getting:
>>
>> source/service/frontpage.d(15,3): Error: undefined identifier 
>> 'tmp', did you mean alias 'cmp'?
>>
>> Did i miss something?
>
> You need to
> - use Class variables
> - use types instead auto (here Mongo collection)
> - return a proper Json
>
> Have a look at: https://is.gd/7AMsKs
>
> And play with it - no output means no complication error.

Thank you it solves my problem, but now i'm getting:

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)
source/service/frontpage.d(21,10): Error: function 
frontpage.FrontPageAPI.getHome no return exp; or assert(0); at 
end of function

What is strange it is just copy/paste from example: 
https://github.com/rejectedsoftware/vibe.d/blob/master/examples/mongodb/source/app.d




More information about the Digitalmars-d-learn mailing list