pupa-tag
v1.0.0
Published
A tag using by the pupa
Downloads
27
Readme
pupa-tag
Usage
/**repare of using this
* ```sh
* yarn add pupa-tag
* ```
*/
import appropriateName from 'pupa-tag';
// e.g.) import sql from 'pupa-tag';
or
<script src="https://unpkg.com/pupa-tag/pupa-tag.js"></script>
<script>
// Can use the `pupaTag` here.
</script>
Example by TypeScript
In the below, definition the selectById
which is expected passing into arguments {id: number}
.
const selectById = sql<{id: number}>`select * from foo where id = {id}`;
console.log(selectById({id: 123}));
// 'select * from foo where id = 123'
You could divide into serveral contents. For example in the below, sentence after the where
is allocated as the whereBy
variable.
const whereBy = pupaTag<{id: number}>`where id = {id}`;
const selectById = pupaTag<{id: number}>`select * from foo ${whereBy}`;
console.log(selectById({id: 123}));
// 'select * from foo where id = 123'
And also the whereBy
is function thus you can use its result as string
. (({id: number}) => string
).
const whereBy = pupaTag<{id: number}>`where id = {id}`;
const selectById = pupaTag<{id: number}>`select * from foo ${whereBy({
id: 123,
})}`;
console.log(selectById());
// 'select * from foo where id = 123'