Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,4 @@ android/keystores/debug.keystore
lib/

.env*.local
.env
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,17 @@ import PouchDB from './pouchdb'

const pouch = new PouchDB('mydb', {
adapter: 'react-native-sqlite',
// Other options
})
```

### Options

You can specify the following options in the PouchDB options:

- `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.
- `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.

## Troubleshootings

### Fails to install crypto shim with `install()` on launch
Expand Down
1 change: 1 addition & 0 deletions example/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = getConfig(
},
},
],
['module:react-native-dotenv'],
],
},
{ root, pkg }
Expand Down
3 changes: 2 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"@react-native/eslint-config": "0.79.2",
"@react-native/metro-config": "0.79.2",
"@react-native/typescript-config": "0.79.2",
"react-native-builder-bob": "^0.35.2"
"react-native-builder-bob": "^0.35.2",
"react-native-dotenv": "^3.4.11"
},
"op-sqlite": {
"fts5": true
Expand Down
15 changes: 13 additions & 2 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ console.log(`Using ${uiManager}`)

const pouch = new PouchDB('mydb', {
adapter: 'react-native-sqlite',
revs_limit: 100,
})
// @ts-ignore
globalThis.pouch = pouch

// async function run() {
// const db = open({ name: 'test' })
Expand Down Expand Up @@ -126,14 +129,22 @@ export default function App() {
}
}
const handleReplicate = async () => {
setResult('Replicating from remote...')
const remoteUrl = process.env.COUCHDB_URL
setResult(`Replicating from remote...${remoteUrl}`)
if (!remoteUrl) {
setResult(
'CouchDB URL is not set. Please set COUCHDB_URL environment variable in `.env.local`.'
)
return
}
try {
const result = await pouch.replicate
.from(process.env.EXPO_PUBLIC_COUCHDB_URL, { live: false })
.from(remoteUrl, { live: false })
.on('error', (err: any) => console.log('error:', err))
console.log('ret:', result)
setResult(JSON.stringify(result, null, 2))
} catch (e: any) {
console.error(e)
setResult(e.name + ': ' + e.message)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
api.auto_compaction = false

api._name = opts.name
logger.debug('Creating SqlPouch instance: %s', api._name)
logger.debug('Creating SqlPouch instance: %s', api._name, opts)

const sqlOpts = Object.assign({}, opts, { name: opts.name + '.sqlite' })
const openDBResult = openDB(sqlOpts)
Expand Down Expand Up @@ -249,7 +249,7 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
logger.debug('**********bulkDocs!!!!!!!!!!!!!!!!!!!')
try {
const response = await sqliteBulkDocs(
{ revs_limit: undefined },
{ revs_limit: opts.revs_limit },
req,
reqOpts,
api,
Expand Down
4 changes: 3 additions & 1 deletion src/openDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { TransactionQueue } from './transactionQueue'
import type { DB } from '@op-engineering/op-sqlite'

type SQLiteOpenParams = Parameters<typeof open>
export type OpenDatabaseOptions = SQLiteOpenParams[0]
export type OpenDatabaseOptions = SQLiteOpenParams[0] & {
revs_limit?: number
}
type OpenDatabaseResult =
| {
db: DB
Expand Down
19 changes: 19 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5880,6 +5880,13 @@ __metadata:
languageName: node
linkType: hard

"dotenv@npm:^16.4.5":
version: 16.5.0
resolution: "dotenv@npm:16.5.0"
checksum: 6543fe87b5ddf2d60dd42df6616eec99148a5fc150cb4530fef5bda655db5204a3afa0e6f25f7cd64b20657ace4d79c0ef974bec32fdb462cad18754191e7a90
languageName: node
linkType: hard

"dunder-proto@npm:^1.0.0, dunder-proto@npm:^1.0.1":
version: 1.0.1
resolution: "dunder-proto@npm:1.0.1"
Expand Down Expand Up @@ -11362,6 +11369,7 @@ __metadata:
react: 19.0.0
react-native: 0.79.2
react-native-builder-bob: ^0.35.2
react-native-dotenv: ^3.4.11
react-native-quick-crypto: ^0.7.8
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -11917,6 +11925,17 @@ __metadata:
languageName: node
linkType: hard

"react-native-dotenv@npm:^3.4.11":
version: 3.4.11
resolution: "react-native-dotenv@npm:3.4.11"
dependencies:
dotenv: ^16.4.5
peerDependencies:
"@babel/runtime": ^7.20.6
checksum: 3ebac2c2ed79dd7e4920fd3fc2da9187413b7190231618e4858b46c47833677838b96d531afe7bd5c4b0a60454dba40cb8708722210df5d522e30aefbf41da05
languageName: node
linkType: hard

"react-native-quick-base64@npm:^2.0.5":
version: 2.1.2
resolution: "react-native-quick-base64@npm:2.1.2"
Expand Down