summaryrefslogtreecommitdiffstats
path: root/2022/captions/emacsconf-2022-sqlite--using-sqlite-as-a-data-source-a-framework-and-an-example--andrew-hyatt--main.vtt
blob: 4c3792aa7a73ea470d490bc19b41f443fecaee69 (plain) (blame)
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
WEBVTT captioned by sachac

00:00:00.000 --> 00:00:08.555
Hello. I'm Andrew Hyatt. I've been working on Emacs,

00:00:08.556 --> 00:00:10.539
with Emacs, and to some extent

00:00:10.540 --> 00:00:15.272
on Emacs for a while. I've written the WebSockets library

00:00:15.273 --> 00:00:20.045
and Emacs calc tutorials. I've enjoyed use of

00:00:20.046 --> 00:00:24.640
many of everyone's incredible packages.

00:00:24.640 --> 00:00:27.132
So my thesis for this talk, why I'm giving this talk,

00:00:27.133 --> 00:00:29.060
is that I'm interested in SQLite.

00:00:29.061 --> 00:00:34.953
I think we should be exploring SQLite for applications

00:00:34.954 --> 00:00:37.482
in ways I think the community has shied away from.

00:00:37.483 --> 00:00:41.950
I'd like to introduce the triples package as a way,

00:00:41.951 --> 00:00:47.664
both easy and with interesting functionality,

00:00:47.665 --> 00:00:49.153
that will allow us to build extensible databases

00:00:49.154 --> 00:00:52.582
in a way that is, I think,

00:00:52.583 --> 00:00:56.220
a little bit unusual and perhaps compelling, I hope.

00:00:56.220 --> 00:00:59.226
So first of all, why SQLite?

00:00:59.227 --> 00:01:06.080
Why is this good? Well, SQLite is now built into Emacs.

00:01:06.080 --> 00:01:12.216
So you get a few things out of this when you use it for data.

00:01:12.217 --> 00:01:14.580
First of all, it's a database.

00:01:14.580 --> 00:01:16.369
It's extremely good for data, of course.

00:01:16.370 --> 00:01:19.918
There's a simplicity to data manipulation

00:01:19.919 --> 00:01:22.027
using a database, compared to data manipulation,

00:01:22.028 --> 00:01:25.196
that is, manipulating data in a text file.

00:01:25.197 --> 00:01:31.033
Text files are really not built for data.

00:01:31.034 --> 00:01:33.140
So when typically when you need to do this,

00:01:33.140 --> 00:01:35.026
like I know Org Mode is--

00:01:35.027 --> 00:01:38.116
which I'm a huge, huge Org Mode fan--

00:01:38.117 --> 00:01:41.044
it's all about sort of data in text.

00:01:41.045 --> 00:01:45.375
It does work, but you certainly would be

00:01:45.376 --> 00:01:47.360
hard pressed to make sweeping changes

00:01:47.360 --> 00:01:51.953
to your database that is represented in text.

00:01:51.954 --> 00:01:53.060
It's just not well suited for this sort of thing.

00:01:53.061 --> 00:01:54.963
It would take a long time,

00:01:54.964 --> 00:02:00.220
where the speed of SQL is incredibly impressive.

00:02:00.220 --> 00:02:04.429
I think certainly Emacs is not known

00:02:04.430 --> 00:02:06.752
for being extremely speedy.

00:02:06.753 --> 00:02:11.905
I think the overuse of text

00:02:11.906 --> 00:02:14.613
is part of this. Of course, text and using text,

00:02:14.614 --> 00:02:18.467
using files has awesome advantages as well.

00:02:18.468 --> 00:02:20.510
I'm really here to talk about

00:02:20.511 --> 00:02:22.717
the other side of the coin, right?

00:02:22.718 --> 00:02:23.961
Everyone can judge

00:02:23.962 --> 00:02:24.645
those advantages and disadvantages

00:02:24.646 --> 00:02:25.416
and make their own trade-offs,

00:02:25.417 --> 00:02:26.020
but I want to kind of

00:02:26.021 --> 00:02:29.869
make the pitch for SQLite.

00:02:29.870 --> 00:02:32.860
So let's talk about the triples package.

00:02:32.860 --> 00:02:35.488
The triples package is a package

