relate icon indicating copy to clipboard operation
relate copied to clipboard

Provide more examples in docs

Open bastaware opened this issue 5 years ago • 1 comments

Going through the different db abstractions for Scala I came across Relate. Looks good, but is there a reason the examples are so simple? Please show how to handle joins.

bastaware avatar Feb 12 '20 07:02 bastaware

Queries with joins should work the same as queries without them. For example,

sql"SELECT users.name, emails.email FROM users INNER JOIN emails ON users.id == emails.user_id".asMap { row =>
  row.long("name") -> row.string("email")
}

should give you a Map of user names to emails.

The query itself can be any valid SQL query. From the docs:

Relate is a lightweight database access layer for Scala that simplifies database interaction while leaving complete control over the actual SQL query.

There's more documentation on the docs page on how to write queries with parameters, query composition, and data retrieval. For general documentation on writing queries with joins, please refer to SQL documentation.

Please let us know if you run into any issues using any valid queries :)

SrodriguezO avatar Feb 12 '20 20:02 SrodriguezO