-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_database.g.dart
130 lines (109 loc) · 4.23 KB
/
app_database.g.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'app_database.dart';
// **************************************************************************
// FloorGenerator
// **************************************************************************
class $FloorAppDatabase {
/// Creates a database builder for a persistent database.
/// Once a database is built, you should keep a reference to it and re-use it.
static _$AppDatabaseBuilder databaseBuilder(String name) =>
_$AppDatabaseBuilder(name);
/// Creates a database builder for an in memory database.
/// Information stored in an in memory database disappears when the process is killed.
/// Once a database is built, you should keep a reference to it and re-use it.
static _$AppDatabaseBuilder inMemoryDatabaseBuilder() =>
_$AppDatabaseBuilder(null);
}
class _$AppDatabaseBuilder {
_$AppDatabaseBuilder(this.name);
final String name;
final List<Migration> _migrations = [];
/// Adds migrations to the builder.
_$AppDatabaseBuilder addMigrations(List<Migration> migrations) {
_migrations.addAll(migrations);
return this;
}
/// Creates the database and initializes it.
Future<AppDatabase> build() async {
final database = _$AppDatabase();
database.database = await database.open(name ?? ':memory:', _migrations);
return database;
}
}
class _$AppDatabase extends AppDatabase {
UserDao _userDaoInstance;
Future<sqflite.Database> open(String name, List<Migration> migrations) async {
final path = join(await sqflite.getDatabasesPath(), name);
return sqflite.openDatabase(
path,
version: 1,
onConfigure: (database) async {
await database.execute('PRAGMA foreign_keys = ON');
},
onUpgrade: (database, startVersion, endVersion) async {
MigrationAdapter.runMigrations(
database, startVersion, endVersion, migrations);
},
onCreate: (database, _) async {
await database.execute(
'CREATE TABLE IF NOT EXISTS `User` (`id` INTEGER PRIMARY KEY NOT NULL, `name` TEXT, `avatar` TEXT, `teammate` INTEGER, `experience` TEXT, `age` INTEGER, `gender` INTEGER, `height` INTEGER, `weight` INTEGER, `insurance` TEXT, `job` TEXT, `created_at` TEXT, `updated_at` TEXT, `api_token` TEXT)');
},
);
}
@override
UserDao get userDao {
return _userDaoInstance ??= _$UserDao(database, changeListener);
}
}
class _$UserDao extends UserDao {
_$UserDao(this.database, this.changeListener)
: _queryAdapter = QueryAdapter(database, changeListener),
_userInsertionAdapter = InsertionAdapter(
database,
'User',
(User item) => <String, dynamic>{
'id': item.id,
'name': item.name,
'avatar': item.avatar,
'teammate': item.teammate,
'experience': item.experience,
'age': item.age,
'gender': item.gender,
'height': item.height,
'weight': item.weight,
'insurance': item.insurance,
'job': item.job,
'created_at': item.createdAt,
'updated_at': item.updatedAt,
'api_token': item.apiToken
},
changeListener);
final sqflite.DatabaseExecutor database;
final StreamController<String> changeListener;
final QueryAdapter _queryAdapter;
final _userMapper = (Map<String, dynamic> row) => User(
row['id'] as int,
row['name'] as String,
row['avatar'] as int,
row['teammate'] as int,
row['experience'] as String,
row['age'] as int,
row['gender'] as String,
row['height'] as String,
row['weight'] as String,
row['insurance'] as int,
row['job'] as int,
row['created_at'] as String,
row['updated_at'] as String,
row['api_token'] as String);
final InsertionAdapter<User> _userInsertionAdapter;
@override
Stream<User> getUserInfo() {
return _queryAdapter.queryStream('SELECT * FROM User LIMIT 1',
tableName: 'User', mapper: _userMapper);
}
@override
Future<void> insertUserInformation(User user) async {
await _userInsertionAdapter.insert(user, sqflite.ConflictAlgorithm.abort);
}
}