Skip to content

Types

Data types are the categories of data values that can be stored, processed, and retrieved by a programming language. Common data types include numbers (integers, floats, complex), characters (single characters, strings), booleans (true/false), dates, times, and null/undefined values. Additionally, derived data types include arrays (ordered collections) and objects (unordered collections of named values). Each data type has its own set of properties and operations that can be performed on it, such as comparison, arithmetic, and casting. Understanding data types is crucial for writing effective and efficient code that accurately processes and manipulates data.

Having a universal type system allows for each integration between various services across technology stacks, programming language, and system boundaries.

Standard Data Types

All the blocks in kis.ai, support standard data types and these form the foundation for strong type-safe way to integrate services.

Data TypeDescriptionPostgresGraphQLJSON
klidkis.ai ulid, used as identity field for users, delegates, bots and agentschar(27)IDstring
ulidulid is better suited than guid as its lexicographically sortablechar(26)IDstring
byte8 bits of data, typical used for storing flag informationbyteByteinteger
bytesarray of bytes, useful for binary databytea[Byte]array(integers)
int32-bit intintIntinteger
bigint64-bit intbigintIntinteger
doubledouble precision floating point numberfloat8Floatdouble
booleanboolean values, true or falsebooleanBooleanboolean
datedatedateStringstring
datetimetimestamp without timezone, no timezone calculations performedintIntstring
timestamptimestamp with timezone informationtimestamptzStringstring
stringvariable length characters, useful for storing text information. This is the default datatypetextStringstring
objectan object with properties, typically used to store embeddablesjsonbobject
array(<type>)array of values of other primitive data types or objectsjsonbarray
enumnative enum datatypeintIntstring

Custom Data Types

In some situations, new types need to be created. Data API allows creation of custom data types. Each custom data types will have encode and decode functions for encoding data before storing in database and decoding after reading from the database.

Here is an example where a binary data is encoded into base64 and being stored as text in the database.

Encoding and Decoding by Database

/data/datastores/alm/types-db.yaml
1
#custom image data type encode/decode done by database
2
types:
3
- name: image
4
database: postgres
5
dbtype: text # need to give database specific type, here in this example for postgres
6
type: db # means the encoding and decoding will be done by database. The other option is app, where app takes care of encoding and decoding.
7
encode: encode({{data}}, 'base64') # converts binary byte array into base64 string
8
decode: decode({{field}}, 'base64') # converts base64 text into binary byte array

Encoding and Decoding by Application

/data/datastores/alm/types-app.yaml
1
#custom image data type encode/decode done by Data API service
2
types:
3
- name: image
4
database: postgres
5
dbtype: text # need to give database specific type, here in this example for postgres
6
type: app # means the encoding and decoding will be done by app.
7
encode: base64 # converts binary byte array into base64 string
8
decode: base64 # converts base64 text into binary byte array

Symbols

In more advanced use cases, some User-Defined Functions (UDFs) or functions provided by database extensions can be exposed to be used by developers. Symbols are added to datastore, to enable their usage in the database. Symbols are database specific, like types.

/data/datastores/alm/symbols.yaml
1
symbols:
2
postgres:
3
system:
4
count: count({{field}})
5
min: min({{field}})
6
max: max({{field}})
7
udf:
8
tax: tax({{1}}, {{2}})
9
vars:
10
- customername

User-Defined Functions

Database specific User-Defined Functions can be added to a datastore. This are advanced features, and should be avoided as much as possible.

/data/datastores/alm/functions.yaml
1
functions:
2
- name: tax
3
database: postgres
4
definition: |
5
CREATE OR REPLACE FUNCTION tax( amount NUMERIC, tax NUMERIC)
6
RETURNS NUMERIC AS $$
7
BEGIN
8
RETURN amount + (amount * tax);
9
END; $$
10
LANGUAGE plpgsql;