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

The non-abstract class is missing implementation #2800

Closed
bilalrabibi opened this issue Dec 21, 2023 · 2 comments
Closed

The non-abstract class is missing implementation #2800

bilalrabibi opened this issue Dec 21, 2023 · 2 comments

Comments

@bilalrabibi
Copy link

BUG

: Error: The non-abstract class '$UserJobsTable' is missing implementation
database.dart
// In database.dart

import 'package:drift/drift.dart';

import 'tables/JobConverter.dart';
import 'tables/PostTags.dart';
import 'tables/Posts.dart';
import 'tables/Profiles.dart';
import 'tables/Tags.dart';
import 'tables/Users.dart';
import 'tables/Job.dart';
import 'tables/UserJobs.dart';
part 'generated/database.g.dart';

@DriftDatabase(
  tables: [
    UserJobs,
    Users,
    Profiles,
    Posts,
    Tags,
    PostTags,
  ],
)
class ReflowLocalAppDatabase extends _$ReflowLocalAppDatabase {
  ReflowLocalAppDatabase(super.e);

  @override
  int get schemaVersion => 2;

  @override
  MigrationStrategy get migration => MigrationStrategy(
        onCreate: (Migrator m) => m.createAll(),
        onUpgrade: (Migrator m, int from, int to) async {
          if (from < 1) {
            await m.createTable(profiles);
          }
          if (from < 1) {
            await m.createTable(users);
          }
          if (from < 1) {
            await m.createTable(posts);
          }
          if (from < 1) {
            await m.createTable(tags);
          }
          if (from < 1) {
            await m.createTable(postTags);
          }
          if (from < 1) {
            await m.createTable(userJobs);
          }
        },
      );
}

Error

lib/src/features/experiments/experiments/local_database/services/db/generated/database.g.dart:214:7: Error: The non-abstract class '$UserJobsTable' is missing implementations for these members:
 - Table.blob
 - Table.boolean
 - Table.customConstraints
 - Table.customType
 - Table.dateTime
 - Table.dontWriteConstraints
 - Table.int64
 - Table.intEnum
 - Table.integer
 - Table.isStrict
 - Table.real
 - Table.tableName
 - Table.text
 - Table.textEnum
 - Table.withoutRowId
Try to either
 - provide an implementation,
 - inherit an implementation from a superclass or mixin,
 - mark the class as abstract, or
 - provide a 'noSuchMethod' implementation.

class $UserJobsTable extends UserJobs with TableInfo<$UserJobsTable, UserJobs> {
      ^^^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/drift-2.14.1/lib/src/dsl/table.dart:190:28: Context: 'Table.blob' is defined here.
  ColumnBuilder<Uint8List> blob() => _isGenerated();

This is the part of database.g.dart which is causing the issue

database.g.dart

class $UserJobsTable extends UserJobs with TableInfo<$UserJobsTable, UserJobs> {
  @override
  final GeneratedDatabase attachedDatabase;
  final String? _alias;
  $UserJobsTable(this.attachedDatabase, [this._alias]);
  static const VerificationMeta _idMeta = const VerificationMeta('id');
  @override
  late final GeneratedColumn<int> id = GeneratedColumn<int>(
      'id', aliasedName, false,
      hasAutoIncrement: true,
      type: DriftSqlType.int,
      requiredDuringInsert: false,
      defaultConstraints:
          GeneratedColumn.constraintIsAlways('PRIMARY KEY AUTOINCREMENT'));
  static const VerificationMeta _userIdMeta = const VerificationMeta('userId');
  @override
  late final GeneratedColumn<int> userId = GeneratedColumn<int>(
      'user_id', aliasedName, true,
      type: DriftSqlType.int,
      requiredDuringInsert: false,
      defaultConstraints:
          GeneratedColumn.constraintIsAlways('REFERENCES users (id)'));
  static const VerificationMeta _jobsMeta = const VerificationMeta('jobs');
  @override
  late final GeneratedColumnWithTypeConverter<List<Job>, String> jobs =
      GeneratedColumn<String>('jobs', aliasedName, false,
              type: DriftSqlType.string, requiredDuringInsert: true)
          .withConverter<List<Job>>($UserJobsTable.$converterjobs);
  @override
  List<GeneratedColumn> get $columns => [id, userId, jobs];
  @override
  String get aliasedName => _alias ?? actualTableName;
  @override
  String get actualTableName => $name;
  static const String $name = 'user_jobs';
  @override
  VerificationContext validateIntegrity(Insertable<UserJobs> instance,
      {bool isInserting = false}) {
    final context = VerificationContext();
    final data = instance.toColumns(true);
    if (data.containsKey('id')) {
      context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta));
    }
    if (data.containsKey('user_id')) {
      context.handle(_userIdMeta,
          userId.isAcceptableOrUnknown(data['user_id']!, _userIdMeta));
    }
    context.handle(_jobsMeta, const VerificationResult.success());
    return context;
  }
@simolus3
Copy link
Owner

The problem is this DataClassName annotation:

@DataClassName('UserJobs')
class UserJobs extends Table {

Drift will generate three classes for each table:

  1. A data/row class holding a full row of the table in the database.
  2. A companion class holding a partial row, used for updates and inserts.
  3. A hidden table class used by drift to inspect the schema at runtime, used to construct SQL statements and for migration APIs.

The third class needs to extend your existing UserJobs class describing the table. But with the DataClassName annotation, you're telling drift that the name of the first class to generate should be UserJobs as well. So you end up with two identically named classes which is invalid and causes all kinds of errors.

The solution is to either rename the table class (e.g. class UserJobsTable), or to use a different data class name.

@bilalrabibi
Copy link
Author

Many thanks for your response. the issue is resolved the issue.

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

No branches or pull requests

2 participants