Move tests to query package

This commit is contained in:
Asdine El Hrychy
2019-12-04 20:47:19 +01:00
parent 56abf30461
commit 5b51b1ac0c
14 changed files with 618 additions and 550 deletions

64
query/drop.go Normal file
View File

@@ -0,0 +1,64 @@
package query
import (
"database/sql/driver"
"errors"
"github.com/asdine/genji/database"
)
// DropTableStmt is a DSL that allows creating a DROP TABLE query.
type DropTableStmt struct {
TableName string
IfExists bool
}
// IsReadOnly always returns false. It implements the Statement interface.
func (stmt DropTableStmt) IsReadOnly() bool {
return false
}
// Run runs the DropTable statement in the given transaction.
// It implements the Statement interface.
func (stmt DropTableStmt) Run(tx *database.Transaction, args []driver.NamedValue) (Result, error) {
var res Result
if stmt.TableName == "" {
return res, errors.New("missing table name")
}
err := tx.DropTable(stmt.TableName)
if err == database.ErrTableNotFound && stmt.IfExists {
err = nil
}
return res, err
}
// DropIndexStmt is a DSL that allows creating a DROP INDEX query.
type DropIndexStmt struct {
IndexName string
IfExists bool
}
// IsReadOnly always returns false. It implements the Statement interface.
func (stmt DropIndexStmt) IsReadOnly() bool {
return false
}
// Run runs the DropIndex statement in the given transaction.
// It implements the Statement interface.
func (stmt DropIndexStmt) Run(tx *database.Transaction, args []driver.NamedValue) (Result, error) {
var res Result
if stmt.IndexName == "" {
return res, errors.New("missing index name")
}
err := tx.DropIndex(stmt.IndexName)
if err == database.ErrIndexNotFound && stmt.IfExists {
err = nil
}
return res, err
}