Re: [go-nuts] Using database/sql in a web application

2018-01-10 Thread Manlio Perillo
Il giorno venerdì 5 gennaio 2018 18:09:40 UTC+1, Chris Hopkins ha scritto: > > Why not use an interface? > type TableSaver func (db *DB) > or > type TableSaver func (tx *Tx) // depending on your needs > > > Allowing you to: > func (t *Table) SaveTable (...) {} > > > Which in your example if you

Re: [go-nuts] Using database/sql in a web application

2018-01-05 Thread Chris Hopkins
Why not use an interface? type TableSaver func (db *DB) or type TableSaver func (tx *Tx) // depending on your needs Allowing you to: func (t *Table) SaveTable (...) {} Which in your example if you wanted use a different SaveTable implementation for OtherTable you could. Otherwise it would

Re: [go-nuts] Using database/sql in a web application

2018-01-05 Thread Manlio Perillo
Il giorno venerdì 5 gennaio 2018 16:57:04 UTC+1, Ayan George ha scritto: > > > > On 01/05/2018 10:16 AM, Manlio Perillo wrote: > > Recently I have developed a few web applications in Go, using a > > PostgreSQL database, but I have yet understand the best way to use > > the database/sql package.

Re: [go-nuts] Using database/sql in a web application

2018-01-05 Thread Ayan George
On 01/05/2018 10:16 AM, Manlio Perillo wrote: > Recently I have developed a few web applications in Go, using a > PostgreSQL database, but I have yet understand the best way to use > the database/sql package. > I don't know how you're serving web pages but I typically use net/http. This also

[go-nuts] Using database/sql in a web application

2018-01-05 Thread Manlio Perillo
Recently I have developed a few web applications in Go, using a PostgreSQL database, but I have yet understand the best way to use the database/sql package. The simplest method seems to start a transaction in the HTTP handler and pass a *sql.Tx value to all the functions that need to access