juliancoleman / orchestra

A dependency-free, pure-function String manipulation library
MIT License
1 stars 0 forks source link

Add new #query() method to lib #10

Open juliancoleman opened 5 years ago

juliancoleman commented 5 years ago

Or come up with a better name. It should be able to compile and parse query strings. The compiler will construct a string with the given properties. I imagine this will be recursive. The parser will convert the string back into the original query object.

For example,

{
  columns: ["first_name", "last_name", "email_address"],
  filters: ["+last_name", ["email_address", "@gmail.com"]], // sorts the db query by `first_name` ascending `WHERE table.email_address = '% || ? ||%'`,
  paginate: true,
}

should compile into

columns[]=first_name&columns[]=last_name&columns[]=email_address&filters[0]=+last_name&filters[1][0]=email_address&filters[1][1]=@gmail.com&paginate=true

and should parse back into the original object.

juliancoleman commented 5 years ago

Note: escape where needed. Most API tools, such as Paw or Postman, will automatically escape query strings, but we can't assume they will always properly escape