-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #614 from dolthub/taylor/schemata
Implement information_schema.schemata
- Loading branch information
Showing
5 changed files
with
129 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2024 Dolthub, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package information_schema | ||
|
||
import ( | ||
"github.com/dolthub/go-mysql-server/sql" | ||
"github.com/dolthub/go-mysql-server/sql/information_schema" | ||
) | ||
|
||
// newSchemataTable creates a new information_schema.SCHEMATA table. | ||
func newSchemataTable() *information_schema.InformationSchemaTable { | ||
return &information_schema.InformationSchemaTable{ | ||
TableName: information_schema.SchemataTableName, | ||
TableSchema: schemataSchema, | ||
Reader: schemataRowIter, | ||
} | ||
} | ||
|
||
// schemataSchema is the schema for the information_schema.SCHEMATA table. | ||
var schemataSchema = sql.Schema{ | ||
{Name: "catalog_name", Type: sql_identifier, Default: nil, Nullable: true, Source: information_schema.SchemataTableName}, | ||
{Name: "schema_name", Type: sql_identifier, Default: nil, Nullable: true, Source: information_schema.SchemataTableName}, | ||
{Name: "schema_owner", Type: sql_identifier, Default: nil, Nullable: true, Source: information_schema.SchemataTableName}, | ||
{Name: "default_character_set_catalog", Type: sql_identifier, Default: nil, Nullable: true, Source: information_schema.SchemataTableName}, | ||
{Name: "default_character_set_schema", Type: sql_identifier, Default: nil, Nullable: true, Source: information_schema.SchemataTableName}, | ||
{Name: "default_character_set_name", Type: sql_identifier, Default: nil, Nullable: true, Source: information_schema.SchemataTableName}, | ||
{Name: "sql_path", Type: character_data, Default: nil, Nullable: true, Source: information_schema.SchemataTableName}, | ||
} | ||
|
||
// schemataRowIter implements the sql.RowIter for the information_schema.SCHEMATA table. | ||
func schemataRowIter(ctx *sql.Context, c sql.Catalog) (sql.RowIter, error) { | ||
dbs, err := information_schema.AllDatabases(ctx, c, false) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var rows []sql.Row | ||
|
||
for _, db := range dbs { | ||
rows = append(rows, sql.Row{ | ||
db.CatalogName, // catalog_name | ||
db.SchemaName, // schema_name | ||
"", // schema_owner | ||
nil, // default_character_set_catalog | ||
nil, // default_character_set_schema | ||
nil, // default_character_set_name | ||
nil, // sql_path | ||
}) | ||
} | ||
|
||
return sql.RowsToRowIter(rows...), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2024 Dolthub, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package information_schema | ||
|
||
import ( | ||
pgtypes "github.com/dolthub/doltgresql/server/types" | ||
) | ||
|
||
// information_schema columns are one of these 5 types https://www.postgresql.org/docs/current/infoschema-datatypes.html | ||
var cardinal_number = pgtypes.Int32 | ||
var character_data = pgtypes.Text | ||
var sql_identifier = pgtypes.VarCharType{Length: 64} | ||
var yes_or_no = pgtypes.VarCharType{Length: 3} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters