Skip to main content

QueryBuilder

A small utility to build selector strings for Instance.QueryDescendants.

All functions on the class return self so you can chain like so:

local myModel = ...
myModel:QueryDescendants(QueryBuilder.new():withTag("Cool"):query())

Functions

new

QueryBuilder.new() → ()

withTag

returns-self
QueryBuilder:withTag(tagstring) → QueryBuilder

Adds the tag to the search query.

either

returns-self
QueryBuilder:either(tagstring) → QueryBuilder

An or operation between whats on the left to the right. For example:

:withTag("Apple"):either():withTag("Orange"):hasAttribute("IsPeeled")
-- Has the tag "Apple" OR Has the tag "Orange" with an attribute of "IsPeeled"

child

returns-self
QueryBuilder:child() → QueryBuilder

Anything after this method is called will act on children of queried instances that match the previous cases.

descendant

returns-self
QueryBuilder:descendant() → QueryBuilder

Same as QueryBuilder.child but for descendant.

negate

returns-self
QueryBuilder:negate() → QueryBuilder

Negates the next function that is aclled. For example:

:negate():withTag("cool") -- Does NOT have the tag "cool"

hasAttribute

returns-self
QueryBuilder:hasAttribute(attributeNamestring) → QueryBuilder

Anything which has the attributeName set to anything but nil

hasAttribute

returns-self
QueryBuilder:hasAttribute(
attributeNamestring,
attributeValuestring | any
) → QueryBuilder

Anything which has the attributeName set to attributeValue. See more info about how attributeValue works: QueryBuilder.wherePropertyIs

whichIsA

returns-self
QueryBuilder:whichIsA(classstring) → QueryBuilder

Anything which is a of class class (:IsA())

named

returns-self
QueryBuilder:named(namestring) → QueryBuilder

Anything which has the name name.

wherePropertyIs

returns-self
QueryBuilder:wherePropertyIs(
propertystring,
valuestring | any
) → QueryBuilder

Anything which has the its property set to value. For best results you should pass the value as a string, for example:

:wherePropertyIs("CanCollide", "false")
WARNING

If you pass a normal value into value then tostring(value) will be called on the value.

query

QueryBuilder:query() → string

Returns the built up query string.

Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "",
            "params": [],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 41,
                "path": "packages/queryBuilder/source/init.luau"
            }
        },
        {
            "name": "_AppendToQuery",
            "desc": "Internal function to directly append to the qurey string. Also appends any needed characters\nlike a closing brace if a §not§ operation was used.",
            "params": [
                {
                    "name": "append",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [],
            "function_type": "method",
            "private": true,
            "source": {
                "line": 57,
                "path": "packages/queryBuilder/source/init.luau"
            }
        },
        {
            "name": "withTag",
            "desc": "Adds the `tag` to the search query.",
            "params": [
                {
                    "name": "tag",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "QueryBuilder"
                }
            ],
            "function_type": "method",
            "tags": [
                "returns-self"
            ],
            "source": {
                "line": 74,
                "path": "packages/queryBuilder/source/init.luau"
            }
        },
        {
            "name": "either",
            "desc": "An `or` operation between whats on the left to the right. For example:\n```lua\n:withTag(\"Apple\"):either():withTag(\"Orange\"):hasAttribute(\"IsPeeled\")\n-- Has the tag \"Apple\" OR Has the tag \"Orange\" with an attribute of \"IsPeeled\"\n```",
            "params": [
                {
                    "name": "tag",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "QueryBuilder"
                }
            ],
            "function_type": "method",
            "tags": [
                "returns-self"
            ],
            "source": {
                "line": 92,
                "path": "packages/queryBuilder/source/init.luau"
            }
        },
        {
            "name": "child",
            "desc": "Anything after this method is called will act on children of queried instances\nthat match the previous cases.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "QueryBuilder"
                }
            ],
            "function_type": "method",
            "tags": [
                "returns-self"
            ],
            "source": {
                "line": 106,
                "path": "packages/queryBuilder/source/init.luau"
            }
        },
        {
            "name": "descendant",
            "desc": "Same as [QueryBuilder.child] but for descendant.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "QueryBuilder"
                }
            ],
            "function_type": "method",
            "tags": [
                "returns-self"
            ],
            "source": {
                "line": 119,
                "path": "packages/queryBuilder/source/init.luau"
            }
        },
        {
            "name": "negate",
            "desc": "Negates the next function that is aclled. For example:\n```lua\n:negate():withTag(\"cool\") -- Does NOT have the tag \"cool\"\n```",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "QueryBuilder"
                }
            ],
            "function_type": "method",
            "tags": [
                "returns-self"
            ],
            "source": {
                "line": 135,
                "path": "packages/queryBuilder/source/init.luau"
            }
        },
        {
            "name": "hasAttribute",
            "desc": "Anything which has the `attributeName` set to anything but nil",
            "params": [
                {
                    "name": "attributeName",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "QueryBuilder"
                }
            ],
            "function_type": "method",
            "tags": [
                "returns-self"
            ],
            "source": {
                "line": 150,
                "path": "packages/queryBuilder/source/init.luau"
            }
        },
        {
            "name": "hasAttribute",
            "desc": "Anything which has the `attributeName` set to `attributeValue`. See more info about how `attributeValue` works: [QueryBuilder.wherePropertyIs]",
            "params": [
                {
                    "name": "attributeName",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "attributeValue",
                    "desc": "",
                    "lua_type": "string | any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "QueryBuilder"
                }
            ],
            "function_type": "method",
            "tags": [
                "returns-self"
            ],
            "source": {
                "line": 165,
                "path": "packages/queryBuilder/source/init.luau"
            }
        },
        {
            "name": "whichIsA",
            "desc": "Anything which is a of class `class` (`:IsA()`)",
            "params": [
                {
                    "name": "class",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "QueryBuilder"
                }
            ],
            "function_type": "method",
            "tags": [
                "returns-self"
            ],
            "source": {
                "line": 179,
                "path": "packages/queryBuilder/source/init.luau"
            }
        },
        {
            "name": "named",
            "desc": "Anything which has the name `name`.",
            "params": [
                {
                    "name": "name",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "QueryBuilder"
                }
            ],
            "function_type": "method",
            "tags": [
                "returns-self"
            ],
            "source": {
                "line": 193,
                "path": "packages/queryBuilder/source/init.luau"
            }
        },
        {
            "name": "wherePropertyIs",
            "desc": "Anything which has the its `property` set to `value`. For best results you should pass the value as a string, for example:\n```lua\n:wherePropertyIs(\"CanCollide\", \"false\")\n```\n\n:::warning\nIf you pass a normal value into `value` then `tostring(value)` will be called on the value.\n:::",
            "params": [
                {
                    "name": "property",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "string | any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "QueryBuilder"
                }
            ],
            "function_type": "method",
            "tags": [
                "returns-self"
            ],
            "source": {
                "line": 215,
                "path": "packages/queryBuilder/source/init.luau"
            }
        },
        {
            "name": "query",
            "desc": "Returns the built up query string.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 226,
                "path": "packages/queryBuilder/source/init.luau"
            }
        }
    ],
    "properties": [
        {
            "name": "_Query",
            "desc": "The current query string. Do NOT access this directly, instead use [QueryBuilder.query]",
            "lua_type": "string",
            "private": true,
            "readonly": true,
            "source": {
                "line": 30,
                "path": "packages/queryBuilder/source/init.luau"
            }
        },
        {
            "name": "_Not",
            "desc": "Controls if the next query is negated. [QueryBuilder.negate]",
            "lua_type": "boolean",
            "private": true,
            "readonly": true,
            "source": {
                "line": 39,
                "path": "packages/queryBuilder/source/init.luau"
            }
        }
    ],
    "types": [],
    "name": "QueryBuilder",
    "desc": "A small utility to build selector strings for [Instance.QueryDescendants](https://create.roblox.com/docs/reference/engine/classes/Instance#QueryDescendants).\n\nAll functions on the class return self so you can chain like so:\n```lua\nlocal myModel = ...\nmyModel:QueryDescendants(QueryBuilder.new():withTag(\"Cool\"):query())\n```",
    "source": {
        "line": 11,
        "path": "packages/queryBuilder/source/init.luau"
    }
}