timescaledb-parallel-copy icon indicating copy to clipboard operation
timescaledb-parallel-copy copied to clipboard

Allowing use as a go module (feature request)

Open bharathcs opened this issue 2 years ago • 0 comments

First off, great work with this package, its been very useful!

However, this package could be more useful if it could support its use as a golang package rather than only as a command line program. While using stdin / stdout redirection instead of reading from a file is already useful, developers could make more functional programs if they could send a suitable reader to take the data from.

For example, people who routinely have to upload bulk data, with a script or otherwise, will be able to take better advantage of this package by writing their own go program.

Here is the rough idea I have:

  • the key exposed function Run should take in an io.Reader and functional options that set the arguments (otherwise handled by CLI flags)
  • the main package won't be used in imports, so the key functions have to be moved out to an exposed timescaledb-parallel-copy package
  • the main package must still be able to work with command line args, and calling on the exposed package, so that current functionality continues. This should be as simple as .Run(scanner, WithCliFlags(/* struct containing flag result */)

Here's a possible example of another developer using this this package after such functionality has been achieved:

package main

import (
	"io"

	copy "github.com/timescale/timescaledb-parallel-copy"
)

func main() {
	c := copy.SetConnection( /* ... */ ).SetTableName( /* ... */ ).SetWorkers( /* ... */ )
	r, w := io.Pipe()
	go func() {
		writeCsvData(w)
		w.Close()
	}()

	err := c.Run(r, copy.WithConnection( /* ... */ ), copy.SetTableName( /* ... */ ), copy.SetWorkers(5), /* ... */ )
	if err != nil {
		panic(err)
	}
}

I encountered this use case personally, and I already did the upgrades to make it happen, and I'd be happy to clean up my work and make it in a proper PR if the devs at TimescaleDB are open to this feature request.

bharathcs avatar Mar 17 '22 10:03 bharathcs