mirror of https://github.com/Hax-io/libpb
- Implemented `viewRecord()`
- Added unittests for `viewRecord()`
This commit is contained in:
parent
9cfed9b33d
commit
c2597788d7
|
@ -84,6 +84,29 @@ public class PocketBase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RecordType viewRecord(RecordType)(string table, string id)
|
||||||
|
{
|
||||||
|
RecordType recordOut;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string responseData = cast(string)get(pocketBaseURL~"collections/"~table~"/records/"~id);
|
||||||
|
JSONValue responseJSON = parseJSON(responseData);
|
||||||
|
|
||||||
|
recordOut = fromJSON!(RecordType)(responseJSON);
|
||||||
|
|
||||||
|
return recordOut;
|
||||||
|
}
|
||||||
|
catch(CurlException e)
|
||||||
|
{
|
||||||
|
throw new PBException(PBException.ErrorType.CURL_NETWORK_ERROR, e.msg);
|
||||||
|
}
|
||||||
|
catch(JSONException e)
|
||||||
|
{
|
||||||
|
throw new PBException(PBException.ErrorType.JSON_PARSE_ERROR, e.msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public RecordType updateRecord(string, RecordType)(string table, RecordType item)
|
public RecordType updateRecord(string, RecordType)(string table, RecordType item)
|
||||||
{
|
{
|
||||||
idAbleCheck(item);
|
idAbleCheck(item);
|
||||||
|
@ -401,6 +424,7 @@ unittest
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
import core.thread : Thread, dur;
|
import core.thread : Thread, dur;
|
||||||
|
import std.string : cmp;
|
||||||
|
|
||||||
PocketBase pb = new PocketBase();
|
PocketBase pb = new PocketBase();
|
||||||
|
|
||||||
|
@ -426,5 +450,10 @@ unittest
|
||||||
assert(recordStored.age == 46);
|
assert(recordStored.age == 46);
|
||||||
Thread.sleep(dur!("seconds")(3));
|
Thread.sleep(dur!("seconds")(3));
|
||||||
|
|
||||||
|
Person recordFetched = pb.viewRecord!(Person)("dummy", recordStored.id);
|
||||||
|
assert(recordFetched.age == 46);
|
||||||
|
assert(cmp(recordFetched.name, "Tristan Gonzales") == 0);
|
||||||
|
assert(cmp(recordFetched.id, recordStored.id) == 0);
|
||||||
|
|
||||||
pb.deleteRecord("dummy", recordStored);
|
pb.deleteRecord("dummy", recordStored);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue