-
Notifications
You must be signed in to change notification settings - Fork 0
/
column_db.dart
58 lines (47 loc) · 1.44 KB
/
column_db.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
import 'package:psqlite/psqlite.dart';
import 'field_type_db.dart';
/// Defines a column of a database table.
/// A TableDb object will be made up of a collection of ColumnDb objects.
class ColumnDb {
/// The name of the database column.
final String _name;
/// The type of data that the database column contains.
final FieldTypeDb _type;
/// Indicates if this column is primary key.
final bool _isPrimaryKey;
ColumnDb(
{bool isPrimaryKey = false,
required String name,
required FieldTypeDb type})
: _isPrimaryKey = isPrimaryKey,
_name = name,
_type = type;
/// Return the name of the database column.
String getName() => _name;
/// Return the type of data that the database column contains.
FieldTypeDb getType() => _type;
/// Return if this column is primary key.
bool isPrimaryKey() => _isPrimaryKey;
@override
String toString() {
String description = '$_name ${_type.getName()}';
if (_isPrimaryKey) {
description += ' PRIMARY KEY';
}
return description;
}
@override
bool operator ==(Object other) {
if (other is! ColumnDb) return false;
if (getName().toUpperCase() != other.getName().toUpperCase()) return false;
return true;
}
@override
int get hashCode {
var result = 17;
result = 37 * result + _name.hashCode;
result = 37 * result + _type.hashCode;
result = 37 * result + _isPrimaryKey.hashCode;
return result;
}
}