documentation-website/Writerside/topics/Frequently-Asked-Questions.md
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.
Yes. You can use multiple database connections by passing the database reference to the transaction() function.
For more details and examples, see .
Exposed supports a variety of data types, including basic data types, date and time, arrays, binary data, enumeration, and . You can also extend and create new custom data types to fit your specific needs.
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.
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.
You can use the Statement.prepareSQL()
function, and potentially the buildStatement()
function. For more details, see .
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.
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
.
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.
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.
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 topic.
You can set a savepoint through the ExposedConnection.setSavepoint() method within a transaction. For more details,
see .
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
}
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.