Skip to content
Talk to our solutions team

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.

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 embeddablesjsonbobjectarray
array(<type>)array of values of other primitive data types or objectsjsonbarrayenum
enumnative enum datatypeintIntstring

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.

/data/datastores/alm/types-db.yaml

#custom image data type encode/decode done by database
types:
- name: image
database: postgres
dbtype: text # need to give database specific type, here in this example for postgres
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.
encode: encode({{data}}, 'base64') # converts binary byte array into base64 string
decode: decode({{field}}, 'base64') # converts base64 text into binary byte array

/data/datastores/alm/types-app.yaml

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

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

symbols:
postgres:
system:
count: count({{field}})
min: min({{field}})
max: max({{field}})
udf:
tax: tax({{1}}, {{2}})
vars:
- customername

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

functions:
- name: tax
database: postgres
definition: |
CREATE OR REPLACE FUNCTION tax( amount NUMERIC, tax NUMERIC)
RETURNS NUMERIC AS $$
BEGIN
RETURN amount + (amount * tax);
END; $$
LANGUAGE plpgsql;