mirror of https://github.com/AMT-Cheif/drift.git
Support triggers and indices in modular generation
This commit is contained in:
parent
df76457819
commit
fde7adde48
|
@ -23,11 +23,10 @@ class ModularAccessor extends DatabaseAccessor<GeneratedDatabase> {
|
|||
return attachedDatabase.resultSet(name);
|
||||
}
|
||||
|
||||
/// Find an accessor by its [name] in the database, or create it with
|
||||
/// [create]. The result will be cached.
|
||||
T accessor<T extends DatabaseAccessor>(
|
||||
String name, T Function(GeneratedDatabase) create) {
|
||||
return attachedDatabase.accessor<T>(name, create);
|
||||
/// Find an accessor type, or create it with [create]. The result will be
|
||||
/// cached.
|
||||
T accessor<T extends DatabaseAccessor>(T Function(GeneratedDatabase) create) {
|
||||
return attachedDatabase.accessor<T>(create);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,17 +45,16 @@ extension ReadDatabaseContainer on GeneratedDatabase {
|
|||
|
||||
/// Find an accessor by its [name] in the database, or create it with
|
||||
/// [create]. The result will be cached.
|
||||
T accessor<T extends DatabaseAccessor>(
|
||||
String name, T Function(GeneratedDatabase) create) {
|
||||
T accessor<T extends DatabaseAccessor>(T Function(GeneratedDatabase) create) {
|
||||
final cache = _cache.knownAccessors;
|
||||
|
||||
return cache.putIfAbsent(name, () => create(attachedDatabase)) as T;
|
||||
return cache.putIfAbsent(T, () => create(attachedDatabase)) as T;
|
||||
}
|
||||
}
|
||||
|
||||
class _DatabaseElementCache {
|
||||
final Map<String, DatabaseSchemaEntity> knownEntities;
|
||||
final Map<String, DatabaseAccessor> knownAccessors = {};
|
||||
final Map<Type, DatabaseAccessor> knownAccessors = {};
|
||||
|
||||
_DatabaseElementCache(GeneratedDatabase database)
|
||||
: knownEntities = {
|
||||
|
|
|
@ -197,6 +197,14 @@ class _DriftBuildRun {
|
|||
}
|
||||
}
|
||||
|
||||
if (mode == DriftGenerationMode.modular &&
|
||||
buildStep.inputId.extension != '.dart') {
|
||||
// For modular drift file generation, we need to know about imports which
|
||||
// are only available when discovery ran.
|
||||
await driver.prepareFileForAnalysis(buildStep.inputId.uri,
|
||||
needsDiscovery: true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -231,6 +239,18 @@ class _DriftBuildRun {
|
|||
TableWriter(result, writer.child()).writeInto();
|
||||
} else if (result is DriftView) {
|
||||
ViewWriter(result, writer.child(), null).write();
|
||||
} else if (result is DriftTrigger) {
|
||||
writer.leaf()
|
||||
..writeDriftRef('Trigger')
|
||||
..write(' get ${result.dbGetterName} => ')
|
||||
..write(DatabaseWriter.createTrigger(writer.child(), result))
|
||||
..writeln(';');
|
||||
} else if (result is DriftIndex) {
|
||||
writer.leaf()
|
||||
..writeDriftRef('Index')
|
||||
..write(' get ${result.dbGetterName} => ')
|
||||
..write(DatabaseWriter.createIndex(writer.child(), result))
|
||||
..writeln(';');
|
||||
} else if (result is DriftDatabase) {
|
||||
final resolved =
|
||||
entrypointState.fileAnalysis!.resolvedDatabases[result.id]!;
|
||||
|
|
|
@ -74,7 +74,19 @@ class DatabaseWriter {
|
|||
|
||||
for (final entity in elements.whereType<DriftSchemaElement>()) {
|
||||
final getterName = entity.dbGetterName;
|
||||
|
||||
if (getterName != null) {
|
||||
// In the modular generation mode, table and view instances are still
|
||||
// created in the database instance. However, triggers and indices are
|
||||
// generated as a top-level field which is simply imported.
|
||||
if (scope.generationOptions.isModular &&
|
||||
(entity is DriftTrigger || entity is DriftIndex)) {
|
||||
final import = dbScope.generatedElement(entity, getterName);
|
||||
|
||||
entityGetters[entity] = dbScope.dartCode(import);
|
||||
continue;
|
||||
}
|
||||
|
||||
entityGetters[entity] = getterName;
|
||||
}
|
||||
|
||||
|
@ -88,24 +100,18 @@ class DatabaseWriter {
|
|||
code: '$tableClassName(this)',
|
||||
);
|
||||
} else if (entity is DriftTrigger) {
|
||||
final sql = scope.sqlCode(entity.parsedStatement!);
|
||||
|
||||
writeMemoizedGetter(
|
||||
buffer: dbScope.leaf().buffer,
|
||||
getterName: entity.dbGetterName,
|
||||
returnType: 'Trigger',
|
||||
code: 'Trigger(${asDartLiteral(sql)}, '
|
||||
'${asDartLiteral(entity.schemaName)})',
|
||||
code: createTrigger(dbScope, entity),
|
||||
);
|
||||
} else if (entity is DriftIndex) {
|
||||
final sql = scope.sqlCode(entity.parsedStatement!);
|
||||
|
||||
writeMemoizedGetter(
|
||||
buffer: dbScope.leaf().buffer,
|
||||
getterName: entity.dbGetterName,
|
||||
returnType: 'Index',
|
||||
code: 'Index(${asDartLiteral(entity.schemaName)}, '
|
||||
'${asDartLiteral(sql)})',
|
||||
code: createIndex(scope, entity),
|
||||
);
|
||||
} else if (entity is DriftView) {
|
||||
writeMemoizedGetter(
|
||||
|
@ -145,7 +151,7 @@ class DatabaseWriter {
|
|||
ModularAccessorWriter.modularSupport, 'ReadDatabaseContainer')
|
||||
..writeln('(this).accessor<')
|
||||
..writeDart(type)
|
||||
..write('>(${asDartLiteral(import.ownUri.toString())}, ')
|
||||
..write('>(')
|
||||
..writeDart(type)
|
||||
..writeln('.new);');
|
||||
}
|
||||
|
@ -191,15 +197,17 @@ class DatabaseWriter {
|
|||
FindStreamUpdateRules(input.resolvedAccessor).identifyRules();
|
||||
if (updateRules.rules.isNotEmpty) {
|
||||
schemaScope
|
||||
..write('@override\nStreamQueryUpdateRules get streamUpdateRules => ')
|
||||
..write('const StreamQueryUpdateRules([');
|
||||
..writeln('@override')
|
||||
..writeDriftRef('StreamQueryUpdateRules')
|
||||
..write(' get streamUpdateRules => const ')
|
||||
..writeDriftRef('StreamQueryUpdateRules([');
|
||||
|
||||
for (final rule in updateRules.rules) {
|
||||
rule.writeConstructor(schemaScope);
|
||||
schemaScope.write(', ');
|
||||
}
|
||||
|
||||
schemaScope.write('],);\n');
|
||||
schemaScope.writeln('],);');
|
||||
}
|
||||
|
||||
if (scope.generationOptions.isGeneratingForSchema) {
|
||||
|
@ -223,6 +231,20 @@ class DatabaseWriter {
|
|||
// close the class
|
||||
schemaScope.write('}\n');
|
||||
}
|
||||
|
||||
static String createTrigger(Scope scope, DriftTrigger entity) {
|
||||
final sql = scope.sqlCode(entity.parsedStatement!);
|
||||
final trigger = scope.drift('Trigger');
|
||||
|
||||
return '$trigger(${asDartLiteral(sql)}, ${asDartLiteral(entity.schemaName)})';
|
||||
}
|
||||
|
||||
static String createIndex(Scope scope, DriftIndex entity) {
|
||||
final sql = scope.sqlCode(entity.parsedStatement!);
|
||||
final index = scope.drift('Index');
|
||||
|
||||
return '$index(${asDartLiteral(entity.schemaName)}, ${asDartLiteral(sql)})';
|
||||
}
|
||||
}
|
||||
|
||||
class GenerationInput<T extends BaseDriftAccessor> {
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
import 'package:path/path.dart' show url;
|
||||
import 'package:recase/recase.dart';
|
||||
|
||||
import '../analysis/driver/state.dart';
|
||||
import '../analysis/results/results.dart';
|
||||
import '../utils/string_escaper.dart';
|
||||
|
@ -59,6 +62,21 @@ class ModularAccessorWriter {
|
|||
}
|
||||
}
|
||||
|
||||
// Also make imports available
|
||||
final imports = file.discovery?.importDependencies ?? const [];
|
||||
for (final import in imports) {
|
||||
if (url.extension(import.path) == '.drift') {
|
||||
final moduleClass = restOfClass.modularAccessor(import);
|
||||
final getterName = ReCase(moduleClass.toString()).camelCase;
|
||||
|
||||
restOfClass
|
||||
..writeDart(moduleClass)
|
||||
..write(' get $getterName => this.accessor(')
|
||||
..writeDart(moduleClass)
|
||||
..writeln('.new);');
|
||||
}
|
||||
}
|
||||
|
||||
restOfClass.writeln('}');
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ class Writer extends _NodeOrWriter {
|
|||
abstract class _NodeOrWriter {
|
||||
Writer get writer;
|
||||
|
||||
AnnotatedDartCode _generatedElement(DriftElement element, String dartName) {
|
||||
AnnotatedDartCode generatedElement(DriftElement element, String dartName) {
|
||||
if (writer.generationOptions.isModular) {
|
||||
return AnnotatedDartCode([
|
||||
DartTopLevelSymbol(dartName, element.id.modularImportUri),
|
||||
|
@ -81,11 +81,11 @@ abstract class _NodeOrWriter {
|
|||
? table.nameOfRowClass
|
||||
: table.baseDartName;
|
||||
|
||||
return _generatedElement(table, '${baseName}Companion');
|
||||
return generatedElement(table, '${baseName}Companion');
|
||||
}
|
||||
|
||||
AnnotatedDartCode entityInfoType(DriftElementWithResultSet element) {
|
||||
return _generatedElement(element, element.entityInfoName);
|
||||
return generatedElement(element, element.entityInfoName);
|
||||
}
|
||||
|
||||
AnnotatedDartCode rowType(DriftElementWithResultSet element) {
|
||||
|
@ -93,7 +93,7 @@ abstract class _NodeOrWriter {
|
|||
if (existing != null) {
|
||||
return existing.targetType;
|
||||
} else {
|
||||
return _generatedElement(element, element.nameOfRowClass);
|
||||
return generatedElement(element, element.nameOfRowClass);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ abstract class _NodeOrWriter {
|
|||
if (existing != null) {
|
||||
return existing.targetClass;
|
||||
} else {
|
||||
return _generatedElement(element, element.nameOfRowClass);
|
||||
return generatedElement(element, element.nameOfRowClass);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,5 +6,14 @@ targets:
|
|||
|
||||
drift_dev:analyzer:
|
||||
enabled: true
|
||||
options: &options
|
||||
store_date_time_values_as_text: true
|
||||
named_parameters: true
|
||||
sql:
|
||||
dialect: sqlite
|
||||
options:
|
||||
version: "3.39"
|
||||
modules: [fts5]
|
||||
drift_dev:modular:
|
||||
enabled: true
|
||||
options: *options
|
||||
|
|
|
@ -2,7 +2,11 @@ import 'package:drift/drift.dart';
|
|||
|
||||
import 'database.drift.dart';
|
||||
|
||||
@DriftDatabase(include: {'src/users.drift'})
|
||||
@DriftDatabase(include: {
|
||||
'src/users.drift',
|
||||
'src/posts.drift',
|
||||
'src/search.drift',
|
||||
})
|
||||
class Database extends $Database {
|
||||
Database(super.e);
|
||||
|
||||
|
|
|
@ -1,17 +1,61 @@
|
|||
// ignore_for_file: type=lint
|
||||
import 'package:drift/drift.dart' as i0;
|
||||
import 'package:modular/src/users.drift.dart' as i1;
|
||||
import 'package:drift/internal/modular.dart' as i2;
|
||||
import 'package:modular/src/posts.drift.dart' as i2;
|
||||
import 'package:modular/src/search.drift.dart' as i3;
|
||||
import 'package:drift/internal/modular.dart' as i4;
|
||||
|
||||
abstract class $Database extends i0.GeneratedDatabase {
|
||||
$Database(i0.QueryExecutor e) : super(e);
|
||||
late final i1.Users users = i1.Users(this);
|
||||
late final i2.Posts posts = i2.Posts(this);
|
||||
late final i3.SearchInPosts searchInPosts = i3.SearchInPosts(this);
|
||||
late final i2.Likes likes = i2.Likes(this);
|
||||
late final i1.Follows follows = i1.Follows(this);
|
||||
i1.UsersDrift get usersDrift =>
|
||||
i2.ReadDatabaseContainer(this).accessor<i1.UsersDrift>(
|
||||
'package:modular/src/users.drift', i1.UsersDrift.new);
|
||||
i4.ReadDatabaseContainer(this).accessor<i1.UsersDrift>(i1.UsersDrift.new);
|
||||
@override
|
||||
Iterable<i0.TableInfo<i0.Table, Object?>> get allTables =>
|
||||
allSchemaEntities.whereType<i0.TableInfo<i0.Table, Object?>>();
|
||||
@override
|
||||
List<i0.DatabaseSchemaEntity> get allSchemaEntities => [users];
|
||||
List<i0.DatabaseSchemaEntity> get allSchemaEntities => [
|
||||
users,
|
||||
posts,
|
||||
searchInPosts,
|
||||
i3.postsInsert,
|
||||
i3.postsUpdate,
|
||||
i3.postsDelete,
|
||||
likes,
|
||||
follows
|
||||
];
|
||||
@override
|
||||
i0.StreamQueryUpdateRules get streamUpdateRules =>
|
||||
const i0.StreamQueryUpdateRules(
|
||||
[
|
||||
i0.WritePropagation(
|
||||
on: i0.TableUpdateQuery.onTableName('posts',
|
||||
limitUpdateKind: i0.UpdateKind.insert),
|
||||
result: [
|
||||
i0.TableUpdate('search_in_posts', kind: i0.UpdateKind.insert),
|
||||
],
|
||||
),
|
||||
i0.WritePropagation(
|
||||
on: i0.TableUpdateQuery.onTableName('posts',
|
||||
limitUpdateKind: i0.UpdateKind.update),
|
||||
result: [
|
||||
i0.TableUpdate('search_in_posts', kind: i0.UpdateKind.insert),
|
||||
],
|
||||
),
|
||||
i0.WritePropagation(
|
||||
on: i0.TableUpdateQuery.onTableName('posts',
|
||||
limitUpdateKind: i0.UpdateKind.delete),
|
||||
result: [
|
||||
i0.TableUpdate('search_in_posts', kind: i0.UpdateKind.insert),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
@override
|
||||
i0.DriftDatabaseOptions get options =>
|
||||
const i0.DriftDatabaseOptions(storeDateTimeAsText: true);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
import 'users.drift';
|
||||
|
||||
CREATE TABLE posts (
|
||||
id INTEGER PRIMARY KEY,
|
||||
author INTEGER NOT NULL REFERENCES users (id),
|
||||
content TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE likes (
|
||||
post INTEGER NOT NULL REFERENCES posts (id),
|
||||
liked_by INTEGER NOT NULL REFERENCES users (id)
|
||||
);
|
|
@ -0,0 +1,403 @@
|
|||
// ignore_for_file: type=lint
|
||||
import 'package:drift/drift.dart' as i0;
|
||||
import 'package:modular/src/posts.drift.dart' as i1;
|
||||
import 'package:drift/internal/modular.dart' as i2;
|
||||
import 'package:modular/src/users.drift.dart' as i3;
|
||||
|
||||
class Post extends i0.DataClass implements i0.Insertable<i1.Post> {
|
||||
final int id;
|
||||
final int author;
|
||||
final String? content;
|
||||
const Post({required this.id, required this.author, this.content});
|
||||
@override
|
||||
Map<String, i0.Expression> toColumns(bool nullToAbsent) {
|
||||
final map = <String, i0.Expression>{};
|
||||
map['id'] = i0.Variable<int>(id);
|
||||
map['author'] = i0.Variable<int>(author);
|
||||
if (!nullToAbsent || content != null) {
|
||||
map['content'] = i0.Variable<String>(content);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
i1.PostsCompanion toCompanion(bool nullToAbsent) {
|
||||
return i1.PostsCompanion(
|
||||
id: i0.Value(id),
|
||||
author: i0.Value(author),
|
||||
content: content == null && nullToAbsent
|
||||
? const i0.Value.absent()
|
||||
: i0.Value(content),
|
||||
);
|
||||
}
|
||||
|
||||
factory Post.fromJson(Map<String, dynamic> json,
|
||||
{i0.ValueSerializer? serializer}) {
|
||||
serializer ??= i0.driftRuntimeOptions.defaultSerializer;
|
||||
return Post(
|
||||
id: serializer.fromJson<int>(json['id']),
|
||||
author: serializer.fromJson<int>(json['author']),
|
||||
content: serializer.fromJson<String?>(json['content']),
|
||||
);
|
||||
}
|
||||
@override
|
||||
Map<String, dynamic> toJson({i0.ValueSerializer? serializer}) {
|
||||
serializer ??= i0.driftRuntimeOptions.defaultSerializer;
|
||||
return <String, dynamic>{
|
||||
'id': serializer.toJson<int>(id),
|
||||
'author': serializer.toJson<int>(author),
|
||||
'content': serializer.toJson<String?>(content),
|
||||
};
|
||||
}
|
||||
|
||||
i1.Post copyWith(
|
||||
{int? id,
|
||||
int? author,
|
||||
i0.Value<String?> content = const i0.Value.absent()}) =>
|
||||
i1.Post(
|
||||
id: id ?? this.id,
|
||||
author: author ?? this.author,
|
||||
content: content.present ? content.value : this.content,
|
||||
);
|
||||
@override
|
||||
String toString() {
|
||||
return (StringBuffer('Post(')
|
||||
..write('id: $id, ')
|
||||
..write('author: $author, ')
|
||||
..write('content: $content')
|
||||
..write(')'))
|
||||
.toString();
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(id, author, content);
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
(other is i1.Post &&
|
||||
other.id == this.id &&
|
||||
other.author == this.author &&
|
||||
other.content == this.content);
|
||||
}
|
||||
|
||||
class PostsCompanion extends i0.UpdateCompanion<i1.Post> {
|
||||
final i0.Value<int> id;
|
||||
final i0.Value<int> author;
|
||||
final i0.Value<String?> content;
|
||||
const PostsCompanion({
|
||||
this.id = const i0.Value.absent(),
|
||||
this.author = const i0.Value.absent(),
|
||||
this.content = const i0.Value.absent(),
|
||||
});
|
||||
PostsCompanion.insert({
|
||||
this.id = const i0.Value.absent(),
|
||||
required int author,
|
||||
this.content = const i0.Value.absent(),
|
||||
}) : author = i0.Value(author);
|
||||
static i0.Insertable<i1.Post> custom({
|
||||
i0.Expression<int>? id,
|
||||
i0.Expression<int>? author,
|
||||
i0.Expression<String>? content,
|
||||
}) {
|
||||
return i0.RawValuesInsertable({
|
||||
if (id != null) 'id': id,
|
||||
if (author != null) 'author': author,
|
||||
if (content != null) 'content': content,
|
||||
});
|
||||
}
|
||||
|
||||
i1.PostsCompanion copyWith(
|
||||
{i0.Value<int>? id, i0.Value<int>? author, i0.Value<String?>? content}) {
|
||||
return i1.PostsCompanion(
|
||||
id: id ?? this.id,
|
||||
author: author ?? this.author,
|
||||
content: content ?? this.content,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, i0.Expression> toColumns(bool nullToAbsent) {
|
||||
final map = <String, i0.Expression>{};
|
||||
if (id.present) {
|
||||
map['id'] = i0.Variable<int>(id.value);
|
||||
}
|
||||
if (author.present) {
|
||||
map['author'] = i0.Variable<int>(author.value);
|
||||
}
|
||||
if (content.present) {
|
||||
map['content'] = i0.Variable<String>(content.value);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return (StringBuffer('i1.PostsCompanion(')
|
||||
..write('id: $id, ')
|
||||
..write('author: $author, ')
|
||||
..write('content: $content')
|
||||
..write(')'))
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
||||
class Posts extends i0.Table with i0.TableInfo<Posts, i1.Post> {
|
||||
@override
|
||||
final i0.GeneratedDatabase attachedDatabase;
|
||||
final String? _alias;
|
||||
Posts(this.attachedDatabase, [this._alias]);
|
||||
static const i0.VerificationMeta _idMeta = const i0.VerificationMeta('id');
|
||||
late final i0.GeneratedColumn<int> id = i0.GeneratedColumn<int>(
|
||||
'id', aliasedName, false,
|
||||
type: i0.DriftSqlType.int,
|
||||
requiredDuringInsert: false,
|
||||
$customConstraints: 'PRIMARY KEY');
|
||||
static const i0.VerificationMeta _authorMeta =
|
||||
const i0.VerificationMeta('author');
|
||||
late final i0.GeneratedColumn<int> author = i0.GeneratedColumn<int>(
|
||||
'author', aliasedName, false,
|
||||
type: i0.DriftSqlType.int,
|
||||
requiredDuringInsert: true,
|
||||
$customConstraints: 'NOT NULL REFERENCES users(id)');
|
||||
static const i0.VerificationMeta _contentMeta =
|
||||
const i0.VerificationMeta('content');
|
||||
late final i0.GeneratedColumn<String> content = i0.GeneratedColumn<String>(
|
||||
'content', aliasedName, true,
|
||||
type: i0.DriftSqlType.string,
|
||||
requiredDuringInsert: false,
|
||||
$customConstraints: '');
|
||||
@override
|
||||
List<i0.GeneratedColumn> get $columns => [id, author, content];
|
||||
@override
|
||||
String get aliasedName => _alias ?? 'posts';
|
||||
@override
|
||||
String get actualTableName => 'posts';
|
||||
@override
|
||||
i0.VerificationContext validateIntegrity(i0.Insertable<i1.Post> instance,
|
||||
{bool isInserting = false}) {
|
||||
final context = i0.VerificationContext();
|
||||
final data = instance.toColumns(true);
|
||||
if (data.containsKey('id')) {
|
||||
context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta));
|
||||
}
|
||||
if (data.containsKey('author')) {
|
||||
context.handle(_authorMeta,
|
||||
author.isAcceptableOrUnknown(data['author']!, _authorMeta));
|
||||
} else if (isInserting) {
|
||||
context.missing(_authorMeta);
|
||||
}
|
||||
if (data.containsKey('content')) {
|
||||
context.handle(_contentMeta,
|
||||
content.isAcceptableOrUnknown(data['content']!, _contentMeta));
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
@override
|
||||
Set<i0.GeneratedColumn> get $primaryKey => {id};
|
||||
@override
|
||||
i1.Post map(Map<String, dynamic> data, {String? tablePrefix}) {
|
||||
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';
|
||||
return i1.Post(
|
||||
id: attachedDatabase.typeMapping
|
||||
.read(i0.DriftSqlType.int, data['${effectivePrefix}id'])!,
|
||||
author: attachedDatabase.typeMapping
|
||||
.read(i0.DriftSqlType.int, data['${effectivePrefix}author'])!,
|
||||
content: attachedDatabase.typeMapping
|
||||
.read(i0.DriftSqlType.string, data['${effectivePrefix}content']),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Posts createAlias(String alias) {
|
||||
return Posts(attachedDatabase, alias);
|
||||
}
|
||||
|
||||
@override
|
||||
List<String> get customConstraints => const [];
|
||||
@override
|
||||
bool get dontWriteConstraints => true;
|
||||
}
|
||||
|
||||
class Like extends i0.DataClass implements i0.Insertable<i1.Like> {
|
||||
final int post;
|
||||
final int likedBy;
|
||||
const Like({required this.post, required this.likedBy});
|
||||
@override
|
||||
Map<String, i0.Expression> toColumns(bool nullToAbsent) {
|
||||
final map = <String, i0.Expression>{};
|
||||
map['post'] = i0.Variable<int>(post);
|
||||
map['liked_by'] = i0.Variable<int>(likedBy);
|
||||
return map;
|
||||
}
|
||||
|
||||
i1.LikesCompanion toCompanion(bool nullToAbsent) {
|
||||
return i1.LikesCompanion(
|
||||
post: i0.Value(post),
|
||||
likedBy: i0.Value(likedBy),
|
||||
);
|
||||
}
|
||||
|
||||
factory Like.fromJson(Map<String, dynamic> json,
|
||||
{i0.ValueSerializer? serializer}) {
|
||||
serializer ??= i0.driftRuntimeOptions.defaultSerializer;
|
||||
return Like(
|
||||
post: serializer.fromJson<int>(json['post']),
|
||||
likedBy: serializer.fromJson<int>(json['liked_by']),
|
||||
);
|
||||
}
|
||||
@override
|
||||
Map<String, dynamic> toJson({i0.ValueSerializer? serializer}) {
|
||||
serializer ??= i0.driftRuntimeOptions.defaultSerializer;
|
||||
return <String, dynamic>{
|
||||
'post': serializer.toJson<int>(post),
|
||||
'liked_by': serializer.toJson<int>(likedBy),
|
||||
};
|
||||
}
|
||||
|
||||
i1.Like copyWith({int? post, int? likedBy}) => i1.Like(
|
||||
post: post ?? this.post,
|
||||
likedBy: likedBy ?? this.likedBy,
|
||||
);
|
||||
@override
|
||||
String toString() {
|
||||
return (StringBuffer('Like(')
|
||||
..write('post: $post, ')
|
||||
..write('likedBy: $likedBy')
|
||||
..write(')'))
|
||||
.toString();
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(post, likedBy);
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
(other is i1.Like &&
|
||||
other.post == this.post &&
|
||||
other.likedBy == this.likedBy);
|
||||
}
|
||||
|
||||
class LikesCompanion extends i0.UpdateCompanion<i1.Like> {
|
||||
final i0.Value<int> post;
|
||||
final i0.Value<int> likedBy;
|
||||
const LikesCompanion({
|
||||
this.post = const i0.Value.absent(),
|
||||
this.likedBy = const i0.Value.absent(),
|
||||
});
|
||||
LikesCompanion.insert({
|
||||
required int post,
|
||||
required int likedBy,
|
||||
}) : post = i0.Value(post),
|
||||
likedBy = i0.Value(likedBy);
|
||||
static i0.Insertable<i1.Like> custom({
|
||||
i0.Expression<int>? post,
|
||||
i0.Expression<int>? likedBy,
|
||||
}) {
|
||||
return i0.RawValuesInsertable({
|
||||
if (post != null) 'post': post,
|
||||
if (likedBy != null) 'liked_by': likedBy,
|
||||
});
|
||||
}
|
||||
|
||||
i1.LikesCompanion copyWith({i0.Value<int>? post, i0.Value<int>? likedBy}) {
|
||||
return i1.LikesCompanion(
|
||||
post: post ?? this.post,
|
||||
likedBy: likedBy ?? this.likedBy,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, i0.Expression> toColumns(bool nullToAbsent) {
|
||||
final map = <String, i0.Expression>{};
|
||||
if (post.present) {
|
||||
map['post'] = i0.Variable<int>(post.value);
|
||||
}
|
||||
if (likedBy.present) {
|
||||
map['liked_by'] = i0.Variable<int>(likedBy.value);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return (StringBuffer('i1.LikesCompanion(')
|
||||
..write('post: $post, ')
|
||||
..write('likedBy: $likedBy')
|
||||
..write(')'))
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
||||
class Likes extends i0.Table with i0.TableInfo<Likes, i1.Like> {
|
||||
@override
|
||||
final i0.GeneratedDatabase attachedDatabase;
|
||||
final String? _alias;
|
||||
Likes(this.attachedDatabase, [this._alias]);
|
||||
static const i0.VerificationMeta _postMeta =
|
||||
const i0.VerificationMeta('post');
|
||||
late final i0.GeneratedColumn<int> post = i0.GeneratedColumn<int>(
|
||||
'post', aliasedName, false,
|
||||
type: i0.DriftSqlType.int,
|
||||
requiredDuringInsert: true,
|
||||
$customConstraints: 'NOT NULL REFERENCES posts(id)');
|
||||
static const i0.VerificationMeta _likedByMeta =
|
||||
const i0.VerificationMeta('likedBy');
|
||||
late final i0.GeneratedColumn<int> likedBy = i0.GeneratedColumn<int>(
|
||||
'liked_by', aliasedName, false,
|
||||
type: i0.DriftSqlType.int,
|
||||
requiredDuringInsert: true,
|
||||
$customConstraints: 'NOT NULL REFERENCES users(id)');
|
||||
@override
|
||||
List<i0.GeneratedColumn> get $columns => [post, likedBy];
|
||||
@override
|
||||
String get aliasedName => _alias ?? 'likes';
|
||||
@override
|
||||
String get actualTableName => 'likes';
|
||||
@override
|
||||
i0.VerificationContext validateIntegrity(i0.Insertable<i1.Like> instance,
|
||||
{bool isInserting = false}) {
|
||||
final context = i0.VerificationContext();
|
||||
final data = instance.toColumns(true);
|
||||
if (data.containsKey('post')) {
|
||||
context.handle(
|
||||
_postMeta, post.isAcceptableOrUnknown(data['post']!, _postMeta));
|
||||
} else if (isInserting) {
|
||||
context.missing(_postMeta);
|
||||
}
|
||||
if (data.containsKey('liked_by')) {
|
||||
context.handle(_likedByMeta,
|
||||
likedBy.isAcceptableOrUnknown(data['liked_by']!, _likedByMeta));
|
||||
} else if (isInserting) {
|
||||
context.missing(_likedByMeta);
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
@override
|
||||
Set<i0.GeneratedColumn> get $primaryKey => const {};
|
||||
@override
|
||||
i1.Like map(Map<String, dynamic> data, {String? tablePrefix}) {
|
||||
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';
|
||||
return i1.Like(
|
||||
post: attachedDatabase.typeMapping
|
||||
.read(i0.DriftSqlType.int, data['${effectivePrefix}post'])!,
|
||||
likedBy: attachedDatabase.typeMapping
|
||||
.read(i0.DriftSqlType.int, data['${effectivePrefix}liked_by'])!,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Likes createAlias(String alias) {
|
||||
return Likes(attachedDatabase, alias);
|
||||
}
|
||||
|
||||
@override
|
||||
List<String> get customConstraints => const [];
|
||||
@override
|
||||
bool get dontWriteConstraints => true;
|
||||
}
|
||||
|
||||
class PostsDrift extends i2.ModularAccessor {
|
||||
PostsDrift(i0.GeneratedDatabase db) : super(db);
|
||||
i3.UsersDrift get usersDrift => this.accessor(i3.UsersDrift.new);
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
import 'posts.drift';
|
||||
|
||||
CREATE VIRTUAL TABLE search_in_posts USING fts5 (
|
||||
author,
|
||||
content,
|
||||
content=posts,
|
||||
content_rowid=id
|
||||
);
|
||||
|
||||
-- Keep fts5 table and posts synchronized
|
||||
|
||||
CREATE TRIGGER posts_insert AFTER INSERT ON posts BEGIN
|
||||
INSERT INTO search_in_posts (rowid, author, content) VALUES (new.id, new.author, new.content);
|
||||
END;
|
||||
|
||||
CREATE TRIGGER posts_update AFTER UPDATE ON posts BEGIN
|
||||
INSERT INTO search_in_posts (search_in_posts, rowid, author, content) VALUES ('delete', old.id, old.author, old.content);
|
||||
INSERT INTO search_in_posts (rowid, author, content) VALUES (new.id, new.author, new.content);
|
||||
END;
|
||||
|
||||
CREATE TRIGGER posts_delete AFTER DELETE ON posts BEGIN
|
||||
INSERT INTO search_in_posts (search_in_posts, rowid, author, content) VALUES ('delete', old.id, old.author, old.content);
|
||||
END;
|
|
@ -0,0 +1,209 @@
|
|||
// ignore_for_file: type=lint
|
||||
import 'package:drift/drift.dart' as i0;
|
||||
import 'package:modular/src/search.drift.dart' as i1;
|
||||
import 'package:drift/internal/modular.dart' as i2;
|
||||
import 'package:modular/src/posts.drift.dart' as i3;
|
||||
|
||||
class SearchInPost extends i0.DataClass
|
||||
implements i0.Insertable<i1.SearchInPost> {
|
||||
final String author;
|
||||
final String content;
|
||||
const SearchInPost({required this.author, required this.content});
|
||||
@override
|
||||
Map<String, i0.Expression> toColumns(bool nullToAbsent) {
|
||||
final map = <String, i0.Expression>{};
|
||||
map['author'] = i0.Variable<String>(author);
|
||||
map['content'] = i0.Variable<String>(content);
|
||||
return map;
|
||||
}
|
||||
|
||||
i1.SearchInPostsCompanion toCompanion(bool nullToAbsent) {
|
||||
return i1.SearchInPostsCompanion(
|
||||
author: i0.Value(author),
|
||||
content: i0.Value(content),
|
||||
);
|
||||
}
|
||||
|
||||
factory SearchInPost.fromJson(Map<String, dynamic> json,
|
||||
{i0.ValueSerializer? serializer}) {
|
||||
serializer ??= i0.driftRuntimeOptions.defaultSerializer;
|
||||
return SearchInPost(
|
||||
author: serializer.fromJson<String>(json['author']),
|
||||
content: serializer.fromJson<String>(json['content']),
|
||||
);
|
||||
}
|
||||
@override
|
||||
Map<String, dynamic> toJson({i0.ValueSerializer? serializer}) {
|
||||
serializer ??= i0.driftRuntimeOptions.defaultSerializer;
|
||||
return <String, dynamic>{
|
||||
'author': serializer.toJson<String>(author),
|
||||
'content': serializer.toJson<String>(content),
|
||||
};
|
||||
}
|
||||
|
||||
i1.SearchInPost copyWith({String? author, String? content}) =>
|
||||
i1.SearchInPost(
|
||||
author: author ?? this.author,
|
||||
content: content ?? this.content,
|
||||
);
|
||||
@override
|
||||
String toString() {
|
||||
return (StringBuffer('SearchInPost(')
|
||||
..write('author: $author, ')
|
||||
..write('content: $content')
|
||||
..write(')'))
|
||||
.toString();
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(author, content);
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
(other is i1.SearchInPost &&
|
||||
other.author == this.author &&
|
||||
other.content == this.content);
|
||||
}
|
||||
|
||||
class SearchInPostsCompanion extends i0.UpdateCompanion<i1.SearchInPost> {
|
||||
final i0.Value<String> author;
|
||||
final i0.Value<String> content;
|
||||
const SearchInPostsCompanion({
|
||||
this.author = const i0.Value.absent(),
|
||||
this.content = const i0.Value.absent(),
|
||||
});
|
||||
SearchInPostsCompanion.insert({
|
||||
required String author,
|
||||
required String content,
|
||||
}) : author = i0.Value(author),
|
||||
content = i0.Value(content);
|
||||
static i0.Insertable<i1.SearchInPost> custom({
|
||||
i0.Expression<String>? author,
|
||||
i0.Expression<String>? content,
|
||||
}) {
|
||||
return i0.RawValuesInsertable({
|
||||
if (author != null) 'author': author,
|
||||
if (content != null) 'content': content,
|
||||
});
|
||||
}
|
||||
|
||||
i1.SearchInPostsCompanion copyWith(
|
||||
{i0.Value<String>? author, i0.Value<String>? content}) {
|
||||
return i1.SearchInPostsCompanion(
|
||||
author: author ?? this.author,
|
||||
content: content ?? this.content,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, i0.Expression> toColumns(bool nullToAbsent) {
|
||||
final map = <String, i0.Expression>{};
|
||||
if (author.present) {
|
||||
map['author'] = i0.Variable<String>(author.value);
|
||||
}
|
||||
if (content.present) {
|
||||
map['content'] = i0.Variable<String>(content.value);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return (StringBuffer('i1.SearchInPostsCompanion(')
|
||||
..write('author: $author, ')
|
||||
..write('content: $content')
|
||||
..write(')'))
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
||||
class SearchInPosts extends i0.Table
|
||||
with
|
||||
i0.TableInfo<SearchInPosts, i1.SearchInPost>,
|
||||
i0.VirtualTableInfo<SearchInPosts, i1.SearchInPost> {
|
||||
@override
|
||||
final i0.GeneratedDatabase attachedDatabase;
|
||||
final String? _alias;
|
||||
SearchInPosts(this.attachedDatabase, [this._alias]);
|
||||
static const i0.VerificationMeta _authorMeta =
|
||||
const i0.VerificationMeta('author');
|
||||
late final i0.GeneratedColumn<String> author = i0.GeneratedColumn<String>(
|
||||
'author', aliasedName, false,
|
||||
type: i0.DriftSqlType.string,
|
||||
requiredDuringInsert: true,
|
||||
$customConstraints: '');
|
||||
static const i0.VerificationMeta _contentMeta =
|
||||
const i0.VerificationMeta('content');
|
||||
late final i0.GeneratedColumn<String> content = i0.GeneratedColumn<String>(
|
||||
'content', aliasedName, false,
|
||||
type: i0.DriftSqlType.string,
|
||||
requiredDuringInsert: true,
|
||||
$customConstraints: '');
|
||||
@override
|
||||
List<i0.GeneratedColumn> get $columns => [author, content];
|
||||
@override
|
||||
String get aliasedName => _alias ?? 'search_in_posts';
|
||||
@override
|
||||
String get actualTableName => 'search_in_posts';
|
||||
@override
|
||||
i0.VerificationContext validateIntegrity(
|
||||
i0.Insertable<i1.SearchInPost> instance,
|
||||
{bool isInserting = false}) {
|
||||
final context = i0.VerificationContext();
|
||||
final data = instance.toColumns(true);
|
||||
if (data.containsKey('author')) {
|
||||
context.handle(_authorMeta,
|
||||
author.isAcceptableOrUnknown(data['author']!, _authorMeta));
|
||||
} else if (isInserting) {
|
||||
context.missing(_authorMeta);
|
||||
}
|
||||
if (data.containsKey('content')) {
|
||||
context.handle(_contentMeta,
|
||||
content.isAcceptableOrUnknown(data['content']!, _contentMeta));
|
||||
} else if (isInserting) {
|
||||
context.missing(_contentMeta);
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
@override
|
||||
Set<i0.GeneratedColumn> get $primaryKey => const {};
|
||||
@override
|
||||
i1.SearchInPost map(Map<String, dynamic> data, {String? tablePrefix}) {
|
||||
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';
|
||||
return i1.SearchInPost(
|
||||
author: attachedDatabase.typeMapping
|
||||
.read(i0.DriftSqlType.string, data['${effectivePrefix}author'])!,
|
||||
content: attachedDatabase.typeMapping
|
||||
.read(i0.DriftSqlType.string, data['${effectivePrefix}content'])!,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
SearchInPosts createAlias(String alias) {
|
||||
return SearchInPosts(attachedDatabase, alias);
|
||||
}
|
||||
|
||||
@override
|
||||
List<String> get customConstraints => const [];
|
||||
@override
|
||||
bool get dontWriteConstraints => true;
|
||||
@override
|
||||
String get moduleAndArgs =>
|
||||
'fts5(author, content, content=posts, content_rowid=id)';
|
||||
}
|
||||
|
||||
i0.Trigger get postsInsert => i0.Trigger(
|
||||
'CREATE TRIGGER posts_insert AFTER INSERT ON posts BEGIN INSERT INTO search_in_posts ("rowid", author, content) VALUES (new.id, new.author, new.content);END',
|
||||
'posts_insert');
|
||||
i0.Trigger get postsUpdate => i0.Trigger(
|
||||
'CREATE TRIGGER posts_update AFTER UPDATE ON posts BEGIN INSERT INTO search_in_posts (search_in_posts, "rowid", author, content) VALUES (\'delete\', old.id, old.author, old.content);INSERT INTO search_in_posts ("rowid", author, content) VALUES (new.id, new.author, new.content);END',
|
||||
'posts_update');
|
||||
i0.Trigger get postsDelete => i0.Trigger(
|
||||
'CREATE TRIGGER posts_delete AFTER DELETE ON posts BEGIN INSERT INTO search_in_posts (search_in_posts, "rowid", author, content) VALUES (\'delete\', old.id, old.author, old.content);END',
|
||||
'posts_delete');
|
||||
|
||||
class SearchDrift extends i2.ModularAccessor {
|
||||
SearchDrift(i0.GeneratedDatabase db) : super(db);
|
||||
i3.PostsDrift get postsDrift => this.accessor(i3.PostsDrift.new);
|
||||
}
|
|
@ -4,4 +4,10 @@ CREATE TABLE users (
|
|||
biography TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE follows (
|
||||
followed INTEGER NOT NULL REFERENCES users (id),
|
||||
follower INTEGER NOT NULL REFERENCES users (id),
|
||||
PRIMARY KEY (followed, follower)
|
||||
);
|
||||
|
||||
findUsers($predicate = TRUE): SELECT * FROM users WHERE $predicate;
|
||||
|
|
|
@ -219,6 +219,187 @@ class Users extends i0.Table with i0.TableInfo<Users, i1.User> {
|
|||
bool get dontWriteConstraints => true;
|
||||
}
|
||||
|
||||
class Follow extends i0.DataClass implements i0.Insertable<i1.Follow> {
|
||||
final int followed;
|
||||
final int follower;
|
||||
const Follow({required this.followed, required this.follower});
|
||||
@override
|
||||
Map<String, i0.Expression> toColumns(bool nullToAbsent) {
|
||||
final map = <String, i0.Expression>{};
|
||||
map['followed'] = i0.Variable<int>(followed);
|
||||
map['follower'] = i0.Variable<int>(follower);
|
||||
return map;
|
||||
}
|
||||
|
||||
i1.FollowsCompanion toCompanion(bool nullToAbsent) {
|
||||
return i1.FollowsCompanion(
|
||||
followed: i0.Value(followed),
|
||||
follower: i0.Value(follower),
|
||||
);
|
||||
}
|
||||
|
||||
factory Follow.fromJson(Map<String, dynamic> json,
|
||||
{i0.ValueSerializer? serializer}) {
|
||||
serializer ??= i0.driftRuntimeOptions.defaultSerializer;
|
||||
return Follow(
|
||||
followed: serializer.fromJson<int>(json['followed']),
|
||||
follower: serializer.fromJson<int>(json['follower']),
|
||||
);
|
||||
}
|
||||
@override
|
||||
Map<String, dynamic> toJson({i0.ValueSerializer? serializer}) {
|
||||
serializer ??= i0.driftRuntimeOptions.defaultSerializer;
|
||||
return <String, dynamic>{
|
||||
'followed': serializer.toJson<int>(followed),
|
||||
'follower': serializer.toJson<int>(follower),
|
||||
};
|
||||
}
|
||||
|
||||
i1.Follow copyWith({int? followed, int? follower}) => i1.Follow(
|
||||
followed: followed ?? this.followed,
|
||||
follower: follower ?? this.follower,
|
||||
);
|
||||
@override
|
||||
String toString() {
|
||||
return (StringBuffer('Follow(')
|
||||
..write('followed: $followed, ')
|
||||
..write('follower: $follower')
|
||||
..write(')'))
|
||||
.toString();
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(followed, follower);
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
(other is i1.Follow &&
|
||||
other.followed == this.followed &&
|
||||
other.follower == this.follower);
|
||||
}
|
||||
|
||||
class FollowsCompanion extends i0.UpdateCompanion<i1.Follow> {
|
||||
final i0.Value<int> followed;
|
||||
final i0.Value<int> follower;
|
||||
const FollowsCompanion({
|
||||
this.followed = const i0.Value.absent(),
|
||||
this.follower = const i0.Value.absent(),
|
||||
});
|
||||
FollowsCompanion.insert({
|
||||
required int followed,
|
||||
required int follower,
|
||||
}) : followed = i0.Value(followed),
|
||||
follower = i0.Value(follower);
|
||||
static i0.Insertable<i1.Follow> custom({
|
||||
i0.Expression<int>? followed,
|
||||
i0.Expression<int>? follower,
|
||||
}) {
|
||||
return i0.RawValuesInsertable({
|
||||
if (followed != null) 'followed': followed,
|
||||
if (follower != null) 'follower': follower,
|
||||
});
|
||||
}
|
||||
|
||||
i1.FollowsCompanion copyWith(
|
||||
{i0.Value<int>? followed, i0.Value<int>? follower}) {
|
||||
return i1.FollowsCompanion(
|
||||
followed: followed ?? this.followed,
|
||||
follower: follower ?? this.follower,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, i0.Expression> toColumns(bool nullToAbsent) {
|
||||
final map = <String, i0.Expression>{};
|
||||
if (followed.present) {
|
||||
map['followed'] = i0.Variable<int>(followed.value);
|
||||
}
|
||||
if (follower.present) {
|
||||
map['follower'] = i0.Variable<int>(follower.value);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return (StringBuffer('i1.FollowsCompanion(')
|
||||
..write('followed: $followed, ')
|
||||
..write('follower: $follower')
|
||||
..write(')'))
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
||||
class Follows extends i0.Table with i0.TableInfo<Follows, i1.Follow> {
|
||||
@override
|
||||
final i0.GeneratedDatabase attachedDatabase;
|
||||
final String? _alias;
|
||||
Follows(this.attachedDatabase, [this._alias]);
|
||||
static const i0.VerificationMeta _followedMeta =
|
||||
const i0.VerificationMeta('followed');
|
||||
late final i0.GeneratedColumn<int> followed = i0.GeneratedColumn<int>(
|
||||
'followed', aliasedName, false,
|
||||
type: i0.DriftSqlType.int,
|
||||
requiredDuringInsert: true,
|
||||
$customConstraints: 'NOT NULL REFERENCES users(id)');
|
||||
static const i0.VerificationMeta _followerMeta =
|
||||
const i0.VerificationMeta('follower');
|
||||
late final i0.GeneratedColumn<int> follower = i0.GeneratedColumn<int>(
|
||||
'follower', aliasedName, false,
|
||||
type: i0.DriftSqlType.int,
|
||||
requiredDuringInsert: true,
|
||||
$customConstraints: 'NOT NULL REFERENCES users(id)');
|
||||
@override
|
||||
List<i0.GeneratedColumn> get $columns => [followed, follower];
|
||||
@override
|
||||
String get aliasedName => _alias ?? 'follows';
|
||||
@override
|
||||
String get actualTableName => 'follows';
|
||||
@override
|
||||
i0.VerificationContext validateIntegrity(i0.Insertable<i1.Follow> instance,
|
||||
{bool isInserting = false}) {
|
||||
final context = i0.VerificationContext();
|
||||
final data = instance.toColumns(true);
|
||||
if (data.containsKey('followed')) {
|
||||
context.handle(_followedMeta,
|
||||
followed.isAcceptableOrUnknown(data['followed']!, _followedMeta));
|
||||
} else if (isInserting) {
|
||||
context.missing(_followedMeta);
|
||||
}
|
||||
if (data.containsKey('follower')) {
|
||||
context.handle(_followerMeta,
|
||||
follower.isAcceptableOrUnknown(data['follower']!, _followerMeta));
|
||||
} else if (isInserting) {
|
||||
context.missing(_followerMeta);
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
@override
|
||||
Set<i0.GeneratedColumn> get $primaryKey => {followed, follower};
|
||||
@override
|
||||
i1.Follow map(Map<String, dynamic> data, {String? tablePrefix}) {
|
||||
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';
|
||||
return i1.Follow(
|
||||
followed: attachedDatabase.typeMapping
|
||||
.read(i0.DriftSqlType.int, data['${effectivePrefix}followed'])!,
|
||||
follower: attachedDatabase.typeMapping
|
||||
.read(i0.DriftSqlType.int, data['${effectivePrefix}follower'])!,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Follows createAlias(String alias) {
|
||||
return Follows(attachedDatabase, alias);
|
||||
}
|
||||
|
||||
@override
|
||||
List<String> get customConstraints =>
|
||||
const ['PRIMARY KEY(followed, follower)'];
|
||||
@override
|
||||
bool get dontWriteConstraints => true;
|
||||
}
|
||||
|
||||
class UsersDrift extends i2.ModularAccessor {
|
||||
UsersDrift(i0.GeneratedDatabase db) : super(db);
|
||||
i0.Selectable<i1.User> findUsers({FindUsers$predicate? predicate}) {
|
||||
|
|
Loading…
Reference in New Issue