Skip to content

Commit cb47f2b

Browse files
authored
Merge pull request #53 from craftzdog/opt-revs_limit
Support `revs_limit` option
2 parents e06162e + 4b1e965 commit cb47f2b

File tree

8 files changed

+49
-6
lines changed

8 files changed

+49
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,4 @@ android/keystores/debug.keystore
7878
lib/
7979

8080
.env*.local
81+
.env

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,17 @@ import PouchDB from './pouchdb'
8181

8282
const pouch = new PouchDB('mydb', {
8383
adapter: 'react-native-sqlite',
84+
// Other options
8485
})
8586
```
8687

88+
### Options
89+
90+
You can specify the following options in the PouchDB options:
91+
92+
- `location`: The location of the SQLite database file. See [op-sqlite's docs](https://op-engineering.github.io/op-sqlite/docs/configuration) for more details.
93+
- `encryptionKey`: The encryption key for SQLCipher. See [op-sqlite's docs](https://op-engineering.github.io/op-sqlite/docs/api#sqlcipher-open) for more details.
94+
8795
## Troubleshootings
8896

8997
### Fails to install crypto shim with `install()` on launch

example/babel.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module.exports = getConfig(
2121
},
2222
},
2323
],
24+
['module:react-native-dotenv'],
2425
],
2526
},
2627
{ root, pkg }

example/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"@react-native/eslint-config": "0.79.2",
3333
"@react-native/metro-config": "0.79.2",
3434
"@react-native/typescript-config": "0.79.2",
35-
"react-native-builder-bob": "^0.35.2"
35+
"react-native-builder-bob": "^0.35.2",
36+
"react-native-dotenv": "^3.4.11"
3637
},
3738
"op-sqlite": {
3839
"fts5": true

example/src/App.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ console.log(`Using ${uiManager}`)
1919

2020
const pouch = new PouchDB('mydb', {
2121
adapter: 'react-native-sqlite',
22+
revs_limit: 100,
2223
})
24+
// @ts-ignore
25+
globalThis.pouch = pouch
2326

2427
// async function run() {
2528
// const db = open({ name: 'test' })
@@ -126,14 +129,22 @@ export default function App() {
126129
}
127130
}
128131
const handleReplicate = async () => {
129-
setResult('Replicating from remote...')
132+
const remoteUrl = process.env.COUCHDB_URL
133+
setResult(`Replicating from remote...${remoteUrl}`)
134+
if (!remoteUrl) {
135+
setResult(
136+
'CouchDB URL is not set. Please set COUCHDB_URL environment variable in `.env.local`.'
137+
)
138+
return
139+
}
130140
try {
131141
const result = await pouch.replicate
132-
.from(process.env.EXPO_PUBLIC_COUCHDB_URL, { live: false })
142+
.from(remoteUrl, { live: false })
133143
.on('error', (err: any) => console.log('error:', err))
134144
console.log('ret:', result)
135145
setResult(JSON.stringify(result, null, 2))
136146
} catch (e: any) {
147+
console.error(e)
137148
setResult(e.name + ': ' + e.message)
138149
}
139150
}

src/core.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
9494
api.auto_compaction = false
9595

9696
api._name = opts.name
97-
logger.debug('Creating SqlPouch instance: %s', api._name)
97+
logger.debug('Creating SqlPouch instance: %s', api._name, opts)
9898

9999
const sqlOpts = Object.assign({}, opts, { name: opts.name + '.sqlite' })
100100
const openDBResult = openDB(sqlOpts)
@@ -249,7 +249,7 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
249249
logger.debug('**********bulkDocs!!!!!!!!!!!!!!!!!!!')
250250
try {
251251
const response = await sqliteBulkDocs(
252-
{ revs_limit: undefined },
252+
{ revs_limit: opts.revs_limit },
253253
req,
254254
reqOpts,
255255
api,

src/openDatabase.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { TransactionQueue } from './transactionQueue'
33
import type { DB } from '@op-engineering/op-sqlite'
44

55
type SQLiteOpenParams = Parameters<typeof open>
6-
export type OpenDatabaseOptions = SQLiteOpenParams[0]
6+
export type OpenDatabaseOptions = SQLiteOpenParams[0] & {
7+
revs_limit?: number
8+
}
79
type OpenDatabaseResult =
810
| {
911
db: DB

yarn.lock

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5880,6 +5880,13 @@ __metadata:
58805880
languageName: node
58815881
linkType: hard
58825882

5883+
"dotenv@npm:^16.4.5":
5884+
version: 16.5.0
5885+
resolution: "dotenv@npm:16.5.0"
5886+
checksum: 6543fe87b5ddf2d60dd42df6616eec99148a5fc150cb4530fef5bda655db5204a3afa0e6f25f7cd64b20657ace4d79c0ef974bec32fdb462cad18754191e7a90
5887+
languageName: node
5888+
linkType: hard
5889+
58835890
"dunder-proto@npm:^1.0.0, dunder-proto@npm:^1.0.1":
58845891
version: 1.0.1
58855892
resolution: "dunder-proto@npm:1.0.1"
@@ -11362,6 +11369,7 @@ __metadata:
1136211369
react: 19.0.0
1136311370
react-native: 0.79.2
1136411371
react-native-builder-bob: ^0.35.2
11372+
react-native-dotenv: ^3.4.11
1136511373
react-native-quick-crypto: ^0.7.8
1136611374
languageName: unknown
1136711375
linkType: soft
@@ -11917,6 +11925,17 @@ __metadata:
1191711925
languageName: node
1191811926
linkType: hard
1191911927

11928+
"react-native-dotenv@npm:^3.4.11":
11929+
version: 3.4.11
11930+
resolution: "react-native-dotenv@npm:3.4.11"
11931+
dependencies:
11932+
dotenv: ^16.4.5
11933+
peerDependencies:
11934+
"@babel/runtime": ^7.20.6
11935+
checksum: 3ebac2c2ed79dd7e4920fd3fc2da9187413b7190231618e4858b46c47833677838b96d531afe7bd5c4b0a60454dba40cb8708722210df5d522e30aefbf41da05
11936+
languageName: node
11937+
linkType: hard
11938+
1192011939
"react-native-quick-base64@npm:^2.0.5":
1192111940
version: 2.1.2
1192211941
resolution: "react-native-quick-base64@npm:2.1.2"

0 commit comments

Comments
 (0)