Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upBetter documentation for tagged template and sql() usage #4
Labels
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I thought I had finished the docs for
sql()usage and template strings, but I see they're incomplete.I think at the very start it would be great with a completely basic description of how the tagged template sql fn are to be used.
Any raw value inside a template string will be replaced with
$nand sent as a parameter to postgresql inferring the correct type. If a value needs to be passed directly in the querysql(value)is to be used which ensures escaping happens properly. It also has overloads to expand the most common scenarios in the correct context.Eg:
sql({ a: 'first', b: new Date() })(a, b) values ($1, $2)a = $1, b = $2$1 as a, $2 as band $1 and $2 will be sent as parameters with correct types (string, timestamp) to postgres
As extra help you can supply an array of objects to insert multiple rows in insert context, and also extra arguments to only pluck specific columns from the object. (encouraged for safety).