Skip to content

Commit

Permalink
refactor: use optional.Option directly in SQLC (#1676)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecthomas authored Jun 6, 2024
1 parent a26e03e commit 1b38c7b
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 80 deletions.
6 changes: 3 additions & 3 deletions backend/controller/sql/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions backend/controller/sql/querier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions backend/controller/sql/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 0 additions & 45 deletions backend/controller/sql/types.go
Original file line number Diff line number Diff line change
@@ -1,60 +1,15 @@
package sql

import (
"database/sql"
"database/sql/driver"
"fmt"
"time"

"github.com/alecthomas/types/optional"
"github.com/google/uuid"
"google.golang.org/protobuf/proto"

"github.com/TBD54566975/ftl/backend/controller/leases"
schemapb "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/schema"
"github.com/TBD54566975/ftl/backend/schema"
"github.com/TBD54566975/ftl/internal/model"
)

type NullType = optional.Option[Type]
type NullRef = optional.Option[schema.RefKey]
type NullUUID = optional.Option[uuid.UUID]
type NullLeaseKey = optional.Option[leases.Key]
type NullTime = optional.Option[time.Time]
type NullDuration = optional.Option[time.Duration]
type NullRunnerKey = optional.Option[model.RunnerKey]
type NullCronJobKey = optional.Option[model.CronJobKey]
type NullDeploymentKey = optional.Option[model.DeploymentKey]
type NullRequestKey = optional.Option[model.RequestKey]
type NullTopicKey = optional.Option[model.TopicKey]
type NullSubscriptionKey = optional.Option[model.SubscriptionKey]
type NullSubscriberKey = optional.Option[model.SubscriberKey]
type NullTopicEventKey = optional.Option[model.TopicEventKey]

var _ sql.Scanner = (*NullRunnerKey)(nil)
var _ driver.Valuer = (*NullRunnerKey)(nil)

var _ sql.Scanner = (*NullCronJobKey)(nil)
var _ driver.Valuer = (*NullCronJobKey)(nil)

var _ sql.Scanner = (*NullDeploymentKey)(nil)
var _ driver.Valuer = (*NullDeploymentKey)(nil)

var _ sql.Scanner = (*NullRequestKey)(nil)
var _ driver.Valuer = (*NullRequestKey)(nil)

var _ sql.Scanner = (*NullTopicKey)(nil)
var _ driver.Valuer = (*NullTopicKey)(nil)

var _ sql.Scanner = (*NullSubscriptionKey)(nil)
var _ driver.Valuer = (*NullSubscriptionKey)(nil)

var _ sql.Scanner = (*NullSubscriberKey)(nil)
var _ driver.Valuer = (*NullSubscriberKey)(nil)

var _ sql.Scanner = (*NullTopicEventKey)(nil)
var _ driver.Valuer = (*NullTopicEventKey)(nil)

// Type is a database adapter type for schema.Type.
//
// It encodes to/from the protobuf representation of a Type.
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module github.com/TBD54566975/ftl

go 1.22.2

retract v1.1.0

require (
connectrpc.com/connect v1.16.1
connectrpc.com/grpcreflect v1.2.0
Expand Down Expand Up @@ -146,3 +144,5 @@ require (
modernc.org/strutil v1.2.0 // indirect
modernc.org/token v1.1.0 // indirect
)

retract v1.1.0
32 changes: 16 additions & 16 deletions sqlc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ sql:
- db_type: "uuid"
nullable: true
go_type:
type: "NullUUID"
type: "optional.Option[uuid.UUID]"
- db_type: "timestamptz"
go_type: "time.Time"
- db_type: "pg_catalog.interval"
go_type: "time.Duration"
- db_type: "pg_catalog.interval"
nullable: true
go_type:
type: "NullDuration"
type: "optional.Option[time.Duration]"
- db_type: "module_schema_pb"
go_type: "*github.com/TBD54566975/ftl/backend/schema.Module"
- db_type: "timestamptz"
nullable: true
go_type:
type: "NullTime"
type: "optional.Option[time.Time]"
- db_type: "pg_catalog.varchar"
nullable: true
go_type: "github.com/alecthomas/types/optional.Option[string]"
Expand All @@ -41,72 +41,72 @@ sql:
- db_type: "runner_key"
nullable: true
go_type:
type: "NullRunnerKey"
type: "optional.Option[model.RunnerKey]"
- db_type: "schema_ref"
go_type: "github.com/TBD54566975/ftl/backend/schema.RefKey"
- db_type: "schema_ref"
nullable: true
go_type:
type: "NullRef"
type: "optional.Option[schema.RefKey]"
- db_type: "schema_type"
go_type:
type: "Type"
- db_type: "schema_type"
nullable: true
go_type:
type: "NullType"
type: "optional.Option[Type]"
- db_type: "cron_job_key"
go_type: "github.com/TBD54566975/ftl/internal/model.CronJobKey"
- db_type: "cron_job_key"
nullable: true
go_type:
type: "NullCronJobKey"
type: "optional.Option[model.CronJobKey]"
- db_type: "lease_key"
go_type: "github.com/TBD54566975/ftl/backend/controller/leases.Key"
- db_type: "lease_key"
nullable: true
go_type:
type: "NullLeaseKey"
type: "optional.Option[leases.Key]"
- db_type: "deployment_key"
go_type: "github.com/TBD54566975/ftl/internal/model.DeploymentKey"
- db_type: "cron_job_state"
go_type: "github.com/TBD54566975/ftl/internal/model.CronJobState"
- db_type: "deployment_key"
nullable: true
go_type:
type: "NullDeploymentKey"
type: "optional.Option[model.DeploymentKey]"
- db_type: "cron_job_state"
go_type: "github.com/TBD54566975/ftl/internal/model.CronJobState"
- db_type: "controller_key"
go_type: "github.com/TBD54566975/ftl/internal/model.ControllerKey"
- db_type: "request_key"
go_type: "github.com/TBD54566975/ftl/internal/model.RequestKey"
- db_type: "request_key"
nullable: true
go_type:
type: "NullRequestKey"
type: "optional.Option[model.RequestKey]"
- db_type: "topic_key"
go_type: "github.com/TBD54566975/ftl/internal/model.TopicKey"
- db_type: "topic_key"
nullable: true
go_type:
type: "NullTopicKey"
type: "optional.Option[model.TopicKey]"
- db_type: "subscription_key"
go_type: "github.com/TBD54566975/ftl/internal/model.SubscriptionKey"
- db_type: "subscription_key"
nullable: true
go_type:
type: "NullSubscriptionKey"
type: "optional.Option[model.SubscriptionKey]"
- db_type: "subscriber_key"
go_type: "github.com/TBD54566975/ftl/internal/model.SubscriberKey"
- db_type: "subscriber_key"
nullable: true
go_type:
type: "NullSubscriberKey"
type: "optional.Option[model.SubscriberKey]"
- db_type: "topic_event_key"
go_type: "github.com/TBD54566975/ftl/internal/model.TopicEventKey"
- db_type: "topic_event_key"
nullable: true
go_type:
type: "NullTopicEventKey"
type: "optional.Option[model.TopicEventKey]"
- db_type: "text"
go_type: "string"
- db_type: "text"
Expand Down

0 comments on commit 1b38c7b

Please sign in to comment.