/
dimamir
/
rill
Обзор
Документация
Войти
/
dimamir
/
rill
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
runtime/drivers/postgres/postgres.go
182 строки
5 KB
Benjamin Egelund-Müller
Refactor `.vars`/`--var` to `.env`/`--env` (#5981)
28 окт 2024, 19:00
Не верифицирован
28 окт 2024, 19:00
951d990
Код
Авторство
О чём код?
package postgres import ( "context" "errors" "github.com/rilldata/rill/runtime/drivers" "github.com/rilldata/rill/runtime/pkg/activity" "go.uber.org/zap" ) func init() { drivers.Register("postgres", driver{}) drivers.RegisterAsConnector("postgres", driver{}) } var spec = drivers.Spec{ DisplayName: "Postgres", Description: "Connect to Postgres.", ConfigProperties: []*drivers.PropertySpec{ { Key: "database_url", Secret: true, }, }, SourceProperties: []*drivers.PropertySpec{ { Key: "sql", Type: drivers.StringPropertyType, Required: true, DisplayName: "SQL", Description: "Query to extract data from Postgres.", Placeholder: "select * from table;", }, { Key: "database_url", Type: drivers.StringPropertyType, DisplayName: "Postgres Connection String", Required: false, DocsURL: "https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING", Placeholder: "postgresql://postgres:postgres@localhost:5432/postgres", Hint: "Either set this or pass --env connector.postgres.database_url=... to rill start", }, { Key: "name", Type: drivers.StringPropertyType, DisplayName: "Source name", Description: "The name of the source", Placeholder: "my_new_source", Required: true, }, }, ImplementsSQLStore: true, } type driver struct{} func (d driver) Open(instanceID string, config map[string]any, client *activity.Client, logger *zap.Logger) (drivers.Handle, error) { if instanceID == "" { return nil, errors.New("postgres driver can't be shared") } // actual db connection is opened during query return &connection{ config: config, }, nil } func (d driver) Spec() drivers.Spec { return spec } func (d driver) HasAnonymousSourceAccess(ctx context.Context, src map[string]any, logger *zap.Logger) (bool, error) { return false, nil } func (d driver) TertiarySourceConnectors(ctx context.Context, src map[string]any, logger *zap.Logger) ([]string, error) { return nil, nil } type connection struct { config map[string]any } // Ping implements drivers.Handle. func (c *connection) Ping(ctx context.Context) error { return drivers.ErrNotImplemented } // Migrate implements drivers.Connection. func (c *connection) Migrate(ctx context.Context) (err error) { return nil } // MigrationStatus implements drivers.Handle. func (c *connection) MigrationStatus(ctx context.Context) (current, desired int, err error) { return 0, 0, nil } // Driver implements drivers.Connection. func (c *connection) Driver() string { return "postgres" } // Config implements drivers.Connection. func (c *connection) Config() map[string]any { return c.config } // Close implements drivers.Connection. func (c *connection) Close() error { return nil } // AsRegistry implements drivers.Connection. func (c *connection) AsRegistry() (drivers.RegistryStore, bool) { return nil, false } // AsCatalogStore implements drivers.Connection. func (c *connection) AsCatalogStore(instanceID string) (drivers.CatalogStore, bool) { return nil, false } // AsRepoStore implements drivers.Connection. func (c *connection) AsRepoStore(instanceID string) (drivers.RepoStore, bool) { return nil, false } // AsAdmin implements drivers.Handle. func (c *connection) AsAdmin(instanceID string) (drivers.AdminService, bool) { return nil, false } // AsAI implements drivers.Handle. func (c *connection) AsAI(instanceID string) (drivers.AIService, bool) { return nil, false } // AsOLAP implements drivers.Connection. func (c *connection) AsOLAP(instanceID string) (drivers.OLAPStore, bool) { return nil, false } // AsObjectStore implements drivers.Connection. func (c *connection) AsObjectStore() (drivers.ObjectStore, bool) { return nil, false } // AsModelExecutor implements drivers.Handle. func (c *connection) AsModelExecutor(instanceID string, opts *drivers.ModelExecutorOptions) (drivers.ModelExecutor, bool) { return nil, false } // AsModelManager implements drivers.Handle. func (c *connection) AsModelManager(instanceID string) (drivers.ModelManager, bool) { return nil, false } // AsTransporter implements drivers.Connection. func (c *connection) AsTransporter(from, to drivers.Handle) (drivers.Transporter, bool) { return nil, false } // AsFileStore implements drivers.Connection. func (c *connection) AsFileStore() (drivers.FileStore, bool) { return nil, false } // AsWarehouse implements drivers.Handle. func (c *connection) AsWarehouse() (drivers.Warehouse, bool) { return nil, false } // AsSQLStore implements drivers.Connection. func (c *connection) AsSQLStore() (drivers.SQLStore, bool) { return c, true } // AsNotifier implements drivers.Connection. func (c *connection) AsNotifier(properties map[string]any) (drivers.Notifier, error) { return nil, drivers.ErrNotNotifier }