MySQL lock and unlock tables statement.
This commit is contained in:
parent
ee4897a1e2
commit
a3ae52c43c
5 changed files with 128 additions and 18 deletions
54
mysql/lock_statement.go
Normal file
54
mysql/lock_statement.go
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
package mysql
|
||||
|
||||
import "github.com/go-jet/jet/internal/jet"
|
||||
|
||||
type LockStatement interface {
|
||||
Statement
|
||||
READ() Statement
|
||||
WRITE() Statement
|
||||
}
|
||||
|
||||
func LOCK(tables ...jet.SerializerTable) LockStatement {
|
||||
newLock := &lockStatementImpl{
|
||||
Lock: jet.ClauseStatementBegin{Name: "LOCK TABLES", Tables: tables},
|
||||
Read: jet.ClauseOptional{Name: "READ"},
|
||||
Write: jet.ClauseOptional{Name: "WRITE"},
|
||||
}
|
||||
|
||||
newLock.StatementImpl = jet.NewStatementImpl(Dialect, jet.LockStatementType, newLock, &newLock.Lock, &newLock.Read, &newLock.Write)
|
||||
|
||||
return newLock
|
||||
}
|
||||
|
||||
type lockStatementImpl struct {
|
||||
jet.StatementImpl
|
||||
|
||||
Lock jet.ClauseStatementBegin
|
||||
Read jet.ClauseOptional
|
||||
Write jet.ClauseOptional
|
||||
}
|
||||
|
||||
func (l *lockStatementImpl) READ() Statement {
|
||||
l.Read.Show = true
|
||||
return l
|
||||
}
|
||||
|
||||
func (l *lockStatementImpl) WRITE() Statement {
|
||||
l.Write.Show = true
|
||||
return l
|
||||
}
|
||||
|
||||
func UNLOCK_TABLES() Statement {
|
||||
newUnlock := &unlockStatementImpl{
|
||||
Unlock: jet.ClauseStatementBegin{Name: "UNLOCK TABLES"},
|
||||
}
|
||||
|
||||
newUnlock.StatementImpl = jet.NewStatementImpl(Dialect, jet.UnLockStatementType, newUnlock, &newUnlock.Unlock)
|
||||
|
||||
return newUnlock
|
||||
}
|
||||
|
||||
type unlockStatementImpl struct {
|
||||
jet.StatementImpl
|
||||
Unlock jet.ClauseStatementBegin
|
||||
}
|
||||
21
mysql/lock_statement_test.go
Normal file
21
mysql/lock_statement_test.go
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package mysql
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestLockRead(t *testing.T) {
|
||||
assertStatement(t, table2.LOCK().READ(), `
|
||||
LOCK TABLES db.table2 READ;
|
||||
`)
|
||||
}
|
||||
|
||||
func TestLockWrite(t *testing.T) {
|
||||
assertStatement(t, table2.LOCK().WRITE(), `
|
||||
LOCK TABLES db.table2 WRITE;
|
||||
`)
|
||||
}
|
||||
|
||||
func TestUNLOCK_TABLES(t *testing.T) {
|
||||
assertStatement(t, UNLOCK_TABLES(), `
|
||||
UNLOCK TABLES;
|
||||
`)
|
||||
}
|
||||
|
|
@ -2,12 +2,6 @@ package mysql
|
|||
|
||||
import "github.com/go-jet/jet/internal/jet"
|
||||
|
||||
//type Table jet.Table
|
||||
//
|
||||
//func NewTable(schemaName, name string, columns ...jet.Column) Table {
|
||||
// return jet.NewTable(Dialect, schemaName, name, columns...)
|
||||
//}
|
||||
|
||||
type Table interface {
|
||||
jet.SerializerTable
|
||||
readableTable
|
||||
|
|
@ -15,9 +9,7 @@ type Table interface {
|
|||
INSERT(columns ...jet.Column) InsertStatement
|
||||
UPDATE(column jet.Column, columns ...jet.Column) UpdateStatement
|
||||
DELETE() DeleteStatement
|
||||
//LOCK() LockStatement
|
||||
|
||||
//As(alias string)
|
||||
LOCK() LockStatement
|
||||
}
|
||||
|
||||
type readableTable interface {
|
||||
|
|
@ -94,21 +86,21 @@ type tableImpl struct {
|
|||
parent Table
|
||||
}
|
||||
|
||||
func (w *tableImpl) INSERT(columns ...jet.Column) InsertStatement {
|
||||
return newInsertStatement(w.parent, jet.UnwidColumnList(columns))
|
||||
func (t *tableImpl) INSERT(columns ...jet.Column) InsertStatement {
|
||||
return newInsertStatement(t.parent, jet.UnwidColumnList(columns))
|
||||
}
|
||||
|
||||
func (w *tableImpl) UPDATE(column jet.Column, columns ...jet.Column) UpdateStatement {
|
||||
return newUpdateStatement(w.parent, jet.UnwindColumns(column, columns...))
|
||||
func (t *tableImpl) UPDATE(column jet.Column, columns ...jet.Column) UpdateStatement {
|
||||
return newUpdateStatement(t.parent, jet.UnwindColumns(column, columns...))
|
||||
}
|
||||
|
||||
func (w *tableImpl) DELETE() DeleteStatement {
|
||||
return newDeleteStatement(w.parent)
|
||||
func (t *tableImpl) DELETE() DeleteStatement {
|
||||
return newDeleteStatement(t.parent)
|
||||
}
|
||||
|
||||
//func (w *tableInterfaceImpl) LOCK() LockStatement {
|
||||
// return LOCK(w.parent)
|
||||
//}
|
||||
func (t *tableImpl) LOCK() LockStatement {
|
||||
return LOCK(t.parent)
|
||||
}
|
||||
|
||||
type joinTable2 struct {
|
||||
tableImpl
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue