1.0.0 • Published 5 years ago

pupa-tag v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

pupa-tag

github npm:version typescript ci:status document:typedoc license browserslist code style:prettier

Usage

/**repare of using this
 * ```bash
 * 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'

Edit pupa-tag

1.0.0

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago