22const GithubDb = require ( "./index" ) ;
33
44const db = GithubDb ( { db :process . env . db , token :process . env . token } ) ;
5- function generatePath ( { repo, branch, sha, pull_request_number, filename} ) {
6- return `${ repo } /${ branch } /${ pull_request_number } /${ sha } /${ filename } `
7- }
8- function generateDir ( { repo, branch, sha, pull_request_number} ) {
9- return `${ repo } /${ branch } /${ pull_request_number } /${ sha } `
10- }
11- async function test ( ) {
12- const { identifier :id1 } = await db . add ( { document :"user" } , { name :"John" } ) ;
13- console . log ( "added user" , id1 ) ;
14-
15- const { identifier :id2 } = await db . add ( { document :"user" } , { name :"Will" } ) ;
16- console . log ( "added user" , id2 ) ;
175
18- const user = await db . fetchOne ( { document :"user" , identifier :id1 } ) ;
6+ async function test ( ) {
7+ const { identifier} = await db . add ( { document :"user" } , { name :"John" } ) ;
8+ console . log ( "added user" , identifier ) ;
9+
10+ const user = await db . fetchOne ( { document :"user" , identifier} ) ;
1911 console . log ( "fetched user" , user ) ;
2012
21- const updated = await db . update ( { document :"user" , identifier : id1 } , { name :"John Cena" } ) ;
13+ const updated = await db . update ( { document :"user" , identifier} , { name :"John Cena" } ) ;
2214 console . log ( "updated user" , updated ) ;
2315
2416 const users = await db . fetchAll ( { document :"user" } ) ;
@@ -29,31 +21,9 @@ async function test(){
2921 }
3022}
3123
32- async function testWithPath ( ) {
33- const identifier = generatePath ( { repo :"repo" , branch :"branch" , sha :"sha" , pull_request_number :"pull_request_number" , filename :"filename" } ) ;
34- const dir = generateDir ( { repo :"repo" , branch :"branch" , sha :"sha" , pull_request_number :"pull_request_number" } ) ;
35-
36- const { identifier :id1 } = await db . add ( { document :"diff" , identifier} , { name :"John" } ) ;
37- console . log ( "added diff" , id1 ) ;
38-
39- const updated = await db . update ( { document :"diff" , identifier :id1 } , { name :"John Cena" } ) ;
40- console . log ( "updated diff" , updated ) ;
41-
42- const user = await db . fetchOne ( { document :"diff" , identifier} , id1 ) ;
43- console . log ( "fetched diff" , user ) ;
44-
45-
46- const users = await db . fetchAll ( { document :"diff" , identifier :dir } ) ;
47- console . log ( "fetched diffs" , users ) ;
48- for ( const { identifier} of users ) {
49- const result = await db . delete ( { document :"diff" , identifier} ) ;
50- console . log ( "delete users" , result ) ;
51- }
52- }
5324( async function ( ) {
5425 try {
5526 await test ( ) ;
56- await testWithPath ( )
5727 } catch ( error ) {
5828 console . error ( error ) ;
5929 }
0 commit comments