Example #1
0
func newDB() *pgstream.DB {
	db, err := sql.Open("postgres", "postgres://localhost/pgstream?sslmode=disable")
	if err != nil {
		panic(err)
	}
	db.Exec("TRUNCATE TABLE logs")

	return pgstream.Open(db)
}
Example #2
0
func main() {
	db, err := sql.Open("postgres", "postgres://localhost/pgstream?sslmode=disable")
	if err != nil {
		log.Fatal(err)
	}

	rw := pgstream.Open(db).Stream(os.Args[1])

	go func() {
		if _, err := io.Copy(rw, os.Stdin); err != nil {
			log.Fatal(err)
		}

		if err := rw.Close(); err != nil {
			log.Fatal(err)
		}
	}()

	if _, err := io.Copy(os.Stdout, rw); err != nil {
		log.Fatal(err)
	}
}