Exposed 1.0.0-rc-3 Help

Frequently Asked Questions

What is Exposed?

Exposed is a Kotlin-based SQL library that combines a DSL for building queries, Object-Relational Mapping (ORM) features, and a DAO framework for managing entities. It allows developers to write type-safe queries and interact with a database using Kotlin's expressive and concise syntax. For a more detailed description, see the about section.

Can I use multiple database connections?

Yes. You can use multiple database connections by passing the database reference to the transaction() function. For more details and examples, see Working with multiple databases.

What data types are supported?

Exposed supports a variety of data types, including basic data types, date and time, arrays, binary data, enumeration, and JSON and JSONB. You can also extend and create new custom data types to fit your specific needs.

How can I create a custom column type?

You can implement a custom column type using the IColumnType interface and registerColumn() to register it to a table. For more information, refer to the custom data types documentation.

Is it possible to generate SQL without a database connection?

No, Exposed requires a database connection to generate SQL. SQL generation depends on the database dialect and transaction context, both of which are determined by the active database connection. Since Exposed adapts queries dynamically based on the underlying database, a connection is necessary even if the query is never executed.

How do I get a plain SQL query which will be executed?

You can use Statement.prepareSQL(), and potentially buildStatement(). For more details, see Building SQL Statements.

Is it possible to update a field relative to current field value?

Yes. You can achieve this by using the .update() function with the desired Expression or setting the value of the field directly. For more information, see how to update a record.

How do I prepare query like SELECT * FROM table WHERE (x,y) IN ((1, 2), (3, 4), (5, 6))?

Exposed provides the inList() function that works with pairs of columns. For more details, see Using inList with Pairs or Triples.

How can I convert a DSL query result to a DAO entity?

To convert the result of a DSL query into an entity, you can use the DAO's wrapRow() function, which allows you to wrap a row into a DAO entity.

How can I implement nested queries?

You can implement nested queries by using the alias() function to create subqueries and join them with other tables or queries. For more information, see the alias documentation.

Is it possible to create tables with cyclic (circular) reference?

Yes, it is. To define such tables, you can use the reference() or optReference() functions to establish foreign key relationships between tables. For more information, see the Relationships topic.

How can I use a savepoint?

You can set a savepoint through the ExposedConnection.setSavepoint() method within a transaction. For more details, see Using savepoints.

Is it possible to use a low-level JDBC connection directly with Exposed?

Yes, by accessing the raw connection wrapped by a transaction block's connection property:

transaction { val lowLevelCx = connection.connection as java.sql.Connection val stmt = lowLevelCx.prepareStatement("INSERT INTO TEST_TABLE (AMOUNT) VALUES (?)") stmt.setInt(1, 99) stmt.addBatch() stmt.setInt(1, 100) stmt.addBatch() stmt.executeBatch() val query = lowLevelCx.createStatement() val result = query.executeQuery("SELECT COUNT(*) FROM TEST_TABLE") result.next() val count = result.getInt(1) println(count) // 2 }

How can I add another type of database?

To add another type of database that is not currently supported by Exposed, implement the DatabaseDialect interface and register it with Database.registerDialect().

If the implementation adds a lot of value, consider contributing it to Exposed.

Last modified: 27 November 2025