mirror of https://github.com/Hax-io/libpb
Updated usage examples with record management and updated assertions
This commit is contained in:
parent
0cd17f976e
commit
b894b6e1c6
39
README.md
39
README.md
|
@ -29,6 +29,7 @@ This is just to show off the serialization method `serializeRecord(RecordType)`
|
||||||
public int age;
|
public int age;
|
||||||
public string[] list;
|
public string[] list;
|
||||||
public JSONValue extraJSON;
|
public JSONValue extraJSON;
|
||||||
|
public EnumType eType;
|
||||||
}
|
}
|
||||||
|
|
||||||
Person p1;
|
Person p1;
|
||||||
|
@ -37,6 +38,7 @@ This is just to show off the serialization method `serializeRecord(RecordType)`
|
||||||
p1.age = 23;
|
p1.age = 23;
|
||||||
p1.list = ["1", "2", "3"];
|
p1.list = ["1", "2", "3"];
|
||||||
p1.extraJSON = parseJSON(`{"item":1, "items":[1,2,3]}`);
|
p1.extraJSON = parseJSON(`{"item":1, "items":[1,2,3]}`);
|
||||||
|
p1.eType = EnumType.CAT;
|
||||||
|
|
||||||
JSONValue serialized = PocketBase.serializeRecord(p1);
|
JSONValue serialized = PocketBase.serializeRecord(p1);
|
||||||
|
|
||||||
|
@ -44,6 +46,11 @@ This is just to show off the serialization method `serializeRecord(RecordType)`
|
||||||
assert(canFind(keys, "firstname") && cmp(serialized["firstname"].str(), "Tristan") == 0);
|
assert(canFind(keys, "firstname") && cmp(serialized["firstname"].str(), "Tristan") == 0);
|
||||||
assert(canFind(keys, "lastname") && cmp(serialized["lastname"].str(), "Kildaire") == 0);
|
assert(canFind(keys, "lastname") && cmp(serialized["lastname"].str(), "Kildaire") == 0);
|
||||||
assert(canFind(keys, "age") && serialized["age"].integer() == 23);
|
assert(canFind(keys, "age") && serialized["age"].integer() == 23);
|
||||||
|
|
||||||
|
debug(dbg)
|
||||||
|
{
|
||||||
|
writeln(serialized.toPrettyString());
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Deserialization
|
### Deserialization
|
||||||
|
@ -74,13 +81,43 @@ This is to show off deserialization method `fromJSON(RecordType)(JSONValue jsonI
|
||||||
|
|
||||||
Person person = PocketBase.fromJSON!(Person)(json);
|
Person person = PocketBase.fromJSON!(Person)(json);
|
||||||
|
|
||||||
|
debug(dbg)
|
||||||
|
{
|
||||||
writeln(person);
|
writeln(person);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
assert(cmp(person.firstname, "Tristan") == 0);
|
assert(cmp(person.firstname, "Tristan") == 0);
|
||||||
assert(cmp(person.lastname, "Kildaire") == 0);
|
assert(cmp(person.lastname, "Kildaire") == 0);
|
||||||
assert(person.age == 23);
|
assert(person.age == 23);
|
||||||
assert(person.isMale == true);
|
assert(person.isMale == true);
|
||||||
//TODO: object test case, list test case
|
assert(person.obj["bruh"].integer() == 1);
|
||||||
|
//TODO: list test case
|
||||||
|
```
|
||||||
|
|
||||||
|
### Record management
|
||||||
|
|
||||||
|
Below we have a few calls like create and delete:
|
||||||
|
|
||||||
|
```d
|
||||||
|
PocketBase pb = new PocketBase();
|
||||||
|
|
||||||
|
struct Person
|
||||||
|
{
|
||||||
|
string id;
|
||||||
|
string name;
|
||||||
|
int age;
|
||||||
|
}
|
||||||
|
|
||||||
|
Person p1 = Person();
|
||||||
|
p1.name = "Tristan Gonzales";
|
||||||
|
p1.age = 23;
|
||||||
|
|
||||||
|
Person recordStored = pb.createRecord("dummy", p1);
|
||||||
|
pb.deleteRecord("dummy", recordStored.id);
|
||||||
|
|
||||||
|
recordStored = pb.createRecord("dummy", p1);
|
||||||
|
pb.deleteRecord("dummy", recordStored);
|
||||||
```
|
```
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
Loading…
Reference in New Issue