@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

313

Version

0.10.11

License

Apache-2.0

Unpacked Size

64.8 kB

Total Files

25

Last publish

Collaborators

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