Skip to content

Commit

Permalink
Support SET SCHEMA (#144)
Browse files Browse the repository at this point in the history
Adding the `SET SCHEMA` statement and `CURRENT_SCHEMA` expression. These
would normally be trivial, but this was a good opportunity to refactor
the schema implementation to not be so hacky and make it much easier to
support catalogs in the future.

SQL Standard F763
  • Loading branch information
elliotchance authored Feb 24, 2023
1 parent b503d7f commit 8879d67
Show file tree
Hide file tree
Showing 46 changed files with 1,259 additions and 540 deletions.
13 changes: 9 additions & 4 deletions cmd/vsql/out.v
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ fn out_command(cmd cli.Command) ! {
// To make the output more deterministic, entities will be ordered by name.
// This is not true for the records however, which can potentially come out in
// any order.
schemas.sort(a.name > b.name)
schemas.sort_with_compare(fn (a &vsql.Schema, b &vsql.Schema) int {
return compare_strings(a.name, b.name)
})

for _, schema in schemas {
// We avoid "CREATE SCHEMA PUBLIC;" because it would break the import.
Expand All @@ -39,15 +41,18 @@ fn out_command(cmd cli.Command) ! {
}

mut sequences := db.sequences(schema.name)!
sequences.sort(a.name > b.name)
sequences.sort_with_compare(fn (a &vsql.Sequence, b &vsql.Sequence) int {
return compare_strings(a.name.str(), b.name.str())
})

for _, sequence in sequences {
println('${sequence}\n')
}

mut tables := db.schema_tables(schema.name) or { return err }

tables.sort(a.name > b.name)
tables.sort_with_compare(fn (a &vsql.Table, b &vsql.Table) int {
return compare_strings(a.name.str(), b.name.str())
})

for _, table in tables {
println('${table}\n')
Expand Down
Loading

0 comments on commit 8879d67

Please sign in to comment.