Skip to content

Commit

Permalink
*: Address comments and Update USAGE.md
Browse files Browse the repository at this point in the history
  • Loading branch information
shenli committed Sep 10, 2015
1 parent 62b73d2 commit 4cddb25
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
6 changes: 4 additions & 2 deletions docs/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ func main() {
// Default log level is debug, set it to error to turn off debug log.
log.SetLevelByString("error")

// DriverName is 'tidb', dataSourceName is in the form of "<engine>://<dbPath>".
// DriverName is 'tidb', dataSourceName is in the form of "<engine>://<dbPath>/<dbName>".
// dbPath is the directory that stores the data files if you use a local storage engine.
// dbName is the name of the database which you want to use.
dbPath := "/tmp/tidb"
db, err := sql.Open("tidb", "goleveldb://" + dbPath)
dbName := "tidb"
db, err := sql.Open("tidb", "goleveldb://" + dbPath + "/" + dbName)
if err != nil {
log.Fatal(err)
}
Expand Down
9 changes: 1 addition & 8 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (d *sqlDriver) Open(dataSource string) (driver.Conn, error) {
// Split the dataSource to uri and dbName
i := strings.LastIndex(dataSource, "/")
if i == -1 {
return nil, errors.Errorf("Wrong format of datasource string: %q", dataSource)
return nil, errors.Errorf("Invalid dataSource: %q", dataSource)
}
uri := dataSource[:i]
dbName := dataSource[i+1:]
Expand All @@ -146,12 +146,6 @@ func (d *sqlDriver) Open(dataSource string) (driver.Conn, error) {
}

driver := &sqlDriver{}
switch {
case strings.HasPrefix(uri, "file://"):
uri = uri[len("file://"):]
case strings.HasPrefix(uri, "memory://"):
uri = uri[len("memory://"):]
}
dbName = filepath.Clean(dbName)
if dbName == "" || dbName == "." || dbName == string(os.PathSeparator) {
return nil, errors.Errorf("invalid DB name %q", dbName)
Expand All @@ -171,7 +165,6 @@ func (d *sqlDriver) Open(dataSource string) (driver.Conn, error) {
return nil, errors.Trace(err)
}
}

return newDriverConn(s, driver, DBName.O)
}

Expand Down

1 comment on commit 4cddb25

@qiuyesuifeng
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Please sign in to comment.