github.com/dolthub/dolt/go@v0.40.5-0.20240520175717-68db7794bea6/libraries/doltcore/sqle/dprocedures/init.go (about)

     1  // Copyright 2022 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 dprocedures
    16  
    17  import (
    18  	"github.com/dolthub/go-mysql-server/sql"
    19  	"github.com/dolthub/go-mysql-server/sql/types"
    20  )
    21  
    22  var DoltProcedures = []sql.ExternalStoredProcedureDetails{
    23  	{Name: "dolt_add", Schema: int64Schema("status"), Function: doltAdd},
    24  	{Name: "dolt_backup", Schema: int64Schema("status"), Function: doltBackup, ReadOnly: true, AdminOnly: true},
    25  	{Name: "dolt_branch", Schema: int64Schema("status"), Function: doltBranch},
    26  	{Name: "dolt_checkout", Schema: doltCheckoutSchema, Function: doltCheckout, ReadOnly: true},
    27  	{Name: "dolt_cherry_pick", Schema: cherryPickSchema, Function: doltCherryPick},
    28  	{Name: "dolt_clean", Schema: int64Schema("status"), Function: doltClean},
    29  	{Name: "dolt_clone", Schema: int64Schema("status"), Function: doltClone, AdminOnly: true},
    30  	{Name: "dolt_commit", Schema: stringSchema("hash"), Function: doltCommit},
    31  	{Name: "dolt_commit_hash_out", Schema: stringSchema("hash"), Function: doltCommitHashOut},
    32  	{Name: "dolt_conflicts_resolve", Schema: int64Schema("status"), Function: doltConflictsResolve},
    33  	{Name: "dolt_count_commits", Schema: int64Schema("ahead", "behind"), Function: doltCountCommits, ReadOnly: true},
    34  	{Name: "dolt_fetch", Schema: int64Schema("status"), Function: doltFetch, AdminOnly: true},
    35  	{Name: "dolt_undrop", Schema: int64Schema("status"), Function: doltUndrop, AdminOnly: true},
    36  	{Name: "dolt_purge_dropped_databases", Schema: int64Schema("status"), Function: doltPurgeDroppedDatabases, AdminOnly: true},
    37  	{Name: "dolt_rebase", Schema: doltRebaseProcedureSchema, Function: doltRebase},
    38  
    39  	// dolt_gc is enabled behind a feature flag for now, see dolt_gc.go
    40  	{Name: "dolt_gc", Schema: int64Schema("status"), Function: doltGC, ReadOnly: true, AdminOnly: true},
    41  
    42  	{Name: "dolt_merge", Schema: doltMergeSchema, Function: doltMerge},
    43  	{Name: "dolt_pull", Schema: doltPullSchema, Function: doltPull, AdminOnly: true},
    44  	{Name: "dolt_push", Schema: doltPushSchema, Function: doltPush, AdminOnly: true},
    45  	{Name: "dolt_remote", Schema: int64Schema("status"), Function: doltRemote, AdminOnly: true},
    46  	{Name: "dolt_reset", Schema: int64Schema("status"), Function: doltReset},
    47  	{Name: "dolt_revert", Schema: int64Schema("status"), Function: doltRevert},
    48  	{Name: "dolt_tag", Schema: int64Schema("status"), Function: doltTag},
    49  	{Name: "dolt_verify_constraints", Schema: int64Schema("violations"), Function: doltVerifyConstraints},
    50  
    51  	{Name: "dolt_stats_drop", Schema: statsFuncSchema, Function: statsFunc(statsDrop)},
    52  	{Name: "dolt_stats_restart", Schema: statsFuncSchema, Function: statsFunc(statsRestart)},
    53  	{Name: "dolt_stats_stop", Schema: statsFuncSchema, Function: statsFunc(statsStop)},
    54  	{Name: "dolt_stats_status", Schema: statsFuncSchema, Function: statsFunc(statsStatus)},
    55  }
    56  
    57  // stringSchema returns a non-nullable schema with all columns as LONGTEXT.
    58  func stringSchema(columnNames ...string) sql.Schema {
    59  	sch := make(sql.Schema, len(columnNames))
    60  	for i, colName := range columnNames {
    61  		sch[i] = &sql.Column{
    62  			Name:     colName,
    63  			Type:     types.LongText,
    64  			Nullable: false,
    65  		}
    66  	}
    67  	return sch
    68  }
    69  
    70  // int64Schema returns a non-nullable schema with all columns as BIGINT.
    71  func int64Schema(columnNames ...string) sql.Schema {
    72  	sch := make(sql.Schema, len(columnNames))
    73  	for i, colName := range columnNames {
    74  		sch[i] = &sql.Column{
    75  			Name:     colName,
    76  			Type:     types.Int64,
    77  			Nullable: false,
    78  		}
    79  	}
    80  	return sch
    81  }
    82  
    83  // rowToIter returns a sql.RowIter with a single row containing the values passed in.
    84  func rowToIter(vals ...interface{}) sql.RowIter {
    85  	row := make(sql.Row, len(vals))
    86  	for i, val := range vals {
    87  		row[i] = val
    88  	}
    89  	return sql.RowsToRowIter(row)
    90  }