drift icon indicating copy to clipboard operation
drift copied to clipboard

drift files: file formatting impossible

Open asdine opened this issue 8 months ago • 0 comments

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 avatar Jun 21 '24 15:06 asdine