Start of Go's db & db/dbimpl packages, being prototyped here.

Change-Id: I3f2e868403b44f878d5f3fdcb6b7d0971ac12a8d
This commit is contained in:
Brad Fitzpatrick 2011-07-25 12:32:10 -07:00
parent fce867f987
commit 85d2472b34
3 changed files with 206 additions and 0 deletions

View File

@ -645,6 +645,8 @@ TARGET: lib/go/camli/blobserver/replica
TARGET: lib/go/camli/blobserver/shard
TARGET: lib/go/camli/blobserver/s3
TARGET: lib/go/camli/client
TARGET: lib/go/camli/db
TARGET: lib/go/camli/db/dbimpl
TARGET: lib/go/camli/errorutil
TARGET: lib/go/camli/httputil
TARGET: lib/go/camli/jsonconfig

138
lib/go/camli/db/db.go Normal file
View File

@ -0,0 +1,138 @@
/*
Copyright 2011 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package db
import (
"os"
"camli/db/dbimpl"
)
type DB struct {
impl dbimpl.Driver
}
func Open(driver, name string) (*DB, os.Error) {
panic("TODO: implement")
}
func (db *DB) Prepare(query string) (*Stmt, os.Error) {
panic("TODO: implement")
}
func (db *DB) Exec(query string, args ...interface{}) os.Error {
panic("TODO: implement")
}
func (db *DB) Query(query string, args ...interface{}) (*Rows, os.Error) {
panic("TODO: implement")
}
func (db *DB) QueryRow(query string, args ...interface{}) *Row {
panic("TODO: implement")
}
func (db *DB) Begin() (*Tx, os.Error) {
panic("TODO: implement")
}
// DriverDatabase returns the database's underlying driver.
// This is non-portable and should only be used when
// needed.
func (db *DB) DriverDatabase() interface{} {
return db.impl
}
// Tx is an in-progress database transaction.
type Tx struct {
}
func (tx *Tx) Commit() os.Error {
panic("TODO: implement")
}
func (tx *Tx) Rollback() os.Error {
panic("TODO: implement")
}
func (tx *Tx) Prepare(query string) (*Stmt, os.Error) {
panic("TODO: implement")
}
func (tx *Tx) Exec(query string, args ...interface{}) {
panic("TODO: implement")
}
func (tx *Tx) Query(query string, args ...interface{}) (*Rows, os.Error) {
panic("TODO: implement")
}
func (tx *Tx) QueryRow(query string, args ...interface{}) *Row {
panic("TODO: implement")
}
type Stmt struct {
}
func (s *Stmt) Exec(args ...interface{}) os.Error {
panic("TODO: implement")
}
func (s *Stmt) Query(args ...interface{}) (*Rows, os.Error) {
panic("TODO: implement")
}
func (s *Stmt) QueryRow(args ...interface{}) *Row {
panic("TODO: implement")
}
func (s *Stmt) Close() os.Error {
panic("TODO: implement")
}
type Rows struct {
}
func (rs *Rows) Next() bool {
panic("TODO: implement")
}
func (rs *Rows) Error() os.Error {
panic("TODO: implement")
}
func (rs *Rows) Scan(dest ...interface{}) os.Error {
panic("TODO: implement")
}
func (rs *Rows) Close() os.Error {
panic("TODO: implement")
}
type Row struct {
err os.Error
}
func (r *Row) Scan(dest ...interface{}) os.Error {
if r.err != nil {
return r.err
}
panic("TODO: implement")
}

View File

@ -0,0 +1,66 @@
/*
Copyright 2011 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package dbimpl
import (
"os"
)
// must only deal with values:
// int64 (no uint64 support, for now?)
// float64
// bool
// nil
// []byte
type Driver interface {
Open(name string) (Conn, os.Error)
}
type Conn interface {
Prepare(query string) (Stmt, os.Error)
Close()
Begin() (Tx, os.Error)
}
type Result interface {
AutoIncrementId() (int64, os.Error)
RowsAffected() (int64, os.Error)
}
type Stmt interface {
Close()
NumInput() int
Exec(args []interface{}) (Result, os.Error)
}
type Rows interface {
Columns() []string
Close() os.Error
// Returns os.EOF at end of cursor
Next(dest []interface{}) os.Error
}
type Tx interface {
Commit() os.Error
Rollback() os.Error
}