@@ -5,38 +5,47 @@ use regex::Regex;
55use serde:: Serialize ;
66use sled:: { Db , Tree } ;
77
8+ pub mod discussion;
9+
10+ pub ( crate ) use discussion:: DiscussionDbSchema ;
11+
812use crate :: {
913 github:: { GitHubIssue , GitHubPullRequests } ,
1014 graphql:: { Issue , PullRequest } ,
1115} ;
16+
1217const ISSUE_TREE_NAME : & str = "issues" ;
1318const PULL_REQUEST_TREE_NAME : & str = "pull_requests" ;
19+ const DISCUSSION_TREE_NAME : & str = "discussions" ;
1420
1521#[ derive( Clone ) ]
1622pub ( crate ) struct Database {
1723 db : Db ,
1824 issue_tree : Tree ,
1925 pull_request_tree : Tree ,
26+ discussion_tree : Tree ,
2027}
2128
2229impl Database {
2330 fn connect_db ( path : & Path ) -> Result < Db > {
2431 Ok ( sled:: open ( path) ?)
2532 }
2633
27- fn connect_trees ( db : & Db ) -> Result < ( Tree , Tree ) > {
34+ fn connect_trees ( db : & Db ) -> Result < ( Tree , Tree , Tree ) > {
2835 let issue_tree = db. open_tree ( ISSUE_TREE_NAME ) ?;
2936 let pull_request_tree = db. open_tree ( PULL_REQUEST_TREE_NAME ) ?;
30- Ok ( ( issue_tree, pull_request_tree) )
37+ let discussion_tree = db. open_tree ( DISCUSSION_TREE_NAME ) ?;
38+ Ok ( ( issue_tree, pull_request_tree, discussion_tree) )
3139 }
3240
3341 pub ( crate ) fn connect ( db_path : & Path ) -> Result < Database > {
3442 let db = Database :: connect_db ( db_path) ?;
35- let ( issue_tree, pull_request_tree) = Database :: connect_trees ( & db) ?;
43+ let ( issue_tree, pull_request_tree, discussion_tree ) = Database :: connect_trees ( & db) ?;
3644 Ok ( Database {
3745 db,
3846 issue_tree,
3947 pull_request_tree,
48+ discussion_tree,
4049 } )
4150 }
4251
@@ -155,7 +164,7 @@ impl<T: TryFromKeyValue> DoubleEndedIterator for Iter<T> {
155164 }
156165}
157166
158- pub ( crate ) fn parse_key ( key : & [ u8 ] ) -> Result < ( String , String , i64 ) > {
167+ pub ( crate ) fn parse_key ( key : & [ u8 ] ) -> Result < ( String , String , i32 ) > {
159168 let re = Regex :: new ( r"(?P<owner>\S+)/(?P<name>\S+)#(?P<number>[0-9]+)" ) . expect ( "valid regex" ) ;
160169 if let Some ( caps) = re. captures (
161170 String :: from_utf8 ( key. to_vec ( ) )
@@ -176,7 +185,7 @@ pub(crate) fn parse_key(key: &[u8]) -> Result<(String, String, i64)> {
176185 . name ( "number" )
177186 . ok_or_else ( || anyhow ! ( "invalid key" ) ) ?
178187 . as_str ( )
179- . parse :: < i64 > ( )
188+ . parse :: < i32 > ( )
180189 . context ( "invalid key" ) ?;
181190 Ok ( ( owner, name, number) )
182191 } else {
0 commit comments