Parakeet is a Rust-based Bluesky AppServer aiming to implement most of the functionality required to support the Bluesky client
appview atproto bluesky rust appserver
66
fork

Configure Feed

Select the types of activity you want to include in your feed.

diesel init

Mia f2c50b6a 23d526f7

+507 -12
+2
.gitignore
··· 1 1 target/ 2 2 .DS_Store 3 3 .idea/ 4 + .env 5 + Config.toml
+402
Cargo.lock
··· 83 83 ] 84 84 85 85 [[package]] 86 + name = "async-trait" 87 + version = "0.1.85" 88 + source = "registry+https://github.com/rust-lang/crates.io-index" 89 + checksum = "3f934833b4b7233644e5848f235df3f57ed8c80f1528a26c3dfa13d2147fa056" 90 + dependencies = [ 91 + "proc-macro2", 92 + "quote", 93 + "syn", 94 + ] 95 + 96 + [[package]] 86 97 name = "atomic" 87 98 version = "0.6.0" 88 99 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 117 128 version = "0.2.11" 118 129 source = "registry+https://github.com/rust-lang/crates.io-index" 119 130 checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270" 131 + 132 + [[package]] 133 + name = "base64" 134 + version = "0.22.1" 135 + source = "registry+https://github.com/rust-lang/crates.io-index" 136 + checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" 120 137 121 138 [[package]] 122 139 name = "bitflags" ··· 289 306 dependencies = [ 290 307 "chrono", 291 308 "ciborium", 309 + "diesel", 310 + "diesel-async", 292 311 "eyre", 293 312 "figment", 294 313 "futures", 295 314 "ipld-core", 315 + "parakeet-db", 296 316 "serde", 297 317 "serde_bytes", 298 318 "serde_ipld_dagcbor", 319 + "serde_json", 299 320 "tokio", 300 321 "tokio-tungstenite", 301 322 "tracing", ··· 353 374 ] 354 375 355 376 [[package]] 377 + name = "darling" 378 + version = "0.20.10" 379 + source = "registry+https://github.com/rust-lang/crates.io-index" 380 + checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" 381 + dependencies = [ 382 + "darling_core", 383 + "darling_macro", 384 + ] 385 + 386 + [[package]] 387 + name = "darling_core" 388 + version = "0.20.10" 389 + source = "registry+https://github.com/rust-lang/crates.io-index" 390 + checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" 391 + dependencies = [ 392 + "fnv", 393 + "ident_case", 394 + "proc-macro2", 395 + "quote", 396 + "strsim", 397 + "syn", 398 + ] 399 + 400 + [[package]] 401 + name = "darling_macro" 402 + version = "0.20.10" 403 + source = "registry+https://github.com/rust-lang/crates.io-index" 404 + checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" 405 + dependencies = [ 406 + "darling_core", 407 + "quote", 408 + "syn", 409 + ] 410 + 411 + [[package]] 356 412 name = "data-encoding" 357 413 version = "2.7.0" 358 414 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 379 435 ] 380 436 381 437 [[package]] 438 + name = "deadpool" 439 + version = "0.12.1" 440 + source = "registry+https://github.com/rust-lang/crates.io-index" 441 + checksum = "6541a3916932fe57768d4be0b1ffb5ec7cbf74ca8c903fdfd5c0fe8aa958f0ed" 442 + dependencies = [ 443 + "deadpool-runtime", 444 + "num_cpus", 445 + "tokio", 446 + ] 447 + 448 + [[package]] 449 + name = "deadpool-runtime" 450 + version = "0.1.4" 451 + source = "registry+https://github.com/rust-lang/crates.io-index" 452 + checksum = "092966b41edc516079bdf31ec78a2e0588d1d0c08f78b91d8307215928642b2b" 453 + 454 + [[package]] 455 + name = "diesel" 456 + version = "2.2.6" 457 + source = "registry+https://github.com/rust-lang/crates.io-index" 458 + checksum = "ccf1bedf64cdb9643204a36dd15b19a6ce8e7aa7f7b105868e9f1fad5ffa7d12" 459 + dependencies = [ 460 + "bitflags", 461 + "byteorder", 462 + "chrono", 463 + "diesel_derives", 464 + "itoa", 465 + "serde_json", 466 + ] 467 + 468 + [[package]] 469 + name = "diesel-async" 470 + version = "0.5.2" 471 + source = "registry+https://github.com/rust-lang/crates.io-index" 472 + checksum = "51a307ac00f7c23f526a04a77761a0519b9f0eb2838ebf5b905a58580095bdcb" 473 + dependencies = [ 474 + "async-trait", 475 + "deadpool", 476 + "diesel", 477 + "futures-util", 478 + "scoped-futures", 479 + "tokio", 480 + "tokio-postgres", 481 + ] 482 + 483 + [[package]] 484 + name = "diesel_derives" 485 + version = "2.2.3" 486 + source = "registry+https://github.com/rust-lang/crates.io-index" 487 + checksum = "e7f2c3de51e2ba6bf2a648285696137aaf0f5f487bcbea93972fe8a364e131a4" 488 + dependencies = [ 489 + "diesel_table_macro_syntax", 490 + "dsl_auto_type", 491 + "proc-macro2", 492 + "quote", 493 + "syn", 494 + ] 495 + 496 + [[package]] 497 + name = "diesel_table_macro_syntax" 498 + version = "0.2.0" 499 + source = "registry+https://github.com/rust-lang/crates.io-index" 500 + checksum = "209c735641a413bc68c4923a9d6ad4bcb3ca306b794edaa7eb0b3228a99ffb25" 501 + dependencies = [ 502 + "syn", 503 + ] 504 + 505 + [[package]] 382 506 name = "digest" 383 507 version = "0.10.7" 384 508 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 386 510 dependencies = [ 387 511 "block-buffer", 388 512 "crypto-common", 513 + "subtle", 389 514 ] 390 515 391 516 [[package]] 517 + name = "dsl_auto_type" 518 + version = "0.1.2" 519 + source = "registry+https://github.com/rust-lang/crates.io-index" 520 + checksum = "c5d9abe6314103864cc2d8901b7ae224e0ab1a103a0a416661b4097b0779b607" 521 + dependencies = [ 522 + "darling", 523 + "either", 524 + "heck", 525 + "proc-macro2", 526 + "quote", 527 + "syn", 528 + ] 529 + 530 + [[package]] 531 + name = "either" 532 + version = "1.13.0" 533 + source = "registry+https://github.com/rust-lang/crates.io-index" 534 + checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" 535 + 536 + [[package]] 392 537 name = "equivalent" 393 538 version = "1.0.1" 394 539 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 413 558 "indenter", 414 559 "once_cell", 415 560 ] 561 + 562 + [[package]] 563 + name = "fallible-iterator" 564 + version = "0.2.0" 565 + source = "registry+https://github.com/rust-lang/crates.io-index" 566 + checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" 416 567 417 568 [[package]] 418 569 name = "fastrand" ··· 594 745 checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" 595 746 596 747 [[package]] 748 + name = "hermit-abi" 749 + version = "0.3.9" 750 + source = "registry+https://github.com/rust-lang/crates.io-index" 751 + checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" 752 + 753 + [[package]] 754 + name = "hmac" 755 + version = "0.12.1" 756 + source = "registry+https://github.com/rust-lang/crates.io-index" 757 + checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" 758 + dependencies = [ 759 + "digest", 760 + ] 761 + 762 + [[package]] 597 763 name = "http" 598 764 version = "1.2.0" 599 765 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 632 798 dependencies = [ 633 799 "cc", 634 800 ] 801 + 802 + [[package]] 803 + name = "ident_case" 804 + version = "1.0.1" 805 + source = "registry+https://github.com/rust-lang/crates.io-index" 806 + checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" 635 807 636 808 [[package]] 637 809 name = "indenter" ··· 723 895 checksum = "04cbf5b083de1c7e0222a7a51dbfdba1cbe1c6ab0b15e29fff3f6c077fd9cd9f" 724 896 725 897 [[package]] 898 + name = "md-5" 899 + version = "0.10.6" 900 + source = "registry+https://github.com/rust-lang/crates.io-index" 901 + checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" 902 + dependencies = [ 903 + "cfg-if", 904 + "digest", 905 + ] 906 + 907 + [[package]] 726 908 name = "memchr" 727 909 version = "2.7.4" 728 910 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 807 989 ] 808 990 809 991 [[package]] 992 + name = "num_cpus" 993 + version = "1.16.0" 994 + source = "registry+https://github.com/rust-lang/crates.io-index" 995 + checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" 996 + dependencies = [ 997 + "hermit-abi", 998 + "libc", 999 + ] 1000 + 1001 + [[package]] 810 1002 name = "object" 811 1003 version = "0.36.7" 812 1004 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 875 1067 name = "parakeet" 876 1068 version = "0.1.0" 877 1069 dependencies = [ 1070 + "diesel", 1071 + "diesel-async", 878 1072 "eyre", 879 1073 "figment", 1074 + "parakeet-db", 880 1075 "serde", 881 1076 "tokio", 882 1077 "tracing", ··· 884 1079 ] 885 1080 886 1081 [[package]] 1082 + name = "parakeet-db" 1083 + version = "0.1.0" 1084 + dependencies = [ 1085 + "chrono", 1086 + "diesel", 1087 + "serde_json", 1088 + ] 1089 + 1090 + [[package]] 887 1091 name = "parakeet-lexgen" 888 1092 version = "0.1.0" 889 1093 dependencies = [ ··· 942 1146 ] 943 1147 944 1148 [[package]] 1149 + name = "percent-encoding" 1150 + version = "2.3.1" 1151 + source = "registry+https://github.com/rust-lang/crates.io-index" 1152 + checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" 1153 + 1154 + [[package]] 1155 + name = "phf" 1156 + version = "0.11.3" 1157 + source = "registry+https://github.com/rust-lang/crates.io-index" 1158 + checksum = "1fd6780a80ae0c52cc120a26a1a42c1ae51b247a253e4e06113d23d2c2edd078" 1159 + dependencies = [ 1160 + "phf_shared", 1161 + ] 1162 + 1163 + [[package]] 1164 + name = "phf_shared" 1165 + version = "0.11.3" 1166 + source = "registry+https://github.com/rust-lang/crates.io-index" 1167 + checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5" 1168 + dependencies = [ 1169 + "siphasher", 1170 + ] 1171 + 1172 + [[package]] 945 1173 name = "pin-project-lite" 946 1174 version = "0.2.16" 947 1175 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 960 1188 checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" 961 1189 962 1190 [[package]] 1191 + name = "postgres-protocol" 1192 + version = "0.6.7" 1193 + source = "registry+https://github.com/rust-lang/crates.io-index" 1194 + checksum = "acda0ebdebc28befa84bee35e651e4c5f09073d668c7aed4cf7e23c3cda84b23" 1195 + dependencies = [ 1196 + "base64", 1197 + "byteorder", 1198 + "bytes", 1199 + "fallible-iterator", 1200 + "hmac", 1201 + "md-5", 1202 + "memchr", 1203 + "rand", 1204 + "sha2", 1205 + "stringprep", 1206 + ] 1207 + 1208 + [[package]] 1209 + name = "postgres-types" 1210 + version = "0.2.8" 1211 + source = "registry+https://github.com/rust-lang/crates.io-index" 1212 + checksum = "f66ea23a2d0e5734297357705193335e0a957696f34bed2f2faefacb2fec336f" 1213 + dependencies = [ 1214 + "bytes", 1215 + "fallible-iterator", 1216 + "postgres-protocol", 1217 + ] 1218 + 1219 + [[package]] 963 1220 name = "ppv-lite86" 964 1221 version = "0.2.20" 965 1222 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1088 1345 ] 1089 1346 1090 1347 [[package]] 1348 + name = "scoped-futures" 1349 + version = "0.1.4" 1350 + source = "registry+https://github.com/rust-lang/crates.io-index" 1351 + checksum = "1b24aae2d0636530f359e9d5ef0c04669d11c5e756699b27a6a6d845d8329091" 1352 + dependencies = [ 1353 + "pin-project-lite", 1354 + ] 1355 + 1356 + [[package]] 1091 1357 name = "scopeguard" 1092 1358 version = "1.2.0" 1093 1359 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1183 1449 version = "0.10.6" 1184 1450 source = "registry+https://github.com/rust-lang/crates.io-index" 1185 1451 checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" 1452 + dependencies = [ 1453 + "cfg-if", 1454 + "cpufeatures", 1455 + "digest", 1456 + ] 1457 + 1458 + [[package]] 1459 + name = "sha2" 1460 + version = "0.10.8" 1461 + source = "registry+https://github.com/rust-lang/crates.io-index" 1462 + checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" 1186 1463 dependencies = [ 1187 1464 "cfg-if", 1188 1465 "cpufeatures", ··· 1214 1491 ] 1215 1492 1216 1493 [[package]] 1494 + name = "siphasher" 1495 + version = "1.0.1" 1496 + source = "registry+https://github.com/rust-lang/crates.io-index" 1497 + checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" 1498 + 1499 + [[package]] 1217 1500 name = "slab" 1218 1501 version = "0.4.9" 1219 1502 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1239 1522 ] 1240 1523 1241 1524 [[package]] 1525 + name = "stringprep" 1526 + version = "0.1.5" 1527 + source = "registry+https://github.com/rust-lang/crates.io-index" 1528 + checksum = "7b4df3d392d81bd458a8a621b8bffbd2302a12ffe288a9d931670948749463b1" 1529 + dependencies = [ 1530 + "unicode-bidi", 1531 + "unicode-normalization", 1532 + "unicode-properties", 1533 + ] 1534 + 1535 + [[package]] 1242 1536 name = "strsim" 1243 1537 version = "0.11.1" 1244 1538 source = "registry+https://github.com/rust-lang/crates.io-index" 1245 1539 checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" 1540 + 1541 + [[package]] 1542 + name = "subtle" 1543 + version = "2.6.1" 1544 + source = "registry+https://github.com/rust-lang/crates.io-index" 1545 + checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" 1246 1546 1247 1547 [[package]] 1248 1548 name = "syn" ··· 1300 1600 ] 1301 1601 1302 1602 [[package]] 1603 + name = "tinyvec" 1604 + version = "1.8.1" 1605 + source = "registry+https://github.com/rust-lang/crates.io-index" 1606 + checksum = "022db8904dfa342efe721985167e9fcd16c29b226db4397ed752a761cfce81e8" 1607 + dependencies = [ 1608 + "tinyvec_macros", 1609 + ] 1610 + 1611 + [[package]] 1612 + name = "tinyvec_macros" 1613 + version = "0.1.1" 1614 + source = "registry+https://github.com/rust-lang/crates.io-index" 1615 + checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" 1616 + 1617 + [[package]] 1303 1618 name = "tokio" 1304 1619 version = "1.43.0" 1305 1620 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1339 1654 ] 1340 1655 1341 1656 [[package]] 1657 + name = "tokio-postgres" 1658 + version = "0.7.12" 1659 + source = "registry+https://github.com/rust-lang/crates.io-index" 1660 + checksum = "3b5d3742945bc7d7f210693b0c58ae542c6fd47b17adbbda0885f3dcb34a6bdb" 1661 + dependencies = [ 1662 + "async-trait", 1663 + "byteorder", 1664 + "bytes", 1665 + "fallible-iterator", 1666 + "futures-channel", 1667 + "futures-util", 1668 + "log", 1669 + "parking_lot", 1670 + "percent-encoding", 1671 + "phf", 1672 + "pin-project-lite", 1673 + "postgres-protocol", 1674 + "postgres-types", 1675 + "rand", 1676 + "socket2", 1677 + "tokio", 1678 + "tokio-util", 1679 + "whoami", 1680 + ] 1681 + 1682 + [[package]] 1342 1683 name = "tokio-tungstenite" 1343 1684 version = "0.26.1" 1344 1685 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1353 1694 ] 1354 1695 1355 1696 [[package]] 1697 + name = "tokio-util" 1698 + version = "0.7.13" 1699 + source = "registry+https://github.com/rust-lang/crates.io-index" 1700 + checksum = "d7fcaa8d55a2bdd6b83ace262b016eca0d79ee02818c5c1bcdf0305114081078" 1701 + dependencies = [ 1702 + "bytes", 1703 + "futures-core", 1704 + "futures-sink", 1705 + "pin-project-lite", 1706 + "tokio", 1707 + ] 1708 + 1709 + [[package]] 1356 1710 name = "toml" 1357 1711 version = "0.8.19" 1358 1712 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1478 1832 ] 1479 1833 1480 1834 [[package]] 1835 + name = "unicode-bidi" 1836 + version = "0.3.18" 1837 + source = "registry+https://github.com/rust-lang/crates.io-index" 1838 + checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5" 1839 + 1840 + [[package]] 1481 1841 name = "unicode-ident" 1482 1842 version = "1.0.14" 1483 1843 source = "registry+https://github.com/rust-lang/crates.io-index" 1484 1844 checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" 1845 + 1846 + [[package]] 1847 + name = "unicode-normalization" 1848 + version = "0.1.24" 1849 + source = "registry+https://github.com/rust-lang/crates.io-index" 1850 + checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" 1851 + dependencies = [ 1852 + "tinyvec", 1853 + ] 1854 + 1855 + [[package]] 1856 + name = "unicode-properties" 1857 + version = "0.1.3" 1858 + source = "registry+https://github.com/rust-lang/crates.io-index" 1859 + checksum = "e70f2a8b45122e719eb623c01822704c4e0907e7e426a05927e1a1cfff5b75d0" 1485 1860 1486 1861 [[package]] 1487 1862 name = "unsigned-varint" ··· 1536 1911 checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" 1537 1912 1538 1913 [[package]] 1914 + name = "wasite" 1915 + version = "0.1.0" 1916 + source = "registry+https://github.com/rust-lang/crates.io-index" 1917 + checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" 1918 + 1919 + [[package]] 1539 1920 name = "wasm-bindgen" 1540 1921 version = "0.2.100" 1541 1922 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1591 1972 checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" 1592 1973 dependencies = [ 1593 1974 "unicode-ident", 1975 + ] 1976 + 1977 + [[package]] 1978 + name = "web-sys" 1979 + version = "0.3.77" 1980 + source = "registry+https://github.com/rust-lang/crates.io-index" 1981 + checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2" 1982 + dependencies = [ 1983 + "js-sys", 1984 + "wasm-bindgen", 1985 + ] 1986 + 1987 + [[package]] 1988 + name = "whoami" 1989 + version = "1.5.2" 1990 + source = "registry+https://github.com/rust-lang/crates.io-index" 1991 + checksum = "372d5b87f58ec45c384ba03563b03544dc5fadc3983e434b286913f5b4a9bb6d" 1992 + dependencies = [ 1993 + "redox_syscall", 1994 + "wasite", 1995 + "web-sys", 1594 1996 ] 1595 1997 1596 1998 [[package]]
+1
Cargo.toml
··· 4 4 members = [ 5 5 "consumer", 6 6 "parakeet", 7 + "parakeet-db", 7 8 "parakeet-lexgen" 8 9 ]
+4
consumer/Cargo.toml
··· 6 6 [dependencies] 7 7 chrono = { version = "0.4.39", features = ["serde"] } 8 8 ciborium = "0.2.2" 9 + diesel = { version = "2.2.6", features = ["chrono", "serde_json"] } 10 + diesel-async = { version = "0.5.2", features = ["deadpool", "postgres"] } 9 11 eyre = "0.6.12" 10 12 figment = { version = "0.10.19", features = ["env", "toml"] } 11 13 futures = "0.3.31" 12 14 ipld-core = "0.4.1" 15 + parakeet-db = { path = "../parakeet-db" } 13 16 serde = { version = "1.0.217", features = ["derive"] } 14 17 serde_bytes = "0.11" 15 18 serde_ipld_dagcbor = "0.6.1" 19 + serde_json = "1.0.134" 16 20 tokio = { version = "1.42.0", features = ["full"] } 17 21 tokio-tungstenite = { version = "0.26.1", features = ["native-tls"] } 18 22 tracing = "0.1.40"
+3 -2
consumer/src/config.rs
··· 1 - use figment::Figment; 2 1 use figment::providers::{Env, Format, Toml}; 2 + use figment::Figment; 3 3 use serde::Deserialize; 4 4 5 5 pub(crate) fn load_config() -> eyre::Result<Config> { ··· 14 14 #[derive(Debug, Deserialize)] 15 15 pub struct Config { 16 16 pub relay_source: String, 17 - } 17 + pub database_url: String, 18 + }
+11 -7
consumer/src/indexer/mod.rs
··· 1 + use diesel_async::AsyncPgConnection; 2 + use diesel_async::pooled_connection::deadpool::Pool; 1 3 use crate::firehose::{AtpAccountEvent, AtpCommitEvent, AtpIdentityEvent, FirehoseEvent}; 2 4 use tokio::sync::mpsc::Receiver; 3 5 4 - pub async fn relay_indexer(mut rx: Receiver<FirehoseEvent>) -> eyre::Result<()> { 6 + pub async fn relay_indexer(pool: Pool<AsyncPgConnection>, mut rx: Receiver<FirehoseEvent>) -> eyre::Result<()> { 7 + let mut conn = pool.get().await?; 8 + 5 9 while let Some(event) = rx.recv().await { 6 10 let res = match event { 7 - FirehoseEvent::Identity(identity) => index_identity(identity).await, 8 - FirehoseEvent::Account(account) => index_account(account).await, 9 - FirehoseEvent::Commit(commit) => index_commit(commit).await, 11 + FirehoseEvent::Identity(identity) => index_identity(&mut conn, identity).await, 12 + FirehoseEvent::Account(account) => index_account(&mut conn, account).await, 13 + FirehoseEvent::Commit(commit) => index_commit(&mut conn, commit).await, 10 14 FirehoseEvent::Label(_) => { 11 15 // We handle all labels through direct connections to labelers 12 16 tracing::warn!("got #labels from the relay"); ··· 22 26 Ok(()) 23 27 } 24 28 25 - async fn index_identity(identity: AtpIdentityEvent) -> eyre::Result<()> { 29 + async fn index_identity(conn: &mut AsyncPgConnection, identity: AtpIdentityEvent) -> eyre::Result<()> { 26 30 Ok(()) 27 31 } 28 32 29 - async fn index_account(account: AtpAccountEvent) -> eyre::Result<()> { 33 + async fn index_account(conn: &mut AsyncPgConnection, account: AtpAccountEvent) -> eyre::Result<()> { 30 34 Ok(()) 31 35 } 32 36 33 - async fn index_commit(commit: AtpCommitEvent) -> eyre::Result<()> { 37 + async fn index_commit(conn: &mut AsyncPgConnection, commit: AtpCommitEvent) -> eyre::Result<()> { 34 38 Ok(()) 35 39 }
+7 -1
consumer/src/main.rs
··· 1 + use diesel_async::AsyncPgConnection; 2 + use diesel_async::pooled_connection::AsyncDieselConnectionManager; 3 + use diesel_async::pooled_connection::deadpool::Pool; 1 4 use tokio::sync::mpsc::Sender; 2 5 3 6 mod config; ··· 10 13 11 14 let conf = config::load_config()?; 12 15 16 + let db_mgr = AsyncDieselConnectionManager::<AsyncPgConnection>::new(&conf.database_url); 17 + let pool = Pool::builder(db_mgr).build()?; 18 + 13 19 let (tx, rx) = tokio::sync::mpsc::channel::<firehose::FirehoseEvent>(64); 14 20 15 21 let relay_firehose = firehose::FirehoseConsumer::new_relay(&conf.relay_source, None).await?; 16 22 17 23 let firehose_handle = tokio::spawn(relay_consumer(relay_firehose, tx)); 18 - let indexer_handle = tokio::spawn(indexer::relay_indexer(rx)); 24 + let indexer_handle = tokio::spawn(indexer::relay_indexer(pool.clone(), rx)); 19 25 20 26 let (firehose_res, indexer_res) = tokio::try_join!{ 21 27 firehose_handle,
+9
diesel.toml
··· 1 + # For documentation on how to configure this file, 2 + # see https://diesel.rs/guides/configuring-diesel-cli 3 + 4 + [print_schema] 5 + file = "parakeet-db/src/schema.rs" 6 + custom_type_derives = ["diesel::query_builder::QueryId"] 7 + 8 + [migrations_directory] 9 + dir = "migrations"
migrations/.keep

This is a binary file and will not be displayed.

+6
migrations/00000000000000_diesel_initial_setup/down.sql
··· 1 + -- This file was automatically created by Diesel to setup helper functions 2 + -- and other internal bookkeeping. This file is safe to edit, any future 3 + -- changes will be added to existing projects as new migrations. 4 + 5 + DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass); 6 + DROP FUNCTION IF EXISTS diesel_set_updated_at();
+36
migrations/00000000000000_diesel_initial_setup/up.sql
··· 1 + -- This file was automatically created by Diesel to setup helper functions 2 + -- and other internal bookkeeping. This file is safe to edit, any future 3 + -- changes will be added to existing projects as new migrations. 4 + 5 + 6 + 7 + 8 + -- Sets up a trigger for the given table to automatically set a column called 9 + -- `updated_at` whenever the row is modified (unless `updated_at` was included 10 + -- in the modified columns) 11 + -- 12 + -- # Example 13 + -- 14 + -- ```sql 15 + -- CREATE TABLE users (id SERIAL PRIMARY KEY, updated_at TIMESTAMP NOT NULL DEFAULT NOW()); 16 + -- 17 + -- SELECT diesel_manage_updated_at('users'); 18 + -- ``` 19 + CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$ 20 + BEGIN 21 + EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s 22 + FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl); 23 + END; 24 + $$ LANGUAGE plpgsql; 25 + 26 + CREATE OR REPLACE FUNCTION diesel_set_updated_at() RETURNS trigger AS $$ 27 + BEGIN 28 + IF ( 29 + NEW IS DISTINCT FROM OLD AND 30 + NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at 31 + ) THEN 32 + NEW.updated_at := current_timestamp; 33 + END IF; 34 + RETURN NEW; 35 + END; 36 + $$ LANGUAGE plpgsql;
+9
parakeet-db/Cargo.toml
··· 1 + [package] 2 + name = "parakeet-db" 3 + version = "0.1.0" 4 + edition = "2021" 5 + 6 + [dependencies] 7 + chrono = { version = "0.4.39", features = ["serde"] } 8 + diesel = { version = "2.2.6", features = ["chrono", "serde_json"] } 9 + serde_json = "1.0.134"
+2
parakeet-db/src/lib.rs
··· 1 + pub mod models; 2 + pub mod schema;
parakeet-db/src/models.rs

This is a binary file and will not be displayed.

+2
parakeet-db/src/schema.rs
··· 1 + // @generated automatically by Diesel CLI. 2 +
+3
parakeet/Cargo.toml
··· 4 4 edition = "2021" 5 5 6 6 [dependencies] 7 + diesel = { version = "2.2.6", features = ["chrono", "serde_json"] } 8 + diesel-async = { version = "0.5.2", features = ["deadpool", "postgres"] } 7 9 eyre = "0.6.12" 8 10 figment = { version = "0.10.19", features = ["env", "toml"] } 11 + parakeet-db = { path = "../parakeet-db" } 9 12 serde = { version = "1.0.217", features = ["derive"] } 10 13 tokio = { version = "1.42.0", features = ["full"] } 11 14 tracing = "0.1.40"
+2 -1
parakeet/src/config.rs
··· 1 - use figment::Figment; 2 1 use figment::providers::{Env, Format, Toml}; 2 + use figment::Figment; 3 3 use serde::Deserialize; 4 4 5 5 pub(crate) fn load_config() -> eyre::Result<Config> { ··· 13 13 14 14 #[derive(Debug, Deserialize)] 15 15 pub struct Config { 16 + pub database_url: String, 16 17 #[serde(default)] 17 18 pub server: ConfigServer, 18 19 }
+8 -1
parakeet/src/main.rs
··· 1 + use diesel_async::AsyncPgConnection; 2 + use diesel_async::pooled_connection::AsyncDieselConnectionManager; 3 + use diesel_async::pooled_connection::deadpool::Pool; 4 + 1 5 mod config; 2 6 3 7 #[tokio::main] 4 - async fn main() -> eyre::Result<()> { 8 + async fn main() -> eyre::Result<()> { 5 9 tracing_subscriber::fmt::init(); 6 10 7 11 let conf = config::load_config()?; 12 + 13 + let db_mgr = AsyncDieselConnectionManager::<AsyncPgConnection>::new(&conf.database_url); 14 + let pool = Pool::builder(db_mgr).build()?; 8 15 9 16 Ok(()) 10 17 }