Introducing Polylang



Oct 20, 2022


Polylang is the programming language used in Polybase. Designed to be easy to read and understand, Polylang allows developers to declaratively define their schemas and functions. The language was inspired by TypeScript and JavaScript, if you are familiar with those languages, you should be able to pick up Polylang quickly.


Field Types

Polybase supports the following field types:

  • string: a string of characters

  • number: a numerical, floating point value

  • map<K, V>: a key-value map, where K is the type of the keys (either string or number) and V is the type of the values

  • array: an ordered list of values, such as string[] for an array of strings

  • object: a nested object, such as details: { description: string; manufacturer: string; }


Here is an example of a collection definition in Polylang:

Polylang is Polybase database definition language. Here is an example of collection definition in Polylang.

This collection has a string field called id, a string field called name, a number field called price, an array field called tags, and an object field called details. The details field has two fields of its own: description and manufacturer, both of which are strings.

The constructor function is called when we want to create a new record in the collection. In this example, the constructor function takes five arguments: id, name, price, description, and manufacturer. The constructor function assigns these values to the corresponding fields in the new record. It also initializes the tags field to an empty array and the details field to an object with description and manufacturer fields.


In addition to defining fields, types, and constructors for collections, Polylang also allows developers to define custom functions within a collection. These functions can be used to perform various tasks, such as modifying field values, adding additional logic and validation, deleting the record, or interacting with other collections and records.

For example, consider the following collection definition with transfer and delete functions:

Here is an example of a function written in Polylang

This collection has a transfer function that takes two arguments: an Account record called to and a number called amount. It first checks if the current account has sufficient funds for the transfer by comparing its balance field to the amount argument. If the balance is less than the amount, an error is thrown. If the balance is sufficient, the function modifies the balance field of the current account by subtracting the amount, and it modifies the balance field of the to account by adding the amount.

The delete function is used to delete a record from a collection. When this function is called, it makes a call to the built-in selfdestruct function, which deletes the record from the collection.


In Polybase, you can use indexes to specify fields that you want to be able to query and sort by. Without indexes, you cannot filter or sort records in a collection.

To define an index in Polylang, you can use the @index decorator. For example:

You can use @index decorator to define an index in Polylang.

This collection has an index on the name field. You can now use the name field in queries and sort clauses.

You can also define compound indexes by specifying multiple fields in the @index decorator. For example:

Compound indexes in polylang.

This collection has a compound index on the name and age fields. You can now use both fields together in queries and sort clauses.


In conclusion, Polylang is a powerful and expressive language for defining collections and functions in Polybase. With Polylang, you can declaratively define the schemas and behavior of your collections, and use functions to modify field values, perform calculations, delete records, and interact with other collections and records. You can also use indexes to specify fields that you want to be able to query and sort by.

I hope this article has helped you learn more about Polylang and how it can be used in Polybase. If you have any further questions or would like to learn more, don’t hesitate to ask on our Discord server or explore the Polybase documentation.