Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drift files: file formatting impossible #3057

Open
asdine opened this issue Jun 21, 2024 · 0 comments
Open

drift files: file formatting impossible #3057

asdine opened this issue Jun 21, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@asdine
Copy link

asdine commented Jun 21, 2024

The drift files are a very convenient way of maintaining SQL queries but because the syntax is not exactly SQL, the IDE formatters (VS Code, Goland, etc.) can't work properly and format the file and / or show syntax errors.
This hinders productivity and can be a source of frustration sometimes.

Proposal

sqlc uses a slightly different approach, where metadata is written as a valid SQL comment instead.

-- name: GetAuthor :one
SELECT * FROM authors
WHERE id = $1;

I propose to add the support for something equivalent, without breaking compatibility.

-- import 'status.dart';

-- createEntry:
INSERT INTO todos (title, content) VALUES (:title, :content);

-- deleteById:
DELETE FROM todos WHERE id = :id;

-- myQuery(:variable AS TEXT): 
SELECT :variable;

-- normal comments are still ignored

-- current syntax still works
getTodos ($predicate = TRUE):
SELECT * FROM todos WHERE $predicate;

The parsing rule for queries would be something like:

  • the comment must end with :
  • the comment is followed by a query

The parsing rule for imports would be:

  • the comment must start with import and satisfy the current import parsing rule
@asdine asdine added the enhancement New feature or request label Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant