Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Extracted "connection" API to its own file.

  • Loading branch information...
commit 8fb69d2da1bbacc5679022f5060fa1b1c00ba698 1 parent 01e74c3
@phf authored
Showing with 77 additions and 70 deletions.
  1. +1 −1  Makefile
  2. +76 −0 connection.go
  3. +0 −69 db.go
View
2  Makefile
@@ -1,6 +1,6 @@
include $(GOROOT)/src/Make.$(GOARCH)
TARG=db
-GOFILES=db.go classic.go util.go result.go set.go
+GOFILES=db.go classic.go util.go result.go set.go connection.go
include $(GOROOT)/src/Make.pkg
View
76 connection.go
@@ -0,0 +1,76 @@
+// Copyright 2009 Peter H. Froehlich. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package db
+
+import "os"
+
+// The most basic type of database connection.
+//
+// The choice to separate Prepare() and Execute() is deliberate:
+// It leaves the database driver the most flexibilty for achieving
+// good performance without requiring additional caching schemes.
+//
+// Prepare() accepts a query language string and returns
+// a precompiled statement that can be executed after any
+// remaining parameters have been bound. The format of
+// parameters in the query string is dependent on the
+// database driver in question.
+//
+// Execute() accepts a precompiled statement, binds the
+// given parameters, and then executes the statement.
+// Execute() returns a channel of Result objects which
+// can be examined one at a time (if the query produced
+// results to begin with). Specific database drivers
+// will return result objects conforming to one or more
+// of the following interfaces which represent different
+// levels of functionality.
+//
+// Close() ends the connection to the database system
+// and frees up all internal resources associated with
+// it. Note that you must close all objects created on
+// the connection before closing the connection itself.
+// After a connection has been closed, no further
+// operations are allowed on it.
+type Connection interface {
+ Prepare(query string) (Statement, os.Error);
+ Execute(stat Statement, parameters ...) (<-chan Result, os.Error);
+ Close() os.Error;
+}
+
+// InformativeConnections supply useful but optional information.
+//
+// Changes() returns the number of changes the last query made
+// to the database. Note that the database driver has to explain
+// what exactly constitutes a "change" for a given database system
+// and query.
+//
+// LastId() returns the id of the last successful insertion into
+// the database. The database driver has to explain the exact
+// meaning of the id and the conditions under which it changes.
+type InformativeConnection interface {
+ Connection;
+ Changes() (int, os.Error);
+ LastId() (int, os.Error);
+}
+
+// TransactionalConnections support transactions. Note that
+// the database driver in question may be in "auto commit"
+// mode by default. Once you call Begin(), "auto commit" will
+// be disabled for that connection until you either Commit()
+// or Rollback() successfully.
+//
+// Begin() starts a transaction.
+//
+// Commit() tries to push all changes made as part of the
+// current transaction to the database.
+//
+// Rollback() tries to undo all changes made as part of the
+// current transaction.
+type TransactionalConnection interface {
+ Connection;
+ Begin() os.Error;
+ Commit() os.Error;
+ Rollback() os.Error;
+}
View
69 db.go
@@ -104,75 +104,6 @@ type VersionSignature func() (map[string]string, os.Error)
// interfaces which represent different levels of functionality.
type OpenSignature func(url string) (Connection, os.Error)
-// The most basic type of database connection.
-//
-// The choice to separate Prepare() and Execute() is deliberate:
-// It leaves the database driver the most flexibilty for achieving
-// good performance without requiring additional caching schemes.
-//
-// Prepare() accepts a query language string and returns
-// a precompiled statement that can be executed after any
-// remaining parameters have been bound. The format of
-// parameters in the query string is dependent on the
-// database driver in question.
-//
-// Execute() accepts a precompiled statement, binds the
-// given parameters, and then executes the statement.
-// Execute() returns a channel of Result objects which
-// can be examined one at a time (if the query produced
-// results to begin with). Specific database drivers
-// will return result objects conforming to one or more
-// of the following interfaces which represent different
-// levels of functionality.
-//
-// Close() ends the connection to the database system
-// and frees up all internal resources associated with
-// it. Note that you must close all objects created on
-// the connection before closing the connection itself.
-// After a connection has been closed, no further
-// operations are allowed on it.
-type Connection interface {
- Prepare(query string) (Statement, os.Error);
- Execute(stat Statement, parameters ...) (<-chan Result, os.Error);
- Close() os.Error;
-}
-
-// InformativeConnections supply useful but optional information.
-//
-// Changes() returns the number of changes the last query made
-// to the database. Note that the database driver has to explain
-// what exactly constitutes a "change" for a given database system
-// and query.
-//
-// LastId() returns the id of the last successful insertion into
-// the database. The database driver has to explain the exact
-// meaning of the id and the conditions under which it changes.
-type InformativeConnection interface {
- Connection;
- Changes() (int, os.Error);
- LastId() (int, os.Error);
-}
-
-// TransactionalConnections support transactions. Note that
-// the database driver in question may be in "auto commit"
-// mode by default. Once you call Begin(), "auto commit" will
-// be disabled for that connection until you either Commit()
-// or Rollback() successfully.
-//
-// Begin() starts a transaction.
-//
-// Commit() tries to push all changes made as part of the
-// current transaction to the database.
-//
-// Rollback() tries to undo all changes made as part of the
-// current transaction.
-type TransactionalConnection interface {
- Connection;
- Begin() os.Error;
- Commit() os.Error;
- Rollback() os.Error;
-}
-
// Statements are precompiled queries, possibly with remaining
// parameter slots that need to be filled before execution.
// TODO: include parameter binding API? or subsume in Execute()?
Please sign in to comment.
Something went wrong with that request. Please try again.