Binary
Exposed provides support for storing and handling binary data through the ExposedBlob type, which efficiently wraps binary content using InputStream. This approach ensures optimal memory usage when working with large binary objects.
Supported types
The exposed-core module provides the following binary types:
blob()Maps to database
BLOB(or equivalent type depending on the database). Used for storing binary objects of any size.Database-specific mappings:
PostgreSQL: Maps to
byteaSQLServer: Maps to
VARBINARY(MAX)
binary()Maps to database
VARBINARY. Available in two forms:Simple version: Takes only the column name parameter and maps to
VARBINARYwith database-specific default length.val simpleData = binary("simple_data") // simple version without lengthDatabase-specific mappings:
PostgreSQL: Maps to
byteaSQLite: Maps to
BLOBSQLServer, MySQL, and Oracle: Not supported
Length-specified version: Takes both name and length parameters, maps to
VARBINARY(MAX)whereMAXis the specified maximum length. Used for storing fixed-size binary data.val thumbnail = binary("thumbnail", 1024) // length-specified versionDatabase-specific mappings:
PostgreSQL: Maps to
byteaOracle: Maps to
RAWif the provided length is lower than 2000, otherwise not supported.
Basic usage
Here's a simple example of using binary types in a table definition:
PostgreSQL Object Identifiers
PostgreSQL supports storing large objects using Object Identifiers (OIDs):