示例#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)
}
示例#2
0
文件: main.go 项目: ejholmes/pgstream
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)
	}
}