-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchange.dart
55 lines (47 loc) · 1.26 KB
/
change.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
import 'package:postgres/postgres.dart';
/// Run this file after running `listen.dart`
///
/// This function will modify the database
void main() async {
final conn = PostgreSQLConnection(
'localhost',
5432,
'postgres',
username: 'postgres',
password: 'postgres',
);
print('connecting to db');
await conn.open();
// create table
await conn.execute('''
create table if not exists temp (
id int GENERATED ALWAYS AS IDENTITY,
val text,
PRIMARY KEY (id)
);
''');
await wait(2);
print('inserting values');
await conn.execute('''
insert into temp (val) values ('value1'), ('value2'), ('value3');
''');
await wait(2);
print('updating values');
await conn.execute('''
update temp set val = 'value' where id in (select id from temp limit 2);
''');
await wait(2);
print('deleting values');
await conn.execute('''
delete from temp where id in (select id from temp limit 2);
''');
await wait(2);
print('truncating table');
// this may not show a change when using `wal2json` due to format version but it'd show using `pgoutput`
await conn.execute('''
truncate table temp;
''');
print('closing connection');
await conn.close();
}
Future<void> wait(int seconds) async => await Future.delayed(Duration(seconds: seconds));