User Manual

Class uiink::Query

Queries allow you to find a Data object in a list that matches given field value(s).

To get an idea of when you might want to use a query, check out: http://uiink.com/articles/query-api/

Methods

Query(Data parent, Ident field)
void Dispose()
Query MatchInt(Ident field, int v)
Query MatchBool(Ident field, bool v)
Query MatchString(Ident field, string v)
Query MatchIdent(Ident field, Ident v)
Query MatchColor(Ident field, uint v)
Data Get()

Returns the first Data that matches this Query, creating it if it doesn't exist.

If a new entry had to be created, it will be automatically populated with the field values of this Query.

If this is called inside of Data.Rebuild(), the returned Data object will not be removed when the rebuild ends.

Examples

var main = ink.Source("main");
var q = new Query(main, "entries");
Data d = q.MatchString("label", "Hello World!").Get();
AssertEquals(d.GetString("label"), "Hello World!");

Data MaybeGet()

Returns the first Data that matches this Query.

If no entry in the list matches the Query, an empty Data handle is returned. If this is called inside of Data.Rebuild(), the returned Data object will not be removed when the rebuild ends.

Examples

var main = ink.Source("main");
var q = new Query(main, "entries");
Data d = q.MatchString("label", "Hello World!").MaybeGet();
AssertFalsy(d);

Using a query within a rebuild prevents the data from being removed:

var main = ink.Source("main");
main.Append("entries").SetString("label", "Hello World!");
main.Append("entries").SetString("label", "Goodbye Cruel World!");

main.Rebuild(() => {
    main.Query("entries").MatchString("label", "Hello World!").Get();
});

AssertEquals(main.GetChild("entries", 0).GetString("label"), "Hello World!");
AssertFalsy(main.GetChild("entries", 1));

void Remove()

Remove all Data objects that match this Query.

Examples

var main = ink.Source("main");
var d = main.Append("entries");
d.SetString("label", "Hello World!");

new Query(main, "entries").MatchString("label", "Hello World!").Remove();
AssertFalsy(main.GetChild("entries", 0));