00:02:35.489 --> 00:02:40.419
that is designed to give you a very generic schema.

00:02:40.420 --> 00:02:42.005
You don't have to do,

00:02:42.006 --> 00:02:43.291
for most of the common operations,

00:02:43.292 --> 00:02:45.516
you don't have to write SQL yourself.

00:02:45.517 --> 00:02:47.924
A lot of stuff is built in

00:02:47.925 --> 00:02:51.035
and is based on a very generic schema.

00:02:51.036 --> 00:02:53.840
That is, it's a single table.

00:02:53.840 --> 00:02:55.229
That table has, of course, fixed schema.

00:02:55.230 --> 00:02:57.478
It basically has three columns.

00:02:57.479 --> 00:03:00.867
It actually has four columns.

00:03:00.868 --> 00:03:01.193
In this talk, I'm not going to get into

00:03:01.194 --> 00:03:04.123
the fourth column and why, but it's useful.

00:03:04.124 --> 00:03:07.710
So the three columns are subject, predicate,

00:03:07.711 --> 00:03:10.361
and object. This is what it's related to

00:03:10.362 --> 00:03:13.908
what we call an RDF format.

00:03:13.909 --> 00:03:17.139
These things basically describe a link.

00:03:17.140 --> 00:03:20.007
The link is from the subject to the object.

00:03:20.008 --> 00:03:23.955
The link type is a predicate.

00:03:23.956 --> 00:03:26.085
That sounds overly theoretical,

00:03:26.086 --> 00:03:28.032
but the point is that you can describe

00:03:28.033 --> 00:03:32.005
a lot of things with this format.

00:03:32.006 --> 00:03:33.329
You probably describe everything with it.

00:03:33.330 --> 00:03:39.226
It's very simple because the schema is fixed.

00:03:39.227 --> 00:03:42.773
It's only this kind of data. That means

00:03:42.774 --> 00:03:44.140
for your application, you define a schema

00:03:44.140 --> 00:03:47.326
in subject, predicate, object format.

00:03:47.327 --> 00:03:50.072
That defines what data you can use,

00:03:50.073 --> 00:03:56.069
what types there are, what properties they have,

00:03:56.070 --> 00:03:57.214
how you can use the system,

00:03:57.215 --> 00:04:01.006
and what is legal to do. And this is stored as data.

00:04:01.007 --> 00:04:03.890
I think as Lisp people,

00:04:03.891 --> 00:04:07.540
I think we're all very onboard

00:04:07.540 --> 00:04:13.912
with the fact that you have a simple way

00:04:13.913 --> 00:04:17.660
to express everything, and you don't have these

00:04:17.660 --> 00:04:18.924
two systems. In this way,

00:04:18.925 --> 00:04:20.871
you don't have to have code as a system.

00:04:20.872 --> 00:04:24.825
Do you have to load code to use the triples package

00:04:24.826 --> 00:04:27.916
to make sure your schema is obeyed?

00:04:27.917 --> 00:04:35.213
No, it's all just built in to this database.

00:04:35.214 --> 00:04:37.036
I'll describe this. As I said,

00:04:37.037 --> 00:04:39.860
it's a little bit abstract right now,

00:04:39.860 --> 00:04:42.048
but it will become a lot clearer

00:04:42.049 --> 00:04:46.778
when we go through an example,

00:04:46.779 --> 00:04:50.208
which we're going to do now.

00:04:50.209 --> 00:04:56.660
As an exercise, let's create Emacs bookmarks,

00:04:56.660 --> 00:04:57.345
which basically are three things:

00:04:57.346 --> 00:05:01.038
a name, a file, and an annotation.

00:05:01.039 --> 00:05:02.364
I may be missing out on functionality.

00:05:02.365 --> 00:05:04.772
Of course, everything in Emacs,

00:05:04.773 --> 00:05:05.140
everything has lots and lots of functionality,

00:05:05.140 --> 00:05:08.049
but let's just start with this simple thing.

00:05:08.050 --> 00:05:11.100
First of all, we're going to open up a database.

00:05:11.100 --> 00:05:12.103
Pretty simple.

00:05:12.104 --> 00:05:15.014
I think there's nothing to explain there.

00:05:15.015 --> 00:05:19.106
But here on this line that I'm on right now,

00:05:19.107 --> 00:05:21.432
we are saying, okay, there's going to be

00:05:21.433 --> 00:05:24.839
a type called bookmark.

00:05:24.840 --> 00:05:26.826
It's going to have the following properties.

00:05:26.827 --> 00:05:29.178
First, a file, which is unique and a string.

00:05:29.179 --> 00:05:31.764
The second is an annotation,

00:05:31.765 --> 00:05:34.317
which is again unique and a string.

00:05:34.318 --> 00:05:37.864
Then we're going to have another type called named.

00:05:37.865 --> 00:05:39.808
First of all, why is it named as part of bookmark?

00:05:39.809 --> 00:05:45.562
As I'll get into, it's interesting

00:05:45.563 --> 00:05:48.511
when you start sharing this database

00:05:48.512 --> 00:05:51.365
with other things, not just bookmarks, but other types.

00:05:51.366 --> 00:05:54.616
Bookmarks are very similar to many other things

00:05:54.617 --> 00:05:56.723
that you might want to expand into.

00:05:56.724 --> 00:05:57.086
Those other things have names,

00:05:57.087 --> 00:05:58.269
but they're not bookmarks.

00:05:58.270 --> 00:06:04.123
It's nice to separate these concerns out

00:06:04.124 --> 00:06:08.372
and just have another type called named,

00:06:08.373 --> 00:06:12.780
which just basically has a name.

00:06:12.780 --> 00:06:15.746
We can execute this.

00:06:15.747 --> 00:06:21.798
It's not interesting to look at these.

00:06:21.440 --> 00:06:25.907
that is not all that useful for anything,

00:06:21.799 --> 00:06:21.439
It outputs something

00:06:25.908 --> 00:06:28.014
but that's okay. What's done is, actually,

00:06:28.015 --> 00:06:32.262
it's created a database

00:06:32.263 --> 00:06:34.045
and it's populated it with the schema.

00:06:34.046 --> 00:06:41.478
We can look at this.

00:06:41.479 --> 00:06:43.602
We won't go through all of this

00:06:43.603 --> 00:06:44.188
because it's a little bit too much

00:06:44.189 --> 00:06:46.036
for a short presentation like this,

00:06:46.037 --> 00:06:48.185
but you could see that there's something here

00:06:48.186 --> 00:06:52.500
that's like, oh, we have a subject bookmark.

00:06:52.500 --> 00:06:56.031
We have a property base/type.

00:06:56.032 --> 00:06:58.878
That just means that there's a property

00:06:58.879 --> 00:07:00.562
that's defined by the base.

00:07:00.563 --> 00:07:02.248
This means this is from the triples package itself.

00:07:02.249 --> 00:07:08.940
It's not some other package.

00:07:08.940 --> 00:07:11.525
Third is, what is the type of this object?

00:07:11.526 --> 00:07:17.060
It's a schema. This thing could be many types.

00:07:17.060 --> 00:07:19.150
As I said, if you have a--

00:07:19.151 --> 00:07:20.235
we haven't seen an example yet,

00:07:20.236 --> 00:07:21.100
but if you have a bookmark,

00:07:21.100 --> 00:07:23.686
it's going to have a name type

00:07:23.687 --> 00:07:25.694
and a bookmark type.

00:07:25.695 --> 00:07:26.719
Everything is multi-typed

00:07:26.720 --> 00:07:28.146
and that's kind of a feature

00:07:28.147 --> 00:07:32.137
of this kind of storage system.

00:07:32.138 --> 00:07:33.140
I'm not going to go through everything,

00:07:33.140 --> 00:07:35.865
but you can see it's all there in triples,

00:07:35.866 --> 00:07:40.740
the whole schema, everything we just did.

00:07:40.740 --> 00:07:42.645
Let's create a bookmark.  Again,

00:07:42.646 --> 00:07:46.997
we're going to connect to our database

00:07:46.998 --> 00:07:49.246
and we're going to basically set

00:07:49.247 --> 00:07:52.552
an entire subject.

00:07:52.553 --> 00:07:54.239
The subject is, it's basically like an entity.

00:07:54.240 --> 00:07:56.105
We're going to define a whole entity

00:07:56.106 --> 00:08:00.676
or you could refer to it as an object.

00:08:00.677 --> 00:08:03.909
That's a perfectly fine way to look at it, I think.

00:08:03.910 --> 00:08:04.356
It's going to have some identifier.

00:08:04.357 --> 00:08:06.723
That identifier could be anything.

00:08:06.724 --> 00:08:07.431
It doesn't have to be a string.

00:08:07.432 --> 00:08:09.260
It could really be anything, but we're going

00:08:09.260 --> 00:08:11.369
to give it a string called emacs-init.

00:08:11.370 --> 00:08:13.298
It does not matter what this identifier is,

00:08:13.299 --> 00:08:17.808
at least for our purposes.

00:08:17.809 --> 00:08:19.914
It does matter when you're linking to it,

00:08:19.915 --> 00:08:22.263
but I think nothing that I'm about to show you.

00:08:22.264 --> 00:08:25.830
This could truly be anything

00:08:25.831 --> 00:08:28.180
because it has a separate name.

00:08:28.180 --> 00:08:32.131
I'm giving it a name here, which is init.

00:08:32.133 --> 00:08:34.917
I'm just specifying the named type here

00:08:34.918 --> 00:08:38.047
and I'm specifying the bookmark type here

00:08:38.048 --> 00:08:43.219
and its values. We're going to do that.

00:08:43.220 --> 00:08:47.769
Now, if we look, we see everything we saw before,

00:08:47.770 --> 00:08:52.246
but now we have subject emacs-init.

00:08:52.247 --> 00:08:55.973
It has a type and it's named.

00:08:55.974 --> 00:08:57.220
We also see the same thing two lines down.

00:08:57.220 --> 00:08:58.264
This type is also a bookmark,

00:08:58.265 --> 00:09:02.819
but the name is init in the named/name,

00:09:02.820 --> 00:09:05.966
which is like the type is name, named,

00:09:05.967 --> 00:09:08.752
and the property is name. It's init.

00:09:08.753 --> 00:09:12.661
As you can see, this is just

00:09:12.662 --> 00:09:16.331
how everything looks.

00:09:16.332 --> 00:09:18.356
It's pretty straightforward

00:09:18.357 --> 00:09:19.318
and you can retrieve it.

00:09:19.319 --> 00:09:21.603
Now, we're looking at the database,

00:09:21.604 --> 00:09:22.689
but you don't really have to

00:09:22.690 --> 00:09:23.218
look at the database for... In fact,

00:09:23.219 --> 00:09:24.222
I think we're done looking

00:09:24.223 --> 00:09:25.105
at the triples format,

00:09:25.106 --> 00:09:29.718
because I think it's very simple.

00:09:29.719 --> 00:09:31.365
You've already got the hang of it, I think.

00:09:31.366 --> 00:09:33.069
Let's retrieve that just to make sure, yes,

00:09:33.070 --> 00:09:37.980
we can retrieve it.

00:09:37.981 --> 00:09:38.247
We're going to retrieve it and say, okay,

00:09:38.248 --> 00:09:43.286
what do we get when we load the emacs-init subject?

00:09:43.287 --> 00:09:48.697
Well, we get a plist of all of its properties,

00:09:48.698 --> 00:09:55.630
which then you can use in your application.

00:09:55.631 --> 00:09:57.455
There's many more ways to retrieve

00:09:57.456 --> 00:09:59.379
and there's many more ways to save.

00:09:59.380 --> 00:10:01.904
In fact, I think the way I did it here

00:10:01.905 --> 00:10:04.015
with set subject is probably not

00:10:04.016 --> 00:10:06.781
the right way to do it most of the time.

00:10:06.782 --> 00:10:08.127
It's usually because it'll erase everything.

00:10:08.128 --> 00:10:13.740
It's only really to be used when

00:10:13.740 --> 00:10:15.710
you're sure you control all the data,

00:10:15.711 --> 00:10:16.399
but you're never sure because there could be

00:10:16.400 --> 00:10:19.610
other packages that are also using this database,

00:10:19.611 --> 00:10:20.695
they could have their own data.

00:10:20.696 --> 00:10:21.342
You don't want to erase

00:10:21.343 --> 00:10:25.014
all the other Emacs init subject data.

00:10:25.015 --> 00:10:27.699
In this case, we did because

00:10:27.700 --> 00:10:30.810
we are confident it was a new entity,

