mirror of https://github.com/writeas/writefreely
This adds a new `sqlite` build tag that you should include only if you want SQLite3 support built in. Both `make run` and `make release` create builds with SQLite included.pull/54/head
parent
8513def899
commit
fca3019e4b
@ -0,0 +1,30 @@ |
||||
// +build !sqlite
|
||||
|
||||
/* |
||||
* Copyright © 2019 A Bunch Tell LLC. |
||||
* |
||||
* This file is part of WriteFreely. |
||||
* |
||||
* WriteFreely is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License, included |
||||
* in the LICENSE file in this source code package. |
||||
*/ |
||||
|
||||
package writefreely |
||||
|
||||
import ( |
||||
"github.com/go-sql-driver/mysql" |
||||
"github.com/writeas/web-core/log" |
||||
) |
||||
|
||||
func (db *datastore) isDuplicateKeyErr(err error) bool { |
||||
if db.driverName == driverMySQL { |
||||
if mysqlErr, ok := err.(*mysql.MySQLError); ok { |
||||
return mysqlErr.Number == mySQLErrDuplicateKey |
||||
} |
||||
} else { |
||||
log.Error("isDuplicateKeyErr: failed check for unrecognized driver '%s'", db.driverName) |
||||
} |
||||
|
||||
return false |
||||
} |
@ -0,0 +1,39 @@ |
||||
// +build sqlite
|
||||
|
||||
/* |
||||
* Copyright © 2019 A Bunch Tell LLC. |
||||
* |
||||
* This file is part of WriteFreely. |
||||
* |
||||
* WriteFreely is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License, included |
||||
* in the LICENSE file in this source code package. |
||||
*/ |
||||
|
||||
package writefreely |
||||
|
||||
import ( |
||||
"github.com/go-sql-driver/mysql" |
||||
"github.com/mattn/go-sqlite3" |
||||
"github.com/writeas/web-core/log" |
||||
) |
||||
|
||||
func init() { |
||||
SQLiteEnabled = true |
||||
} |
||||
|
||||
func (db *datastore) isDuplicateKeyErr(err error) bool { |
||||
if db.driverName == driverSQLite { |
||||
if err, ok := err.(sqlite3.Error); ok { |
||||
return err.Code == sqlite3.ErrConstraint |
||||
} |
||||
} else if db.driverName == driverMySQL { |
||||
if mysqlErr, ok := err.(*mysql.MySQLError); ok { |
||||
return mysqlErr.Number == mySQLErrDuplicateKey |
||||
} |
||||
} else { |
||||
log.Error("isDuplicateKeyErr: failed check for unrecognized driver '%s'", db.driverName) |
||||
} |
||||
|
||||
return false |
||||
} |
Loading…
Reference in new issue