I’m still new to Exposed and was wondering how I c...
# exposed
m
I’m still new to Exposed and was wondering how I could use the DSL implementation without any DOA tables. In an application I am building we have books which has relations to series and publishers which is a one to many. The struggle that I find is that when I try to have a link between Authors which is a many to many relation. All the documentation states to use DOA tables which I don’t want to convert to. Is there a way to just use the DSL implementation?
l
Yes, we don't use DOA in our app.
s
It's quite common to use Exposed with just the DSL. I've been doing that at my previous job, and many previous clients. If you can share an example of your tables, and desired query then I might be able to help out in more detail ☺️
m
Copy code
object AuthorsTable : Table("authors") {
    val id = integer("id").autoIncrement()
    val firstName = varchar("firstName", 128)
    val lastName = varchar("lastName", 128)

    override val primaryKey = PrimaryKey(id)
}

fun ResultRow.toAuthorsDTO(): AuthorsDTO {
    return this.let {
        AuthorsDTO(
            id = it[AuthorsTable.id],
            firstName = it[AuthorsTable.firstName],
            lastName = it[AuthorsTable.lastName],
        )
    }
}

object BooksTable : Table("books") {
    val id = integer("id").autoIncrement()
    val title = varchar("title", 128)
    val publishedDate = date("published_date")
    val series = reference("series", SeriesTable.id)
    val publishers = reference("publishers", PublishersTable.id)

    override val primaryKey = PrimaryKey(id)
}

fun ResultRow.toBooksDTO(): BooksDTO {
    return this.let {
        BooksDTO(
            id = it[BooksTable.id],
            title = it[BooksTable.title],
            publishedDate = it[BooksTable.publishedDate],
            authors = TODO(),
            series = TODO(),
            publishers = TODO()
//            authors = it[BooksTable.authors],
//            series = it[BooksTable.series],
//            publishers = it[BooksTable.publishers],
        )
    }
}

object BooksAuthorsTable: Table("books_authors") {
    val id = integer("id").autoIncrement()
    val bookId = reference("book_id", BooksTable.id, onDelete = ReferenceOption.CASCADE)
    val authorId = reference("author_id", AuthorsTable.id, onDelete = ReferenceOption.CASCADE)

    override val primaryKey: PrimaryKey = PrimaryKey(id)
}
m
I totally forgot to add the querries. I want to be able to have CRUD books which has the linkage to other tables. As an end result I want to be able to add a book with series, publishers and authors already existing. Besides that also fetching, updating and deleting