00:10:30.811 --> 00:10:31.335
but in most cases, the right thing to do is

00:10:31.336 --> 00:10:34.289
just set it by type. Just say,

00:10:34.290 --> 00:10:36.676
we're just going to set the bookmark type,

00:10:36.677 --> 00:10:37.222
which is... The properties are this,

00:10:37.223 --> 00:10:38.104
and then the name type

00:10:38.105 --> 00:10:42.814
and the properties are that.

00:10:42.815 --> 00:10:44.900
That's a way that you could do things.

00:10:44.900 --> 00:10:48.526
There's also many retrieval types.

00:10:48.527 --> 00:10:53.755
The retrieval types:

00:10:53.756 --> 00:10:56.403
you can retrieve by a number of different ways,

00:10:56.404 --> 00:10:58.869
which I'm not going to get into,

00:10:58.870 --> 00:11:01.241
but you can read about in either the source

00:11:01.242 --> 00:11:10.033
or the readme in the package.

00:11:10.034 --> 00:11:14.539
We have backlinks as well.

00:11:14.540 --> 00:11:15.862
Let me explain what backlinks are.

00:11:15.863 --> 00:11:17.172
There's another feature of the triples.

00:11:17.173 --> 00:11:19.860
As I mentioned, these things

00:11:19.861 --> 00:11:21.849
can be thought about as links,

00:11:21.850 --> 00:11:23.797
but what could be a link in one direction

00:11:23.798 --> 00:11:25.804
could also be a link in the other direction,

00:11:25.805 --> 00:11:28.395
and we basically get this for free.

00:11:28.396 --> 00:11:33.807
Here's an example where we are again

00:11:33.808 --> 00:11:35.752
connecting toward bookmark. Here we're going to

00:11:35.753 --> 00:11:38.223
add a new type called tagged.

00:11:38.224 --> 00:11:41.613
We're going to give everything in tags.

00:11:41.614 --> 00:11:45.524
Here we're saying, okay, there's a type called tagged

00:11:45.525 --> 00:11:49.234
and it has a property called tags.

00:11:49.235 --> 00:11:52.060
This is not unique, so it's a list basically.

00:11:52.060 --> 00:11:54.326
It's a list of string.

00:11:54.327 --> 00:11:58.675
There also is a type called tag.

00:11:58.676 --> 00:12:01.402
This is for things that are tags themselves.

00:12:01.403 --> 00:12:06.127
Then it has a type called numbers

00:12:06.128 --> 00:12:18.003
and it has what we call a virtual reversed property.

00:12:18.004 --> 00:12:21.075
It's virtual because it's not actually stored.

00:12:21.076 --> 00:12:23.741
We just compute it by reversing

00:12:23.742 --> 00:12:24.306
the subject and the object.

00:12:24.307 --> 00:12:29.260
This is on tagged tags. When we query this,

00:12:29.260 --> 00:12:32.006
we can just say, okay,

00:12:32.007 --> 00:12:33.268
what are all the subjects

00:12:33.269 --> 00:12:38.859
that have tagged tags of me, the tag?

00:12:38.860 --> 00:12:39.365
In fact, let me demonstrate that for you.

00:12:39.366 --> 00:12:42.139
We're going to set the type on emacs-init.

00:12:42.140 --> 00:12:45.070
We're going to add the "tagged" type.

00:12:45.071 --> 00:12:47.017
This is the alternate way of setting data

00:12:47.018 --> 00:12:48.740
that I mentioned.

00:12:48.740 --> 00:12:49.924
This won't erase anything else.

00:12:49.925 --> 00:12:51.752
We're just adding something here.

00:12:51.753 --> 00:12:54.742
We're adding this type "tagged"

00:12:54.743 --> 00:12:59.953
to our previous bookmark emacs-init.

00:12:59.954 --> 00:13:01.058
We're going to add emacs and config

00:13:01.059 --> 00:13:06.866
as the tags. We're going to then

00:13:06.867 --> 00:13:11.095
set emacs as a tag and config as a tag.

00:13:11.096 --> 00:13:15.385
That just lets us have this virtual property.

00:13:15.386 --> 00:13:16.389
You have to do something.

00:13:16.390 --> 00:13:18.733
You can't get it out of thin air.

