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

feat: assumeCorrectReference option resolves #2715 #2733

Merged
merged 6 commits into from
Nov 21, 2023

Conversation

Heinrich-vanNieuwenhuizen
Copy link
Contributor

@Heinrich-vanNieuwenhuizen Heinrich-vanNieuwenhuizen commented Nov 17, 2023

Summary
assumeCorrectReference option added
assume the correct reference of the dart code in views, when the resolver fails.

Description
This will allow the ability to use drift tables and dart views. The resolver cannot resolve references of the tables as it doesn't have any context of it yet.

But by coding ahead we know what those references are thus we can use type-safe views.

Example
build.yaml

targets:
  $default:
    builders:
      drift_dev:
        options:
          assume_correct_reference : true

descriptors.drift

CREATE TABLE [DESCRIPTORS](
	[DescriptorID] [int] NOT NULL PRIMARY KEY,
	[HierStrucID] [bigint] NULL,
	[DescType] [int] NULL,
	[LineNumber] [int] NULL,
	[StringNumberID] [bigint] NULL,
	[IsVisible] [bit] NULL,
	[IsDeleted] [bit] NULL,
	[OptionBits] [nvarchar](16) NULL);

string_table.drift

CREATE TABLE [STRING_TABLE](
	[StringID] [bigint] NOT NULL PRIMARY KEY,
	[StringNumberID] [bigint] NULL,
	[LangID] [int] NULL,
	[IsVisible] [bit] NOT NULL DEFAULT ((1)),
	[IsDeleted] [bit] NOT NULL DEFAULT ((0)),
	[HierStrucID] [bigint] NULL,
	[PosRef] [bigint] NULL,
	[StringText] [nvarchar](128) NULL
);

descriptor_view.dart

abstract class DescriptorView extends View {
  late final DatastoreDb attachedDatabase;
  IntColumn get descriptorID => attachedDatabase.descriptors.descriptorID;
  IntColumn get hierStrucID => attachedDatabase.descriptors.hierStrucID;
  IntColumn get descType => attachedDatabase.descriptors.descType;
  IntColumn get lineNumber => attachedDatabase.descriptors.lineNumber;
  RealColumn get isVisible => attachedDatabase.descriptors.isVisible;
  RealColumn get isDeleted => attachedDatabase.descriptors.isDeleted;
  TextColumn get optionBits => attachedDatabase.descriptors.optionBits;
  TextColumn get stringText => attachedDatabase.stringTable.stringText;

  @override
  Query as() => select([
    descriptorID,
    hierStrucID,
    descType,
    lineNumber,
    isVisible,
    isDeleted,
    optionBits,
    stringText
  ]).from(attachedDatabase.descriptors).join([
    innerJoin(
        attachedDatabase.stringTable,
        attachedDatabase.stringTable.stringNumberID
            .equalsExp(attachedDatabase.descriptors.stringNumberID)),
  ]);
}

assumeCorrectReference option added
assume the correct reference of the dart code in views, when resolver fails.
Copy link
Owner

@simolus3 simolus3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a big fan of this option since it essentially bypasses the analyzer, but I think we can have it for this specific use-cases since this used to work.

drift_dev/test/backends/build/build_integration_test.dart Outdated Show resolved Hide resolved
drift_dev/test/backends/build/build_integration_test.dart Outdated Show resolved Hide resolved
drift_dev/lib/src/analysis/results/view.dart Show resolved Hide resolved
drift_dev/lib/src/analysis/resolver/dart/view.dart Outdated Show resolved Hide resolved
drift_dev/lib/src/analysis/resolver/dart/view.dart Outdated Show resolved Hide resolved
Removed residual code and comments.
Commented and explained staticSource
Removed modularBuild and tested test
Copy link
Owner

@simolus3 simolus3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@simolus3 simolus3 merged commit 340462e into simolus3:develop Nov 21, 2023
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants