Skip to content

Parts of a loafang query

A sample query

This is what a sample loafang query looks like

{
    "GET:get-users":{
        "user --name ad":[
            "username",
            "email"
        ],

        "user --name john":[
            "username",
            "email"
        ]
    },

    "GET:get-user-fred:pe": {
        "user --name fred":[
            "username",
            "email"
        ]
    },

    "PUT:update-user-fred": {
        "user --name fred":{
            "username": "fredmy"
        },

        "after": "get-user-fred"
    }
}

The execution block.

"GET:get-users":{
        "user --name ad":[
            "username",
            "email"
        ],

        "user --name john":[
            "username",
            "email"
        ]
    },

This is what's called as a Execution block. And a loafang query is made by stacking together a bunch of these Execution Blocks.

Parts of an execution block

The header

GET:get-users

This is the header of an execution block and is made up of three parts.

  • The request type. (GET, POST, PUT, DELETE, PATCH)

  • A unique identification string for the execution block

  • And a block property key(Optional)

The three parts are arranged in the following order

METHOD:ID:PROPERTY_KEY

The ID must be unique among all the execution blocks in a given loafang query.

A property key can completely change the behavior of an execution block.

Currently there is only one property key that is pe. The pe key will skip the execution of the given block

The Body

The body of an execution block is made up of all the queries that needs to be executed. The request methods (GET, POST, ...) of each query will be the one specified in the header of the execution block.

Parts of a query.

The query has two parts, the args (the head and parameters) and the content of the query.

 "user --name john": [
            "username",
            "email"
        ]

This is a sample query inside an execution block.

Here,

user is the head of the query or where the query needs to executed, this can be a database name or anything like that.

--name john is the parameter to the query. These can be parameter to filter the head.

["username", "email"] These are the content of the query, these can be the fields that you wish to get from the database with the specified parameters.

The contents of the query must be a list for GET and DELETE queries and must be a dict / JS object for PUT, POST, and PATCH.

Query Aliases

In the end response that will be generated by loafang the key of the an executed query in a block will be the query it self. In order to make it a bit easier for a developer to go through the response, you can add aliases to your query.

{
    "GET:get-users":{
        "user --name ad | user-ad":[
            "username",
            "email"
        ],

        "user --name john | user-john":[
            "username",
            "email"
        ]
    }
}

Anything after the pipe (|) is considered as an alias to the query.

No to queries in a block can have the same alias but two queries in two different blocks can have the same alias name.

Click Here to see how aliases affect the response.

The after key.

The after key in an execution block specifies another execution block that needs to executed after the current block has done executing. This can be used to retrieve data after a POST request has been made.

  • The after key can only point to an execution block that has pe as it's property key.

  • An execution block that has pe as it's property key cannot have an after key.