Skip to content

Commit

Permalink
feat: Schemas sdk v2 (#1975)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jcieslak authored Aug 10, 2023
1 parent 45dbd3a commit 289ad8a
Show file tree
Hide file tree
Showing 9 changed files with 1,074 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- name: setup-go
uses: actions/setup-go@v4
with:
go-version-file: './go.mod'
go-version-file: ./go.mod

- name: Install dependencies
run: make setup
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version-file: './go.mod'
go-version-file: ./go.mod
- name: Install dependencies
run: make setup
- name: make ${{ matrix.target }}
Expand Down
10 changes: 5 additions & 5 deletions pkg/sdk/alerts_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ func TestInt_AlertCreate(t *testing.T) {
condition := "SELECT 1"
action := `
select
case
when true then
1
else
2
case
when true then
1
else
2
end
`
id := NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name)
Expand Down
2 changes: 2 additions & 0 deletions pkg/sdk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type Client struct {
Sessions Sessions
Shares Shares
Users Users
Schemas Schemas
Warehouses Warehouses
}

Expand Down Expand Up @@ -136,6 +137,7 @@ func (c *Client) initialize() {
c.SessionPolicies = &sessionPolicies{client: c}
c.Sessions = &sessions{client: c}
c.Shares = &shares{client: c}
c.Schemas = &schemas{client: c}
c.SystemFunctions = &systemFunctions{client: c}
c.Users = &users{client: c}
c.Warehouses = &warehouses{client: c}
Expand Down
5 changes: 5 additions & 0 deletions pkg/sdk/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sdk

import (
"errors"
"fmt"
"log"
"strings"
)
Expand All @@ -15,6 +16,10 @@ var (
ErrInvalidObjectIdentifier = errors.New("invalid object identifier")
)

func errOneOf(fieldNames ...string) error {
return fmt.Errorf("fields %v are incompatible and cannot be set at once", fieldNames)
}

func decodeDriverError(err error) error {
if err == nil {
return nil
Expand Down
16 changes: 8 additions & 8 deletions pkg/sdk/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,15 +359,15 @@ func createSchema(t *testing.T, client *Client, database *Database) (*Schema, fu
func createSchemaWithIdentifier(t *testing.T, client *Client, database *Database, name string) (*Schema, func()) {
t.Helper()
ctx := context.Background()
_, err := client.exec(ctx, fmt.Sprintf("CREATE SCHEMA \"%s\".\"%s\"", database.Name, name))
schemaID := NewSchemaIdentifier(database.Name, name)
err := client.Schemas.Create(ctx, schemaID, nil)
require.NoError(t, err)
return &Schema{
DatabaseName: database.Name,
Name: name,
}, func() {
_, err := client.exec(ctx, fmt.Sprintf("DROP SCHEMA \"%s\".\"%s\"", database.Name, name))
require.NoError(t, err)
}
schema, err := client.Schemas.ShowByID(ctx, NewSchemaIdentifier(database.Name, name))
require.NoError(t, err)
return schema, func() {
err := client.Schemas.Drop(ctx, schemaID, nil)
require.NoError(t, err)
}
}

func createTable(t *testing.T, client *Client, database *Database, schema *Schema) (*Table, func()) {
Expand Down
Loading

0 comments on commit 289ad8a

Please sign in to comment.