00:13:18.734 --> 00:13:23.426
The design decision we've made is:

00:13:23.427 --> 00:13:25.508
you at least need to tag it

00:13:25.509 --> 00:13:32.660
before you get the free property.

00:13:32.660 --> 00:13:35.631
What you should see... Let's try it out.

00:13:35.632 --> 00:13:36.037
We got the subject config,

00:13:36.038 --> 00:13:37.261
which we've set no data on.

00:13:37.262 --> 00:13:40.668
You can tell we're not sending any data.

00:13:40.669 --> 00:13:44.820
If I get that subject, the result is that

00:13:44.821 --> 00:13:46.068
it says its members are emacs-init.

00:13:46.069 --> 00:13:49.878
That's what a virtual reverse property.

00:13:49.879 --> 00:13:53.606
As we tag more things, this just

00:13:53.607 --> 00:13:55.151
continues to work because it's just doing

00:13:55.152 --> 00:13:59.380
a SQL query here.

00:13:59.380 --> 00:14:01.985
Besides showing off the backlinks function,

00:14:01.986 --> 00:14:04.175
this also shows off the general way

00:14:04.176 --> 00:14:07.863
you can have extensible entities.

00:14:07.864 --> 00:14:09.391
That is, it's possible that someone writes

00:14:09.392 --> 00:14:13.062
a bookmarks package that stores everything

00:14:13.063 --> 00:14:18.054
in a database, in the triples database,

00:14:18.055 --> 00:14:21.521
but then someone else can come and say,

00:14:21.522 --> 00:14:23.590
okay, I'm going to define my own types

00:14:23.591 --> 00:14:25.739
that's meant to work with this database,

00:14:25.740 --> 00:14:28.507
just like someone could do what I did here,

00:14:28.508 --> 00:14:30.874
just to add simple tagging.

00:14:30.875 --> 00:14:32.900
It's very easy to do.

00:14:32.901 --> 00:14:35.931
This stuff is not that easy to do otherwise.

00:14:35.932 --> 00:14:38.961
To do this in Lisp, I would say it's a little awkward.

00:14:38.962 --> 00:14:42.673
With databases, again, it's not only possible,

00:14:42.674 --> 00:14:43.498
it's relatively trivial,

00:14:43.499 --> 00:14:49.828
especially with this kind of database.

00:14:49.829 --> 00:14:53.056
The benefit is it's super easy to work with.

00:14:53.057 --> 00:14:56.041
With this kind of generic database,

00:14:56.042 --> 00:15:00.311
the drawback is it's not all that efficient

00:15:00.312 --> 00:15:04.381
as a special purpose table

00:15:04.382 --> 00:15:06.191
that is really built for efficiencies.

00:15:06.192 --> 00:15:08.820
A lot of times you have to do multiple lookups

00:15:08.820 --> 00:15:09.442
and things like that.

00:15:09.443 --> 00:15:11.985
Again, it's a trade-off for various things.

00:15:11.986 --> 00:15:19.900
As you can see, this is like

00:15:19.901 --> 00:15:22.066
one database for everything.

00:15:22.067 --> 00:15:29.178
That means that we don't have to all

00:15:29.179 --> 00:15:31.944
contribute to one giant database.

00:15:31.945 --> 00:15:33.052
All the packages that use triples,

00:15:33.053 --> 00:15:35.180
it doesn't have to be one database,

00:15:35.180 --> 00:15:37.086
but it's cool if it does.

00:15:37.087 --> 00:15:39.393
I don't know what I want to happen

00:15:39.394 --> 00:15:41.220
or what I expect to happen,

00:15:41.220 --> 00:15:43.068
but I think an interesting property is that

00:15:43.069 --> 00:15:45.400
this is a way for lots of data to live together

00:15:45.400 --> 00:15:49.606
and build off each other in ways that I think

00:15:49.607 --> 00:15:55.780
are hard to do with other forms of table layouts

00:15:55.780 --> 00:15:57.007
and things like that.

00:15:57.008 --> 00:15:59.653
Let's talk about a use of it,

00:15:59.654 --> 00:16:02.643
which is the EKG package.

00:16:02.644 --> 00:16:04.589
The EKG package is something I've written

00:16:04.590 --> 00:16:07.780
to demonstrate the triples library

