Skip to content

Commit

Permalink
Kick off data sources service
Browse files Browse the repository at this point in the history
This service will contain all the business logic to deal with data
sources.

Signed-off-by: Juan Antonio Osorio <[email protected]>
  • Loading branch information
JAORMX committed Nov 21, 2024
1 parent 64aec6a commit 5e93fb8
Show file tree
Hide file tree
Showing 7 changed files with 1,007 additions and 0 deletions.
150 changes: 150 additions & 0 deletions database/mock/store.go

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

73 changes: 73 additions & 0 deletions database/query/datasources.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
-- CreateDataSource creates a new datasource in a given project.

-- name: CreateDataSource :one
INSERT INTO data_sources (project_id, name, display_name)
VALUES ($1, $2, $3) RETURNING *;

-- AddDataSourceFunction adds a function to a datasource.

-- name: AddDataSourceFunction :one
INSERT INTO data_sources_functions (data_source_id, name, type, definition)
VALUES ($1, $2, $3, $4) RETURNING *;

-- UpdateDataSource updates a datasource in a given project.

-- name: UpdateDataSource :one
UPDATE data_sources
SET display_name = $3
WHERE id = $1 AND project_id = $2
RETURNING *;

-- UpdateDataSourceFunction updates a function in a datasource. We're
-- only able to update the type and definition of the function.

-- name: UpdateDataSourceFunction :one
UPDATE data_sources_functions
SET type = $3, definition = $4, updated_at = NOW()
WHERE data_source_id = $1 AND name = $2
RETURNING *;

-- name: DeleteDataSource :one
DELETE FROM data_sources
WHERE id = $1 AND project_id = $2
RETURNING *;

-- name: DeleteDataSourceFunction :one
DELETE FROM data_sources_functions
WHERE data_source_id = $1 AND name = $2
RETURNING *;

-- GetDataSource retrieves a datasource by its id and a project hierarchy.
--
-- Note that to get a datasource for a given project, one can simply
-- pass one project id in the project_id array.

-- name: GetDataSource :one
SELECT * FROM data_sources
WHERE id = $1 AND project_id = ANY(sqlc.arg(projects)::uuid[]);

-- GetDataSourceByName retrieves a datasource by its name and
-- a project hierarchy.
--
-- Note that to get a datasource for a given project, one can simply
-- pass one project id in the project_id array.

-- name: GetDataSourceByName :one
SELECT * FROM data_sources
WHERE name = $1 AND project_id = ANY(sqlc.arg(projects)::uuid[]);

-- ListDataSources retrieves all datasources for project hierarchy.
--
-- Note that to get a datasource for a given project, one can simply
-- pass one project id in the project_id array.

-- name: ListDataSources :many
SELECT * FROM data_sources
WHERE project_id = ANY(sqlc.arg(projects)::uuid[]);

-- ListDataSourceFunctions retrieves all functions for a datasource.

-- name: ListDataSourceFunctions :many
SELECT * FROM data_sources_functions
WHERE data_source_id = $1;

Loading

0 comments on commit 5e93fb8

Please sign in to comment.