/
example.dart
102 lines (77 loc) · 2.24 KB
/
example.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
import 'dart:async';
import 'package:jaguar_query/jaguar_query.dart';
import 'package:jaguar_orm/jaguar_orm.dart';
part 'example.jorm.dart';
class CartItem {
@primaryKey
int id;
double amount;
@Column(notNull: true)
String product;
int quantity;
@BelongsTo.many(CartBean, references: 'id')
int cartId;
CartItem({this.amount, this.product, this.quantity, this.id});
CartItem.make(this.amount, this.product, this.quantity);
@override
String toString() =>
'id=$id, amount=$amount, quantity=$quantity, product=$product, cartId=$cartId';
CartItem copy({int id, int quantity, String product, double amount}) {
return CartItem(
amount: amount ?? this.amount,
product: product ?? this.product,
quantity: quantity ?? this.quantity,
id: id ?? this.id,
);
}
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is CartItem &&
runtimeType == other.runtimeType &&
amount == other.amount &&
product == other.product &&
quantity == other.quantity;
@override
int get hashCode => amount.hashCode ^ product.hashCode ^ quantity.hashCode;
}
@GenBean()
class CartItemBean extends Bean<CartItem> with _CartItemBean {
final BeanRepo beanRepo;
CartItemBean(Adapter adapter, this.beanRepo) : super(adapter);
@override
String get tableName => 'cartItem';
}
class Cart {
@primaryKey
int id;
@HasMany(CartItemBean)
List<CartItem> items;
double amount;
Cart({this.id, this.amount = 0.0, this.items = const []});
Cart copy({id, amount, items}) {
return Cart(
id: id ?? this.id,
amount: amount ?? this.amount,
items: items ?? this.items,
);
}
@override
String toString() => 'id=$id, amount=$amount, items=$items';
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Cart &&
runtimeType == other.runtimeType &&
items == other.items &&
amount == other.amount;
@override
int get hashCode => items.hashCode ^ amount.hashCode;
}
@GenBean()
class CartBean extends Bean<Cart> with _CartBean {
final BeanRepo beanRepo;
CartBean(Adapter adapter, this.beanRepo) : super(adapter);
@override
String get tableName => 'cart';
}