@ovotech/potygen-cli
TypeScript icon, indicating that this package has built-in type declarations

0.10.11 • Public • Published

Potygen CLI (Postgres typescript generator)

Command line tool for generating types for potygen

Installation

yarn add --dev @ovotech/potygen-cli

Usage

If we had sql string templates like this:

examples/simple.ts

import { sql } from '@ovotech/potygen';
import { Client } from 'pg';

const db = new Client(process.env.POSTGRES_CONNECTION);

async function main() {
  await db.connect();
  const productsSql = sql`SELECT product FROM orders WHERE region = $region`;
  const data = await productsSql(db, { region: 'Sofia' });

  console.log(data);

  await db.end();
}

main();

We could then run the potygen cli tool to generate types for them

yarn potygen -n postgres://localhost:5432/postgres examples/simple.ts

After that you can import the types and use them, which will type both parameters of the query as well as the results

examples/simple-typed.ts

import { sql } from '@ovotech/potygen';
import { Client } from 'pg';
import { ProductsSqlQuery } from './simple-typed.queries';

const db = new Client(process.env.POSTGRES_CONNECTION);

async function main() {
  await db.connect();
  const productsSql = sql<ProductsSqlQuery>`SELECT product FROM orders WHERE region = $region`;
  const data = await productsSql(db, { region: 'Sofia' });

  console.log(data);

  await db.end();
}

main();

Config

You can define potygen.config.json or provide a json file to the --config property. The full list of parameters are:

Usage: potygen [options]

Convert postgres query files into typescript types

Options:
  -V, --version                  output the version number
  -c, --config <config>          A configuration file to load (default: "potygen.config.json")
  -f, --files <files>            A glob pattern to search files by (default: "**/*.sql")
  -w, --watch                    Watch for file changes and update live
  -v, --verbose                  Show verbose logs
  -a, --cache-file <cacheFile>   Cache file to be used by --cache (default: ".cache/potygen.cache")
  -r, --cache-clear              Clear the cache
  -e, --cache                    Cache which files have been processed, defaults .cache/potygen.cache
  -s, --silent                   Only show error logs
  -p, --typePrefix <typePrefix>  Prefix generated types
  -l, --preload                  Load all data at once. Slower start but faster for a lot of files
  -r, --root <root>              Set the root directory (default: ~/Projects/potygen/packages/cli)
  -n, --connection <connection>  Connection to the postgres database. URI (default: "postgres://localhost:5432/db")
  -t, --template <template>      A template of the path, where to generate the typescript type files. The parameters are the response from node's path.parse function (default:
                                 "{{dir}}/{{name}}.queries.ts")
  -h, --help                     display help for command

Dependents (0)

Package Sidebar

Install

npm i @ovotech/potygen-cli

Weekly Downloads

2,546

Version

0.10.11

License

Apache-2.0

Unpacked Size

64.8 kB

Total Files

25

Last publish

Collaborators

  • ovotech-sg
  • arturpolianskyi
  • ovotech-qs
  • stefan-dospinescu-ovo
  • ovox
  • tomshawovo
  • george.anthony
  • sean-kantan
  • potsec
  • rosario-ovo
  • andrew-brook-rad
  • kantan_m_rutter
  • callumdenby
  • caolan.derry
  • apjm
  • kingfruit85
  • ovoenergyapps
  • tigranargit
  • chris-cooney-ovo
  • maxandre.zils
  • dela_kaluza
  • radinadineva
  • iain.rawson.ovo
  • cohen990-ovo
  • cp-ui-tooling
  • ovo-bit-tech
  • klaudia.marzec
  • mykola.p
  • jgok
  • luis.gashi
  • radhika-bijibilla
  • rmcnovo
  • fahedarshad
  • ovo_steve
  • askomaro
  • rparkhomchuk
  • engagement-insights
  • ievgen-paliichuk-ovo
  • gjain-npm-ovo
  • mwz
  • mtardugno-ovo
  • stewart-kantan
  • dangrebovic
  • myovo-self-serve-service-account
  • morris27sky
  • peterh-ovo
  • zoejm
  • bizval-bot
  • tom.sherman
  • vcheban-ovo
  • vzahakailo
  • data.discovery.ovo
  • mikitadzianisevich
  • nick-ovox
  • ronald.nsabiyera
  • mbrignall
  • nick.long
  • aga-ovo
  • pkari
  • ovotech-smart-thermostat
  • ovo.trading.tech
  • jennyunchan
  • qe-team
  • esra.kaya
  • npmpwoo
  • oliwia-lakatosz
  • lenardprattovo
  • asellick
  • accrecovo
  • csillabarna
  • petro.pavlenko
  • andy-heywood-ovo
  • a.calderwood
  • dvoroniuc-ovo
  • laurawady
  • vmary
  • franciscodiasovo
  • vukovo
  • prtn-ovo
  • mattgrayovo
  • edpatrick-ovo
  • per.linnett
  • vcobzaru
  • jagreenwood1
  • retail-payg-tech
  • madalinadulhac
  • n-jeremic-npm
  • k-fernandez
  • phala.kantan
  • ovo-aarongibbison
  • tom.harrison-ovo
  • michal-at-kantan
  • cristinapetrov
  • ovo-josh
  • anthony_tonev
  • scdf
  • rise-team
  • jackbott-ovo
  • kuwotu
  • darren_thomas_ovo
  • samrumley88
  • bisongee
  • ohs-aurora
  • t.vytrykush
  • chris.clarkzzz
  • alan_smith_ovo
  • kgould
  • arpad.fesis.ovo
  • ovo-james
  • lewright
  • veselin.stamenov
  • philip.fol.ovo
  • cifdso
  • xenjke
  • thomas.bingovo
  • shonnguen
  • ovo-venkat
  • dyl349
  • michaelwheeler
  • pablomuro-ovotech
  • mike-gregory-kaluza
  • zyurii
  • azaspenko
  • melcbuckov
  • vslepkan
  • mladjan-perceptive
  • props
  • jthomasovo
  • tarlingovo
  • mikethorpe-ovo
  • renimihaylova
  • jeffer_ovo
  • jlucktay
  • anglox
  • manoj-ovo
  • bare7aovo
  • brettburman-code
  • volodymyr-viniar
  • sambs
  • ds-ovo
  • maieutiquer
  • shnist
  • ovonicktunstall
  • stevendiplock
  • ezio-intravaia-ovo
  • zolegovo
  • ryan.lee1
  • willshawmedia
  • andbrss
  • vitalii_khudenko
  • bookings-team
  • benaston13
  • jcholewa
  • gabriel.hulubei
  • ovo-markswaffer
  • kseniya.belevich
  • ion.nasu
  • timothy.ajisafe
  • mosman128
  • fraserhamiltonovo
  • lilbyteltd
  • irina.dimitriu
  • militsa_tsvetkova
  • pkoretsovo
  • ylukomskyi-corgi
  • andrixb
  • nathanmarshovo
  • ranarajput123
  • jadamiec-ovo
  • crektek
  • miksg
  • a1nsley
  • gracyde
  • saamiyayousuf
  • veljko.popovic
  • cenkovic_ovo
  • mbartish_ovo
  • maxatko
  • samrushton
  • mihaidavidovo
  • emmadavids
  • mattbarkway
  • dhasovo
  • willcorrigan-ovo
  • edvinas.ovo
  • zoelanham
  • tokict2
  • owen1111
  • rafal-mac
  • ovotarasrusyniak
  • vasileovo
  • lyuboslav.lyubenov.ovo
  • mfiialko-ovo
  • lucafrancesc
  • charlieinshaw
  • ovotech-air-source-heat-pump
  • edandrewovo
  • s.slotskyi-ovo
  • aleksandyr
  • ivan.mihov-ovo
  • chris.brookes
  • iuna4e
  • maricel-ovo
  • brianbroughton
  • mark-b-ovo
  • mikecsmith-ovo
  • olliebatchelor
  • jamieovo
  • darinakulishovo
  • rsh-ovo
  • dlaird-ovo
  • ovo.backstage.admins
  • dtheasby-kaluza
  • catalin.andrei
  • warren-ovo
  • ovo_nunoazevedo
  • gideoncaspi
  • amymctigue
  • iulian.alexandru-ovo
  • richardday-ovo
  • c-bojan
  • iskren.ovo
  • richard.ashworth7
  • yordan-petkov-ovo
  • olesiapaslavska
  • richard-ovo
  • jake-davisovo
  • afdecastro879
  • ovo-home
  • chrisstephens-ovo
  • simon_p_lewis
  • andre-lino-ost
  • liming.cheung
  • sbetts-ovo
  • conor.mather.ovo
  • jonny-ovo
  • ben-harris-ovo
  • wiggly-ovo
  • deepak-moh-ovo
  • martinyanevovo
  • alex-verbovskiy-ovo
  • chrisarmourovo
  • mrutter_ovo
  • vitalii-mohola-1988
  • j_kapella
  • aliovo
  • viktorborys-ovo
  • jaredph_ovo
  • ewanhardingham-ovo
  • ignaciodomenech
  • drydenwilliams_
  • nevenablagoeva
  • trupti.lonkar
  • ajinkya.badgujar
  • domantas.miliauskas
  • giedrestu
  • joetkoczovo
  • alexandru.vicol1
  • marandries
  • jaroslavasovo
  • ovo-minsma
  • adamblackwater
  • aug24-ovo