jeremydaly / data-api-client

A "DocumentClient" for the Amazon Aurora Serverless Data API
MIT License
446 stars 63 forks source link

Improve Developer Query Experience #48

Open MarkHerhold opened 4 years ago

MarkHerhold commented 4 years ago

I think it would be wonderful if v2 of this lib could use sql-template-strings because it offers a really nice dev experience with clean syntax.

// book and author are variables in scope
await query(SQL`SELECT author FROM books WHERE name = ${book} AND author = ${author}`)

I'd like to hear your thoughts on this enhancement request, @jeremydaly . Thank you for the wonderful lib!

MarkHerhold commented 4 years ago

I should also add that sqorn also has a great syntax. Either lib would be a great improvement.

ffxsam commented 4 years ago

FWIW, I'm just using knex to build queries, and then piping those strings into the data API.

MarkHerhold commented 4 years ago

@ffxsam ah, thanks!

ffxsam commented 4 years ago

@MarkHerhold Sure!

const query = knex('users').where(
  'id',
  '5654611c-1b8b-494c-a20e-d6307d510fb4',
);
const data = await dataApi.query(query.toQuery());

BTW, I noticed .query() doesn't just return an array of objects. It returns { records: [/* actual rows */] }. @jeremydaly just a heads-up, as this is different than what the README states.