@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

Readme

Keywords

none

Package Sidebar

Install

npm i @ovotech/potygen-cli

Weekly Downloads

334

Version

0.10.11

License

Apache-2.0

Unpacked Size

64.8 kB

Total Files

25

Last publish

Collaborators

  • raluza
  • david.ovo
  • shashankkushwaha
  • sowruvadhanasekar
  • ovotech-sg
  • jubril
  • trickkaluza
  • arturpolianskyi
  • ovotech-qs
  • mikemchugh
  • kaluzajianzu
  • eloisechilvers
  • stefan-dospinescu-ovo
  • ranjithanataraj
  • ovox
  • tomshawovo
  • alexbkaluza
  • george.anthony
  • sean-kantan
  • potsec
  • kawbot
  • dickensfan
  • rosario-ovo
  • andrew-brook-rad
  • abilash999
  • ruhi-choudhury-kaluza
  • kantan_m_rutter
  • callumdenby
  • daniel-billing-foundations
  • caolan.derry
  • apjm
  • kingfruit85
  • micael-campos
  • ovoenergyapps
  • tigranargit
  • chris-cooney-ovo
  • maxandre.zils
  • dela_kaluza
  • homemoves
  • radinadineva
  • iain.rawson.ovo
  • ovo-oot-bot
  • cohen990-ovo
  • cp-ui-tooling
  • suttonkaluza
  • stuharv-ovo
  • orion-bot
  • ovo-bit-tech
  • klaudia.marzec
  • mykola.p
  • jgok
  • mwidurek
  • sir_hiss
  • g-tibbs
  • weiliangc3
  • luis.gashi
  • chrisfordkaluza
  • tombolinep
  • luke-adams-ovo
  • radhika-bijibilla
  • joepurnell-ovo
  • freddybushboy
  • ellafutkowska
  • rmcnovo
  • kgray-kaluza
  • fahedarshad
  • ovo_steve
  • askomaro
  • rparkhomchuk
  • alexvicolovo
  • ape-team
  • engagement-insights
  • dominicboston-kaluza
  • ievgen-paliichuk-ovo
  • oep-accounts-bot
  • mars-rover
  • gjain-npm-ovo
  • mwz
  • gordonmartin
  • jamie-eb
  • jcdclark
  • mtardugno-ovo
  • stewart-kantan
  • dangrebovic
  • myovo-self-serve-service-account
  • morris27sky
  • peterh-ovo
  • zoejm
  • bizval-bot
  • tom.sherman
  • vcheban-ovo
  • gregshielkaluza
  • anuprasanna
  • vzahakailo
  • data.discovery.ovo
  • mikitadzianisevich
  • sallyemerson
  • nick-ovox
  • ronald.nsabiyera
  • mbrignall
  • nick.long
  • ipa-bot
  • kaluza-billing-coordinator
  • aga-ovo
  • laranjoeduardo
  • scott-thomson239
  • paceteamkaluza
  • pkari
  • filoseovo
  • anthonykaluza
  • simonmclean-ovo
  • ovotech-smart-thermostat
  • trading-and-dispatch
  • jonnyleakaluza
  • ovo.trading.tech
  • jennyunchan
  • qe-team
  • esra.kaya
  • kaluza-lc
  • npmpwoo
  • iovana.pavlovici
  • oliwia-lakatosz
  • samwest
  • lenardprattovo
  • asellick
  • tom.mottram.kaluza
  • kristenkelly_kaluza
  • ponchosb
  • accrecovo
  • marina-ovo
  • csillabarna
  • lebaptiste
  • samcooper720x
  • retrojetpacks
  • petro.pavlenko
  • jamesbaum
  • benvaughanjones
  • andy-heywood-ovo
  • laurierw
  • a.calderwood
  • dvoroniuc-ovo
  • laurawady
  • rafolo78
  • vmary
  • franciscodiasovo
  • cwkaluza
  • david.chellapah.ovo
  • vukovo
  • m_heald
  • prtn-ovo
  • andrewjtn
  • kaluza-rnr
  • eoinkelly
  • krjjm
  • kimnil
  • mattgrayovo
  • edpatrick-ovo
  • per.linnett
  • dwfullerton
  • vcobzaru
  • jagreenwood1
  • retail-payg-tech
  • madalinadulhac
  • vasil.dininski
  • n-jeremic-npm
  • k-fernandez
  • phala.kantan
  • carolinelywood
  • ovo-aarongibbison
  • tom.harrison-ovo
  • danmaly
  • jensraaby-ovo
  • jameswelshkaluza
  • michal-at-kantan
  • cristinapetrov
  • ovo-josh
  • zach-smith-kza
  • anthony_tonev
  • scdf
  • nevenablagoeva
  • rise-team
  • jackbott-ovo
  • kuwotu
  • rohith-kaluza
  • tudor.harries-kaluza
  • mike.walters
  • darren_thomas_ovo
  • lughino
  • samrumley88
  • bisongee
  • ovotech-identity
  • kim-wysocki-ovo
  • jchoskins
  • jamesnoble1
  • rui-alves-kaluza
  • ovo-dc
  • ohs-aurora
  • kaluza-devex
  • t.vytrykush
  • kelveden
  • chris.clarkzzz
  • alan_smith_ovo
  • metering-reads-health-bot
  • kgould
  • lestes
  • arpad.fesis.ovo
  • ovo-james
  • friendigo
  • lewright
  • kathryn.allan
  • adamblance-kaluza
  • veselin.stamenov
  • jadedarko
  • thomasgdane
  • graemef
  • r0bturner
  • philip.fol.ovo
  • liam-chambers
  • cifdso
  • sulgee.kim
  • xenjke
  • thomas.bingovo
  • sophiar27
  • irena3888
  • mableyip
  • shonnguen
  • ovo-venkat
  • edgranau
  • ik1004kaluza
  • andreiracasan-ovo
  • dyl349
  • serena-ahah
  • michaelwheeler
  • marcuskielly
  • pablomuro-ovotech
  • kaluzian
  • mike-gregory-kaluza
  • zyurii
  • raraujo-ovo
  • rafael_kaluza
  • delaluza
  • azaspenko
  • will.crick
  • melcbuckov
  • kupxc
  • vslepkan
  • adam-mcdevitt
  • pedro.caldeira
  • mladjan-perceptive
  • props
  • jthomasovo
  • mesh00
  • tarlingovo
  • davekaluza
  • mikethorpe-ovo
  • oeptariffs
  • jrdavenport
  • miguel-catarino
  • simon.petty
  • amolrindhe
  • phil-pinkowski
  • renimihaylova
  • rob.desbois
  • richard-mounter
  • jeffer_ovo
  • jlucktay
  • rekaelek-ovo
  • anglox
  • harrisonbaxter
  • manoj-ovo
  • bare7aovo
  • lewisdick-ovo
  • mikaelgiacominikaluza
  • brettburman-code
  • olikaluza
  • volodymyr-viniar
  • sambs
  • ds-ovo
  • maieutiquer
  • shnist
  • ovonicktunstall
  • achagan_kaluza
  • georgexcollins
  • stevendiplock
  • jac-hughes
  • ezio-intravaia-ovo
  • zolegovo
  • ryan.lee1
  • willshawmedia
  • andbrss
  • vitalii_khudenko
  • bookings-team
  • benaston13
  • jcholewa
  • joewhittles
  • jnysevilla
  • gabriel.hulubei
  • pallait
  • ovo-markswaffer
  • kseniya.belevich
  • mnolan.kaluza
  • mike.holloway
  • chintogtokh
  • ion.nasu
  • rachelknightkaluza
  • bphenriqueskaluza
  • wjbenfold
  • alicia.bowers
  • timothy.ajisafe
  • puzzledbytheweb
  • marknreynolds
  • ramanan-kaluza
  • mosman128
  • benjamin.golding
  • tashacallow
  • thomas.finch
  • fraserhamiltonovo
  • lilbyteltd
  • irina.dimitriu
  • markwood23
  • militsa_tsvetkova
  • sujitkumar.shil
  • bohdan-kozerema
  • pkoretsovo
  • ylukomskyi-corgi
  • paul.gallagher
  • andrixb
  • nathanmarshovo
  • ranarajput123
  • khadra.ismail2
  • jadamiec-ovo
  • crektek
  • miksg
  • a1nsley
  • gracyde
  • jonnycundall
  • saamiyayousuf
  • veljko.popovic
  • iharea-ovo
  • harry.faulkner
  • cenkovic_ovo
  • mbartish_ovo
  • ekeith-kaluza
  • maxatko
  • vipul_vk
  • sophiesillmanovo
  • samrushton
  • mihaidavidovo
  • emmadavids
  • mattbarkway
  • dhasovo
  • willcorrigan-ovo
  • andrewinci-dev
  • borislav-draganov-ovo
  • pedro.costa.kaluza
  • edvinas.ovo
  • adam.vile
  • zoelanham
  • kaluza-tariffs-and-charging
  • tokict2
  • owen1111
  • caal-bot
  • rafal-mac
  • ovotarasrusyniak
  • vasileovo
  • lyuboslav.lyubenov.ovo
  • kaluza-typescript-caretakers-bot
  • mfiialko-ovo
  • lucafrancesc
  • charlieinshaw
  • consumption
  • ovotech-air-source-heat-pump
  • mishabruml
  • edandrewovo
  • s.slotskyi-ovo
  • aleksandyr
  • ivan.mihov-ovo
  • chris.brookes
  • fulvio.ovo
  • iuna4e
  • tc-kaluza
  • maricel-ovo
  • brianbroughton
  • mark-b-ovo
  • andymay44
  • gordok
  • mikecsmith-ovo
  • olliebatchelor
  • luke.parsons.kaluza
  • jamieovo
  • djmelonz
  • tommaso.bruno
  • darinakulishovo
  • robert-g-j
  • gabrielngovo
  • rsh-ovo
  • garylaikaluza
  • dlaird-ovo
  • ovo.backstage.admins
  • dtheasby-kaluza
  • hentielouw
  • nish1406
  • jacktreble
  • bilaal-kaluza
  • catalin.andrei
  • warren-ovo
  • kelemensanyi
  • dana-kaluza
  • brooke-m
  • chen-kaluza
  • ndoolan360
  • jamesg-kaluza
  • kaluza-serverless-caretakers
  • ovo_nunoazevedo
  • sourabhkhot
  • pauleuh
  • fiona.young
  • felipeneuhauss
  • gideoncaspi
  • tmpalmer
  • troper
  • nayomi_payments_aus
  • amymctigue
  • johnmarshallkaluza
  • iulian.alexandru-ovo
  • kaluza-statements-bot
  • richardday-ovo
  • katyish
  • c-bojan
  • iskren.ovo
  • richard.ashworth7
  • yordan-petkov-ovo
  • reyadsibleycoombe
  • stvmachine-kaluza
  • csherwin
  • renukasampathkumar
  • olesiapaslavska
  • migration-tooling-bot
  • richard-ovo
  • olenak
  • utamkumar1012
  • davidnhamilton
  • kaluza-energy-charging
  • jake-davisovo
  • afdecastro879
  • ovo-home
  • ren-binden-kaluza
  • ashikaanandraj