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

Table code generation with conditional export library #2950

Open
AlexandreAndrade00 opened this issue Apr 12, 2024 · 2 comments
Open

Table code generation with conditional export library #2950

AlexandreAndrade00 opened this issue Apr 12, 2024 · 2 comments
Labels
bug Something isn't working generator Affects the generator

Comments

@AlexandreAndrade00
Copy link

AlexandreAndrade00 commented Apr 12, 2024

This table:

import 'package:persistence/src/database/type_converters/tsid_type_converter.dart';

CREATE TABLE dynamic_tables (
    id INTEGER PRIMARY KEY MAPPED BY `const TsidTypeConverter()`,
    name TEXT(512) NOT NULL,
    permissions TEXT(512) NOT NULL,
    max_entries INTEGER NOT NULL,
    version INTEGER NOT NULL
);

Generates the following imports:

import 'package:drift/drift.dart' as i0;
import 'package:persistence/src/database/models/dynamic_database/dynamic_database.drift.dart'
    as i1;
import 'package:tsid_dart/src/tsid_stub.dart' as i2;
import 'package:persistence/src/database/type_converters/tsid_type_converter.dart'
    as i3;
import 'package:persistence/src/database/models/dynamic_database/dart_sql_type.dart'
    as i4;

Problem: In the third import, the code is accessing a private file instead of using the public library:

import 'package:tsid_dart/tsid_dart.dart';

https://pub.dev/packages/tsid_dart package:tsid_dart/tsid_dart.dart file :

export 'src/tsid_stub.dart'
    if (dart.library.io) 'src/tsid_default.dart'
    if (dart.library.html) 'src/tsid_web.dart';
export 'src/tsid_error.dart';
@AlexandreAndrade00 AlexandreAndrade00 changed the title Table code generation with conditional export property Table code generation with conditional export library Apr 12, 2024
@simolus3
Copy link
Owner

We're using the import that the analyzer gives us - I'll ask around if there's a way to get the import URI you've used that contributed the type instead of having to go directly to the definition.

It's probably not going to work right now, but we could add support for a workaround that let's you do something like

typedef MyId = Tsid;

class TsidTypeConverter extends TypeConverter<id, MyId> {...}

Then when drift sees that type it could reference MyId instead of the underlying type. That would fix the import problem, but it's also kind of hacky.

@simolus3 simolus3 added generator Affects the generator bug Something isn't working labels Apr 15, 2024
@AlexandreAndrade00
Copy link
Author

Thank you for the fast reply 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working generator Affects the generator
Projects
None yet
Development

No branches or pull requests

2 participants