Permalink
Browse files

init

  • Loading branch information...
0 parents commit df1f1317967381f224717825633bb31354d8767c @bmizerany bmizerany committed Mar 10, 2012
Showing with 1,333 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +66 −0 README.md
  3. +74 −0 buf.go
  4. +486 −0 conn.go
  5. +247 −0 conn_test.go
  6. +63 −0 encode.go
  7. +78 −0 error.go
  8. +317 −0 types.go
@@ -0,0 +1,2 @@
+.db
+*.test
@@ -0,0 +1,66 @@
+# pq - A pure Go postgres driver for Go's database/sql package
+
+## Install
+
+ go get github.com/bmizerany/pq
+
+## Use
+
+ package main
+
+ import (
+ _ "github.com/bmizerany/pq"
+ "database/sql"
+ )
+
+ func main() {
+ db, err := sql.Open("postgres", "user=pqgotest dbname=pqgotest sslmode=verify-full")
+ // ...
+ }
+
+**Connection String Parameters**
+
+These are a subset of the libpq connection parameters.
+See http://www.postgresql.org/docs/9.0/static/libpq-connect.html
+
+* `dbname` - The name of the database to connect to
+* `user` - The user to sign in as
+* `password` - The user's password
+* `host` - The host to connect to. Values that start with `/` are for unix domain sockets. (default is `localhost`)
+* `port` - The port to bind to. (default is `5432`)
+* `sslmode` - Whether or not to use SSL (default is `require`, this is not the default for libpq)
+ Valid values are:
+ * `disable` - No SSL
+ * `require` - Always SSL (skip verification)
+ * `verify-full` - Always SSL (require verification)
+
+See http://tip.golang.org/pkg/database/sql to learn how to use with `pq` through the `database/sql` package.
+
+## Features
+
+* SSL
+* Handles bad connections for `database/sql`
+* Scan `time.Time` correctly (i.e. `timestamp[tz]`, `time[tz]`, `date`)
+* Scan binary blobs correctly (i.e. `bytea`)
+
+## Future / Things you can help with
+
+* Notifications: `LISTEN`/`NOTIFY`
+* `hstore` sugar (i.e. handling hstore in `rows.Scan`)
+
+## Thank you (alphabetical)
+
+Some of these contributors are from the original library `bmizerany/pq.go` whose
+code still exists in here.
+
+* Blake Gentry (bgentry)
+* Brad Fitzpatrick (bradfitz)
+* Daniel Farina (fdr)
+* Everyone at The Go Team
+* Federico Romero (federomero)
+* Heroku (heroku)
+* Keith Rarick (kr)
+* Mike Lewis (mikelikespie)
+* Ryan Smith (ryandotsmith)
+* Samuel Stauffer (samuel)
+* notedit (notedit)
@@ -0,0 +1,74 @@
+package pq
+
+import (
+ "bytes"
+ "encoding/binary"
+)
+
+type readBuf []byte
+
+func (b *readBuf) int32() (n int) {
+ n = int(binary.BigEndian.Uint32(*b))
+ *b = (*b)[4:]
+ return
+}
+
+func (b *readBuf) int16() (n int) {
+ n = int(binary.BigEndian.Uint16(*b))
+ *b = (*b)[2:]
+ return
+}
+
+var stringTerm = []byte{0}
+
+func (b *readBuf) string() string {
+ i := bytes.Index(*b, stringTerm)
+ if i < 0 {
+ errorf("invalid message format; expected string terminator")
+ }
+ s := (*b)[:i]
+ *b = (*b)[i+1:]
+ return string(s)
+}
+
+func (b *readBuf) next(n int) (v []byte) {
+ v = (*b)[:n]
+ *b = (*b)[n:]
+ return
+}
+
+func (b *readBuf) byte() byte {
+ return b.next(1)[0]
+}
+
+type writeBuf []byte
+
+func newWriteBuf(c byte) *writeBuf {
+ b := make(writeBuf, 5)
+ b[0] = c
+ return &b
+}
+
+func (b *writeBuf) int32(n int) {
+ x := make([]byte, 4)
+ binary.BigEndian.PutUint32(x, uint32(n))
+ *b = append(*b, x...)
+}
+
+func (b *writeBuf) int16(n int) {
+ x := make([]byte, 2)
+ binary.BigEndian.PutUint16(x, uint16(n))
+ *b = append(*b, x...)
+}
+
+func (b *writeBuf) string(s string) {
+ *b = append(*b, (s + "\000")...)
+}
+
+func (b *writeBuf) byte(c byte) {
+ *b = append(*b, c)
+}
+
+func (b *writeBuf) bytes(v []byte) {
+ *b = append(*b, v...)
+}
Oops, something went wrong.

0 comments on commit df1f131

Please sign in to comment.