|
| 1 | +// Copyright 2025 Dolthub, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package noop |
| 16 | + |
| 17 | +import ( |
| 18 | + "github.com/dolthub/go-mysql-server/sql" |
| 19 | + "github.com/dolthub/go-mysql-server/sql/hooks" |
| 20 | + "github.com/dolthub/go-mysql-server/sql/plan" |
| 21 | +) |
| 22 | + |
| 23 | +// init sets the global hooks to be no-ops by default. It is intended that the variable will be replaced by the |
| 24 | +// integrator. |
| 25 | +func init() { |
| 26 | + hooks.Global = NoOp{} |
| 27 | +} |
| 28 | + |
| 29 | +// NoOp implements hooks.Hooks while having all operations be no-ops. Integrators may supply their own implementation. |
| 30 | +type NoOp struct{} |
| 31 | + |
| 32 | +var _ hooks.Hooks = NoOp{} |
| 33 | + |
| 34 | +// Table implements the interface hooks.Hooks. |
| 35 | +func (NoOp) Table() hooks.Table { |
| 36 | + return Table{} |
| 37 | +} |
| 38 | + |
| 39 | +// TableColumn implements the interface hooks.Hooks. |
| 40 | +func (NoOp) TableColumn() hooks.TableColumn { |
| 41 | + return TableColumn{} |
| 42 | +} |
| 43 | + |
| 44 | +// Table implements no-ops for the hooks.Table interface. |
| 45 | +type Table struct{} |
| 46 | + |
| 47 | +var _ hooks.Table = Table{} |
| 48 | + |
| 49 | +// Create implements the interface hooks.Table. |
| 50 | +func (Table) Create() hooks.CreateTable { |
| 51 | + return CreateTable{} |
| 52 | +} |
| 53 | + |
| 54 | +// Rename implements the interface hooks.Table. |
| 55 | +func (Table) Rename() hooks.RenameTable { |
| 56 | + return RenameTable{} |
| 57 | +} |
| 58 | + |
| 59 | +// Drop implements the interface hooks.Table. |
| 60 | +func (Table) Drop() hooks.DropTable { |
| 61 | + return DropTable{} |
| 62 | +} |
| 63 | + |
| 64 | +// TableColumn implements no-ops for the hooks.TableColumn interface. |
| 65 | +type TableColumn struct{} |
| 66 | + |
| 67 | +var _ hooks.TableColumn = TableColumn{} |
| 68 | + |
| 69 | +// Add implements the interface hooks.TableColumn. |
| 70 | +func (TableColumn) Add() hooks.TableAddColumn { |
| 71 | + return TableAddColumn{} |
| 72 | +} |
| 73 | + |
| 74 | +// Rename implements the interface hooks.TableColumn. |
| 75 | +func (TableColumn) Rename() hooks.TableRenameColumn { |
| 76 | + return TableRenameColumn{} |
| 77 | +} |
| 78 | + |
| 79 | +// Modify implements the interface hooks.TableColumn. |
| 80 | +func (TableColumn) Modify() hooks.TableModifyColumn { |
| 81 | + return TableModifyColumn{} |
| 82 | +} |
| 83 | + |
| 84 | +// Drop implements the interface hooks.TableColumn. |
| 85 | +func (TableColumn) Drop() hooks.TableDropColumn { |
| 86 | + return TableDropColumn{} |
| 87 | +} |
| 88 | + |
| 89 | +// CreateTable implements no-ops for the hooks.CreateTable interface. |
| 90 | +type CreateTable struct{} |
| 91 | + |
| 92 | +var _ hooks.CreateTable = CreateTable{} |
| 93 | + |
| 94 | +// PreSQLExecution implements the interface hooks.CreateTable. |
| 95 | +func (CreateTable) PreSQLExecution(_ *sql.Context, n *plan.CreateTable) (*plan.CreateTable, error) { |
| 96 | + return n, nil |
| 97 | +} |
| 98 | + |
| 99 | +// PostSQLExecution implements the interface hooks.CreateTable. |
| 100 | +func (CreateTable) PostSQLExecution(_ *sql.Context, n *plan.CreateTable) error { |
| 101 | + return nil |
| 102 | +} |
| 103 | + |
| 104 | +// RenameTable implements no-ops for the hooks.RenameTable interface. |
| 105 | +type RenameTable struct{} |
| 106 | + |
| 107 | +var _ hooks.RenameTable = RenameTable{} |
| 108 | + |
| 109 | +// PreSQLExecution implements the interface hooks.RenameTable. |
| 110 | +func (RenameTable) PreSQLExecution(_ *sql.Context, n *plan.RenameTable) (*plan.RenameTable, error) { |
| 111 | + return n, nil |
| 112 | +} |
| 113 | + |
| 114 | +// PostSQLExecution implements the interface hooks.RenameTable. |
| 115 | +func (RenameTable) PostSQLExecution(_ *sql.Context, n *plan.RenameTable) error { |
| 116 | + return nil |
| 117 | +} |
| 118 | + |
| 119 | +// DropTable implements no-ops for the hooks.DropTable interface. |
| 120 | +type DropTable struct{} |
| 121 | + |
| 122 | +var _ hooks.DropTable = DropTable{} |
| 123 | + |
| 124 | +// PreSQLExecution implements the interface hooks.DropTable. |
| 125 | +func (DropTable) PreSQLExecution(_ *sql.Context, n *plan.DropTable) (*plan.DropTable, error) { |
| 126 | + return n, nil |
| 127 | +} |
| 128 | + |
| 129 | +// PostSQLExecution implements the interface hooks.DropTable. |
| 130 | +func (DropTable) PostSQLExecution(_ *sql.Context, n *plan.DropTable) error { |
| 131 | + return nil |
| 132 | +} |
| 133 | + |
| 134 | +// TableAddColumn implements no-ops for the hooks.TableAddColumn interface. |
| 135 | +type TableAddColumn struct{} |
| 136 | + |
| 137 | +var _ hooks.TableAddColumn = TableAddColumn{} |
| 138 | + |
| 139 | +// PreSQLExecution implements the interface hooks.TableAddColumn. |
| 140 | +func (TableAddColumn) PreSQLExecution(_ *sql.Context, n *plan.AddColumn) (*plan.AddColumn, error) { |
| 141 | + return n, nil |
| 142 | +} |
| 143 | + |
| 144 | +// PostSQLExecution implements the interface hooks.TableAddColumn. |
| 145 | +func (TableAddColumn) PostSQLExecution(_ *sql.Context, n *plan.AddColumn) error { |
| 146 | + return nil |
| 147 | +} |
| 148 | + |
| 149 | +// TableRenameColumn implements no-ops for the hooks.TableRenameColumn interface. |
| 150 | +type TableRenameColumn struct{} |
| 151 | + |
| 152 | +var _ hooks.TableRenameColumn = TableRenameColumn{} |
| 153 | + |
| 154 | +// PreSQLExecution implements the interface hooks.TableRenameColumn. |
| 155 | +func (TableRenameColumn) PreSQLExecution(_ *sql.Context, n *plan.RenameColumn) (*plan.RenameColumn, error) { |
| 156 | + return n, nil |
| 157 | +} |
| 158 | + |
| 159 | +// PostSQLExecution implements the interface hooks.TableRenameColumn. |
| 160 | +func (TableRenameColumn) PostSQLExecution(_ *sql.Context, n *plan.RenameColumn) error { |
| 161 | + return nil |
| 162 | +} |
| 163 | + |
| 164 | +// TableModifyColumn implements no-ops for the hooks.TableModifyColumn interface. |
| 165 | +type TableModifyColumn struct{} |
| 166 | + |
| 167 | +var _ hooks.TableModifyColumn = TableModifyColumn{} |
| 168 | + |
| 169 | +// PreSQLExecution implements the interface hooks.TableModifyColumn. |
| 170 | +func (TableModifyColumn) PreSQLExecution(_ *sql.Context, n *plan.ModifyColumn) (*plan.ModifyColumn, error) { |
| 171 | + return n, nil |
| 172 | +} |
| 173 | + |
| 174 | +// PostSQLExecution implements the interface hooks.TableModifyColumn. |
| 175 | +func (TableModifyColumn) PostSQLExecution(_ *sql.Context, n *plan.ModifyColumn) error { |
| 176 | + return nil |
| 177 | +} |
| 178 | + |
| 179 | +// TableDropColumn implements no-ops for the hooks.TableDropColumn interface. |
| 180 | +type TableDropColumn struct{} |
| 181 | + |
| 182 | +var _ hooks.TableDropColumn = TableDropColumn{} |
| 183 | + |
| 184 | +// PreSQLExecution implements the interface hooks.TableDropColumn. |
| 185 | +func (TableDropColumn) PreSQLExecution(_ *sql.Context, n *plan.DropColumn) (*plan.DropColumn, error) { |
| 186 | + return n, nil |
| 187 | +} |
| 188 | + |
| 189 | +// PostSQLExecution implements the interface hooks.TableDropColumn. |
| 190 | +func (TableDropColumn) PostSQLExecution(_ *sql.Context, n *plan.DropColumn) error { |
| 191 | + return nil |
| 192 | +} |
0 commit comments