1

I am trying to use flutter moor on my application. So after creating a column:

import 'package:moor_flutter/moor_flutter.dart';

@DataClassName("LocationTable")
class LocationTables extends Table {
  TextColumn get locationUuid => text()();
  RealColumn get latitude => real()();

Now I want to make locationUuid as index. So According it's official site I created a moor file to add index:

CREATE INDEX location_uuid_index ON LocationTables (locationUuid);

after that I added this file in db calss:

@UseMoor(include: {
  'index.moor'
}, tables: [
  UserTables,
  LocationTables,
], daos: [
  UserDao,

])
class Database extends _$Database {

But after run build runner:

pub run build_runner build --delete-conflicting-outputs

I got This error:

[WARNING] moor_generator:moor_generator on lib/database/database.dart:
line 3, column 37: Target table LocationTables could not be found.
  ╷
3 │ CREATE INDEX location_uuid_index ON LocationTables (locationUuid);

1 Answer 1

0

I find a solution. I put answer to help someone:

In moor file I have to write table name like this:

CREATE INDEX location_uuid_index ON location_tables (location_uuid);

and after that build runner was success.

And This added in database.g.dart:

abstract class _$Database extends GeneratedDatabase {
  _$Database(QueryExecutor e) : super(SqlTypeSystem.defaultInstance, e);
  $LocationTablesTable _locationTables;
  $LocationTablesTable get locationTables =>
      _locationTables ??= $LocationTablesTable(this);
  Index _locationUuidIndex;
  Index get locationUuidIndex => _locationUuidIndex ??= Index(
      'location_uuid_index',
      'CREATE INDEX location_uuid_index ON location_tables (locationUuid);');

Attention to :

  • location_tables

  • location_uuid

1
  • Hi, Is how does the 'locationUuidIndex' gets used when querying the moor table?
    – Braj
    Apr 9, 2021 at 6:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.