@@ -10,9 +10,9 @@ var ErrCreateTable = errors.NewKind("tables cannot be created on database %s")
1010
1111// CreateTable is a node describing the creation of some table.
1212type CreateTable struct {
13- Database sql.Database
14- name string
15- schema sql.Schema
13+ db sql.Database
14+ name string
15+ schema sql.Schema
1616}
1717
1818// NewCreateTable creates a new CreateTable node
@@ -22,23 +22,37 @@ func NewCreateTable(db sql.Database, name string, schema sql.Schema) *CreateTabl
2222 }
2323
2424 return & CreateTable {
25- Database : db ,
26- name : name ,
27- schema : schema ,
25+ db : db ,
26+ name : name ,
27+ schema : schema ,
2828 }
2929}
3030
31+ var _ sql.Databaser = (* CreateTable )(nil )
32+
33+ // Database implements the sql.Databaser interface.
34+ func (c * CreateTable ) Database () sql.Database {
35+ return c .db
36+ }
37+
38+ // WithDatabase implements the sql.Databaser interface.
39+ func (c * CreateTable ) WithDatabase (db sql.Database ) (sql.Node , error ) {
40+ nc := * c
41+ nc .db = db
42+ return & nc , nil
43+ }
44+
3145// Resolved implements the Resolvable interface.
3246func (c * CreateTable ) Resolved () bool {
33- _ , ok := c .Database .(sql.UnresolvedDatabase )
47+ _ , ok := c .db .(sql.UnresolvedDatabase )
3448 return ! ok
3549}
3650
3751// RowIter implements the Node interface.
3852func (c * CreateTable ) RowIter (s * sql.Context ) (sql.RowIter , error ) {
39- d , ok := c .Database .(sql.Alterable )
53+ d , ok := c .db .(sql.Alterable )
4054 if ! ok {
41- return nil , ErrCreateTable .New (c .Database .Name ())
55+ return nil , ErrCreateTable .New (c .db .Name ())
4256 }
4357
4458 return sql .RowsToRowIter (), d .Create (c .name , c .schema )
@@ -52,7 +66,7 @@ func (c *CreateTable) Children() []sql.Node { return nil }
5266
5367// TransformUp implements the Transformable interface.
5468func (c * CreateTable ) TransformUp (f sql.TransformNodeFunc ) (sql.Node , error ) {
55- return f (NewCreateTable (c .Database , c .name , c .schema ))
69+ return f (NewCreateTable (c .db , c .name , c .schema ))
5670}
5771
5872// TransformExpressionsUp implements the Transformable interface.
0 commit comments