@@ -10,7 +10,7 @@ import {
1010 ScrollView ,
1111} from 'react-native'
1212import PouchDB from './pouchdb'
13- import { open } from '@op-engineering/op-sqlite'
13+ // import { open } from '@op-engineering/op-sqlite'
1414
1515// @ts -ignore eslint-ignore-next-line
1616const uiManager = global ?. nativeFabricUIManager ? 'Fabric' : 'Paper'
@@ -21,26 +21,26 @@ const pouch = new PouchDB('mydb', {
2121 adapter : 'react-native-sqlite' ,
2222} )
2323
24- async function run ( ) {
25- const db = open ( { name : 'test' } )
26- db . execute (
27- 'CREATE TABLE IF NOT EXISTS test (id INTEGER PRIMARY KEY, name TEXT)'
28- )
29-
30- await db . transaction ( async ( tx ) => {
31- await Promise . all (
32- Array . from ( { length : 100 } , ( _ , i ) =>
33- tx
34- . executeAsync ( 'INSERT INTO test (name) VALUES (?)' , [ 'foo' ] )
35- . then ( ( result ) => console . log ( 'insertId:' , result . insertId ) )
36- )
37- )
38- } )
39-
40- db . execute ( 'DROP TABLE IF EXISTS test' )
41- }
42-
43- run ( )
24+ // async function run() {
25+ // const db = open({ name: 'test' })
26+ // db.execute(
27+ // 'CREATE TABLE IF NOT EXISTS test (id INTEGER PRIMARY KEY, name TEXT)'
28+ // )
29+ //
30+ // await db.transaction(async (tx) => {
31+ // await Promise.all(
32+ // Array.from({ length: 100 }, (_, i) =>
33+ // tx
34+ // .executeAsync('INSERT INTO test (name) VALUES (?)', ['foo'])
35+ // .then((result) => console.log('insertId:', result.insertId))
36+ // )
37+ // )
38+ // })
39+ //
40+ // db.execute('DROP TABLE IF EXISTS test')
41+ // }
42+ //
43+ // run()
4444
4545export default function App ( ) {
4646 const [ result , setResult ] = React . useState < string > ( '' )
@@ -81,6 +81,39 @@ export default function App() {
8181 console . log ( 'put:' , r )
8282 setResult ( JSON . stringify ( r , null , 2 ) )
8383 }
84+ const handlePutMultiDocs = async ( ) => {
85+ setResult ( '' )
86+ let count = 0
87+
88+ try {
89+ const res = await pouch . bulkDocs (
90+ Array . from ( { length : 10 } , ( _ , i ) => ( {
91+ _id : `test:${ i } ` ,
92+ title : 'Heroes' ,
93+ count : count + 1 ,
94+ } ) )
95+ )
96+ setResult ( JSON . stringify ( res , null , 2 ) )
97+ } catch ( e : any ) {
98+ setResult ( e . name + ': ' + e . message + '\n' + e . stack )
99+ console . error ( e )
100+ }
101+ }
102+ // const handlePutMultiDocs = async () => {
103+ // setResult('')
104+ // let count = 0
105+ //
106+ // const res = await Promise.all(
107+ // Array.from({ length: 100 }, (_, i) =>
108+ // pouch.put({
109+ // _id: `test:${i}`,
110+ // title: 'Heroes',
111+ // count: count + 1,
112+ // })
113+ // )
114+ // )
115+ // setResult(JSON.stringify(res, null, 2))
116+ // }
84117 const handleRemoveDoc = async ( ) => {
85118 setResult ( '' )
86119 try {
@@ -147,6 +180,32 @@ export default function App() {
147180 }
148181 }
149182
183+ const handleWriteLocalDoc = async ( ) => {
184+ setResult ( '' )
185+ try {
186+ const result = await pouch . put ( {
187+ _id : '_local/mydoc' ,
188+ title : 'Heroes' ,
189+ } )
190+ console . log ( 'ret:' , result )
191+ setResult ( JSON . stringify ( result , null , 2 ) )
192+ } catch ( e : any ) {
193+ setResult ( e . name + ': ' + e . message )
194+ }
195+ }
196+
197+ const handleRemoveLocalDoc = async ( ) => {
198+ setResult ( '' )
199+ try {
200+ const mydoc = await pouch . get ( '_local/mydoc' )
201+ const result = await pouch . remove ( mydoc )
202+ console . log ( 'ret:' , result )
203+ setResult ( JSON . stringify ( result , null , 2 ) )
204+ } catch ( e : any ) {
205+ setResult ( e . name + ': ' + e . message )
206+ }
207+ }
208+
150209 return (
151210 < ScrollView
152211 style = { styles . container }
@@ -161,6 +220,9 @@ export default function App() {
161220 < TouchableOpacity onPress = { handlePutDoc } style = { styles . button } >
162221 < Text style = { styles . buttonText } > Put a doc</ Text >
163222 </ TouchableOpacity >
223+ < TouchableOpacity onPress = { handlePutMultiDocs } style = { styles . button } >
224+ < Text style = { styles . buttonText } > Put docs</ Text >
225+ </ TouchableOpacity >
164226 < TouchableOpacity onPress = { handleRemoveDoc } style = { styles . button } >
165227 < Text style = { styles . buttonText } > Delete a doc</ Text >
166228 </ TouchableOpacity >
@@ -176,6 +238,12 @@ export default function App() {
176238 < TouchableOpacity onPress = { handleGetAttachment } style = { styles . button } >
177239 < Text style = { styles . buttonText } > Get an attachment</ Text >
178240 </ TouchableOpacity >
241+ < TouchableOpacity onPress = { handleWriteLocalDoc } style = { styles . button } >
242+ < Text style = { styles . buttonText } > Write a local doc</ Text >
243+ </ TouchableOpacity >
244+ < TouchableOpacity onPress = { handleRemoveLocalDoc } style = { styles . button } >
245+ < Text style = { styles . buttonText } > Remove a local doc</ Text >
246+ </ TouchableOpacity >
179247 { imageData && (
180248 < Image
181249 source = { { uri : imageData } }
0 commit comments