00:16:07.780 --> 00:16:09.409
and use it for something I think is interesting,

00:16:09.410 --> 00:16:12.420
which is personal knowledge management systems

00:16:12.420 --> 00:16:14.384
of the same type, of the same genre

00:16:14.385 --> 00:16:15.286
that Org Roam is,

00:16:15.287 --> 00:16:18.433
but with different design decisions.

00:16:18.434 --> 00:16:26.531
I'll show it in action for a little bit.

00:16:26.532 --> 00:16:28.359
Let's just look at... it's all tag-based,

00:16:28.360 --> 00:16:30.185
same kind of tags we saw before

00:16:30.186 --> 00:16:32.232
when we were playing around

00:16:32.233 --> 00:16:35.560
with the bookmarks example application,

00:16:35.224 --> 00:16:37.475
What I want to show is: I can look at a tag.

00:16:35.560 --> 00:16:35.223
but everything here is...

00:16:37.476 --> 00:16:40.287
I could see notes with that tag.

00:16:40.288 --> 00:16:42.632
Everything you see here is in the database,

00:16:42.633 --> 00:16:43.198
no files involved.

00:16:43.199 --> 00:16:46.404
All of this is just a thing

00:16:46.405 --> 00:16:49.390
that's an entire object, the entire string.

00:16:49.391 --> 00:16:56.081
It works. It has tags.

00:16:56.082 --> 00:16:59.229
You can see not only this tag,

00:16:59.230 --> 00:17:01.354
but all the other tags associated with it

00:17:01.355 --> 00:17:04.860
and their notes.

00:17:04.860 --> 00:17:10.255
It's kind of an interesting way to do things.

00:17:10.256 --> 00:17:12.260
When you capture it, I think it's interesting.

00:17:12.260 --> 00:17:22.275
There's a lot of interesting design elements here.

00:17:22.276 --> 00:17:25.819
This tags thing is not part of the buffer.

00:17:25.819 --> 00:17:28.751
It's not like Org Roam.

00:17:28.752 --> 00:17:29.116
You see here in this other tags,

00:17:29.117 --> 00:17:31.924
these are things I've imported from Org Roam.

00:17:31.925 --> 00:17:32.230
This is why they look like they do.

00:17:32.231 --> 00:17:34.020
They have their own titles because

00:17:34.020 --> 00:17:37.889
I just wrote them all in Org Roam.

00:17:37.890 --> 00:17:39.457
What it looks like, really, for these notes

00:17:39.458 --> 00:17:41.023
is that it's just text.

00:17:41.024 --> 00:17:44.615
You really don't have to bother with this metadata.

00:17:44.616 --> 00:17:46.282
If I want another tag like pancakes,

00:17:46.283 --> 00:17:53.654
I can just add it here. Again, these tags

00:17:53.655 --> 00:17:56.740
will turn into data, triple data.

00:17:56.740 --> 00:17:59.825
The text is just a triple date[??] as well,

00:17:59.826 --> 00:18:01.969
but different to triple data.

00:18:01.970 --> 00:18:08.362
All these things are like that.

00:18:08.363 --> 00:18:12.771
You can open up any of these things, et cetera.

00:18:12.772 --> 00:18:16.682
I think the interesting thing here

00:18:16.683 --> 00:18:22.596
is to see the code. It's not super interesting

00:18:22.597 --> 00:18:23.980
to look at code for too long,

00:18:23.980 --> 00:18:26.991
but we don't have that long.

00:18:26.992 --> 00:18:27.654
Whenever we connect--

00:18:27.655 --> 00:18:28.819
I just want to point out a few things.

00:18:28.820 --> 00:18:29.205
Whenever we connect, we have a schema.

00:18:29.206 --> 00:18:31.175
We just do this. Every time we connect,

00:18:31.176 --> 00:18:33.163
we just make sure it has the right schema.

00:18:33.164 --> 00:18:36.314
This way, the user is up to date.

00:18:36.315 --> 00:18:38.300
This schema just looks exactly like

00:18:38.301 --> 00:18:41.687
stuff I showed you in the triples

00:18:41.688 --> 00:18:43.532
when we were looking at bookmarks.

00:18:43.533 --> 00:18:45.100
It's not complicated.

00:18:45.100 --> 00:18:48.210
I even have stuff here with people

00:18:48.211 --> 00:18:51.538
to use this as a person database.

00:18:51.539 --> 00:18:52.104
I haven't figured out how I'm going to use this yet,

00:18:52.105 --> 00:18:54.273
but you can see just to do this,

00:18:54.274 --> 00:19:01.913
it's really trivial and it's pretty easy.

00:19:01.914 --> 00:19:02.498
Let's show a few other things,

00:19:02.499 --> 00:19:05.844
like getting all the tags.

00:19:05.845 --> 00:19:07.990
Here, we could just say,

00:19:07.991 --> 00:19:10.379
let's get the subjects of type tag.

00:19:10.380 --> 00:19:12.902
We have all the triples,

00:19:12.903 --> 00:19:15.849
all the ones that are of type tag,

00:19:15.850 --> 00:19:18.777
all the things that have a subject.

00:19:18.778 --> 00:19:22.145
All the subjects that have links,

00:19:22.146 --> 00:19:28.337
that have this type, this tag in it,

00:19:28.338 --> 00:19:30.660
we can return them all.

00:19:30.426 --> 00:19:32.674
of all these objects.

00:19:30.660 --> 00:19:30.425
Basically, it just gives you a list

00:19:32.675 --> 00:19:33.243
Again, you can think of these things as objects.

00:19:33.244 --> 00:19:35.433
All the objects of type tag,

00:19:35.434 --> 00:19:37.320
we'll just get them all. Super, super simple.

00:19:37.321 --> 00:19:39.585
Triples gives you this functionality

00:19:39.586 --> 00:19:43.780
out of the box. It's not that complicated.

00:19:43.780 --> 00:19:45.167
What I would like to show,

00:19:45.168 --> 00:19:49.518
and that shows my thesis for this whole talk,

00:19:49.519 --> 00:19:52.785
is this rename tag. Now, think about

00:19:52.786 --> 00:19:54.150
how you would rename a tag in Org Roam

00:19:54.151 --> 00:20:03.013
or anything where the tag is part of the files.

00:20:03.014 --> 00:20:05.280
It's like how you would re-tag everything

00:20:05.280 --> 00:20:09.869
in Org Mode. It's complicated and error-prone

00:20:09.870 --> 00:20:12.556
and slow. This is anything,

00:20:12.557 --> 00:20:14.763
this is instantaneous and super easy.

00:20:14.764 --> 00:20:17.255
Look, that's it. There's not that many places

00:20:17.256 --> 00:20:19.540
for an error to live here.

00:20:19.540 --> 00:20:21.507
One thing I would like to point out

00:20:21.508 --> 00:20:23.337
is that we are doing direct,

00:20:23.338 --> 00:20:24.320
not everything has to go through

00:20:24.321 --> 00:20:28.292
the triples package. Maybe it should,

00:20:28.293 --> 00:20:31.660
but the triples package is a fixed format,

00:20:31.660 --> 00:20:33.906
which is why it's okay--

00:20:33.907 --> 00:20:34.069
whether it's a good idea, I'm not sure,

00:20:34.070 --> 00:20:39.863
but it's okay for client packages

00:20:39.864 --> 00:20:42.833
to just directly manipulate the tables.

00:20:42.834 --> 00:20:43.937
Here, we're just doing it just to

00:20:43.938 --> 00:20:45.265
update all the tags

00:20:45.266 --> 00:20:47.891
and then remove and set types

00:20:47.892 --> 00:20:49.119
so that the correct thing happens.

00:20:49.120 --> 00:20:52.146
As you can see, it's super, super simple.

00:20:52.147 --> 00:20:55.374
I think this proves my thesis about

00:20:55.375 --> 00:21:01.526
the advantages of applications with SQLite.

00:21:01.527 --> 00:21:02.430
Thank you for listening.

00:21:02.431 --> 00:21:05.876
I hope this puts ideas in your minds

00:21:05.877 --> 00:21:09.827
about taking advantage of this functionality.

00:21:09.828 --> 00:21:11.935
I hope to see more things

00:21:11.936 --> 00:21:12.180
using the triples library

00:21:12.180 --> 00:21:16.017
or otherwise that take advantage of this.

00:21:16.018 --> 00:21:17.660
Thank you for your time.