Variant type
The variant data type can store any value. It specifies the data type so the database and application can easily use the data. The FairCom server comes with predefined data types, and in a future release, you will be able to create your own.
The variant data type uses a JSON object to represent any value. This JSON object is called the variant object. You can use a variant object in a JSON document. Any system can read the variant object and be programmed to convert it into a native binary value.
The variant object brings strongly typed values to JSON. It enables you to embed binary values in JSON and specify the data type and encoding of those values, such as images, PDFs, and binary formats like BSON and CBOR.
Example Variant Object
The variant object in the example encodes a GIF image as Base64 in the "value"
property. It also specifies a database should store its binary value in compressed format using the 7z algorithm.
{
"schema": "jsonaction.org/schemas/variantObject",
"value": "R0lGODlhAQABAIAAAAAAAP///yH5BAUAAAEALAAAAAABAAEAAAICRAEAOw==",
"valueEncoding": ["base64"],
"type": "gif",
"storageEncoding": ["7z"],
}
Variant behavior in different FairCom APIs
JSON Action APIs
FairCom's JSON action APIs read and write to variant fields. By default, they read and write JSON to variant fields. They can also use variant objects and settings to read and write binary values to variant fields.
CTDB and ISAM
CTDB and ISAM APIs read and write to a variant field using a C structure representing the variant object, including its length, value, type, and storage encoding.
SQL
SQL reads and writes to a variant field using its binary value. In the future, you can set and return its value using the Variant Object.