├── .babelrc ├── .gitignore ├── .npmignore ├── LICENSE.md ├── README.md ├── __test__ └── test.js ├── examples └── rn │ ├── ReduxPersistSQLiteExample │ ├── .babelrc │ ├── .buckconfig │ ├── .flowconfig │ ├── .gitattributes │ ├── .gitignore │ ├── .watchmanconfig │ ├── App.js │ ├── actions │ │ ├── action-types.js │ │ └── actions.js │ ├── android │ │ ├── app │ │ │ ├── BUCK │ │ │ ├── build.gradle │ │ │ ├── proguard-rules.pro │ │ │ └── src │ │ │ │ └── main │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── reduxpersistsqliteexample │ │ │ │ │ ├── MainActivity.java │ │ │ │ │ └── MainApplication.java │ │ │ │ └── res │ │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ │ └── values │ │ │ │ ├── strings.xml │ │ │ │ └── styles.xml │ │ ├── build.gradle │ │ ├── gradle.properties │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ ├── keystores │ │ │ ├── BUCK │ │ │ └── debug.keystore.properties │ │ └── settings.gradle │ ├── app.json │ ├── components │ │ └── todo.js │ ├── index.js │ ├── ios │ │ ├── ReduxPersistSQLiteExample-tvOS │ │ │ └── Info.plist │ │ ├── ReduxPersistSQLiteExample-tvOSTests │ │ │ └── Info.plist │ │ ├── ReduxPersistSQLiteExample.xcodeproj │ │ │ ├── project.pbxproj │ │ │ └── xcshareddata │ │ │ │ └── xcschemes │ │ │ │ ├── ReduxPersistSQLiteExample-tvOS.xcscheme │ │ │ │ └── ReduxPersistSQLiteExample.xcscheme │ │ ├── ReduxPersistSQLiteExample │ │ │ ├── AppDelegate.h │ │ │ ├── AppDelegate.m │ │ │ ├── Base.lproj │ │ │ │ └── LaunchScreen.xib │ │ │ ├── Images.xcassets │ │ │ │ ├── AppIcon.appiconset │ │ │ │ │ └── Contents.json │ │ │ │ └── Contents.json │ │ │ ├── Info.plist │ │ │ └── main.m │ │ └── ReduxPersistSQLiteExampleTests │ │ │ ├── Info.plist │ │ │ └── ReduxPersistSQLiteExampleTests.m │ ├── package.json │ ├── reducers │ │ └── todo-reducers.js │ ├── store.js │ └── yarn.lock │ └── ReduxPersistSQLiteSecondExample │ ├── .babelrc │ ├── .buckconfig │ ├── .flowconfig │ ├── .gitattributes │ ├── .gitignore │ ├── .watchmanconfig │ ├── App.js │ ├── actions │ ├── action-types.js │ └── actions.js │ ├── android │ ├── app │ │ ├── BUCK │ │ ├── build.gradle │ │ ├── proguard-rules.pro │ │ └── src │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ └── com │ │ │ │ └── reduxpersistsqliteexample │ │ │ │ ├── MainActivity.java │ │ │ │ └── MainApplication.java │ │ │ └── res │ │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ │ └── values │ │ │ ├── strings.xml │ │ │ └── styles.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── keystores │ │ ├── BUCK │ │ └── debug.keystore.properties │ └── settings.gradle │ ├── app.json │ ├── components │ └── todo.js │ ├── index.js │ ├── ios │ ├── ReduxPersistSQLiteExample-tvOS │ │ └── Info.plist │ ├── ReduxPersistSQLiteExample-tvOSTests │ │ └── Info.plist │ ├── ReduxPersistSQLiteExample.xcodeproj │ │ ├── project.pbxproj │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ ├── ReduxPersistSQLiteExample-tvOS.xcscheme │ │ │ └── ReduxPersistSQLiteExample.xcscheme │ ├── ReduxPersistSQLiteExample │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Base.lproj │ │ │ └── LaunchScreen.xib │ │ ├── Images.xcassets │ │ │ ├── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ │ └── Contents.json │ │ ├── Info.plist │ │ └── main.m │ └── ReduxPersistSQLiteExampleTests │ │ ├── Info.plist │ │ └── ReduxPersistSQLiteExampleTests.m │ ├── package.json │ ├── reducers │ └── todo-reducers.js │ ├── store.js │ └── yarn.lock ├── index.js └── package.json /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "env", 4 | "stage-3" 5 | ], 6 | "plugins": [ 7 | ["transform-class-properties", { "spec": true }], 8 | "transform-flow-strip-types", 9 | "transform-runtime" 10 | ] 11 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Redux Offline specific ignores 2 | lib/ 3 | 4 | # Logs 5 | logs 6 | *.log 7 | npm-debug.log* 8 | 9 | # Runtime data 10 | pids 11 | *.pid 12 | *.seed 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # node-waf configuration 27 | .lock-wscript 28 | 29 | # Compiled binary addons (http://nodejs.org/api/addons.html) 30 | build/Release 31 | 32 | # Dependency directories 33 | node_modules 34 | jspm_packages 35 | 36 | # Optional npm cache directory 37 | .npm 38 | 39 | # Optional REPL history 40 | .node_repl_history 41 | 42 | .DS_Store 43 | 44 | # yarn.lock exists so don't commit package-lock.json 45 | package-lock.json 46 | 47 | # local file history 48 | .history -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .babelrc 2 | .eslintrc.js 3 | .flowconfig 4 | .travis.yml 5 | .idea/** 6 | examples/** 7 | docs/* -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Prasun Pal 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # redux-persist-sqlite-storage 2 | 3 | A redux-persist store adaptor which uses SQLite database to persist store. 4 | 5 | # Motivation 6 | 7 | By default redux-persist uses `AsyncStorage` as storage engine in react-native. This is a drop-in replacemet of `AsyncStorage`. 8 | 9 | The library is inspired by `react-native-sqlite-storage`. 10 | 11 | # Install 12 | ```bash 13 | npm install --save redux-persist-sqlite-storage 14 | ``` 15 | 16 | Please do follow the installation steps to install `react-native-sqlite-storage`. 17 | 18 | # Usages 19 | First configure SQLite from below link 20 | 1. https://github.com/andpor/react-native-sqlite-storage 21 | 22 | Follow below steps after you have successfully configured the SQLite 23 | 24 | ```Javascript 25 | import SQLiteStorage from 'redux-persist-sqlite-storage'; 26 | import SQLite from 'react-native-sqlite-storage'; 27 | // Considering SQLite object is defined / imported 28 | 29 | // Pass any valid configuration as `config` parameter applied to react-native-sqlite-storage as per above link 30 | const storeEngine = SQLiteStorage(SQLite, config); 31 | 32 | // Now pass the storeEngine as value of store while configuring redux-persist 33 | 34 | const persistConfig = { 35 | ... 36 | store: storeEngine 37 | } 38 | 39 | ``` 40 | 41 | Please note that, the `config` object will take any valid configuration as accepted by `react-native-sqlite-storage`. 42 | The default configuration only consider `name` and `location` 43 | 44 | ```Javascript 45 | const defaultConfig = { 46 | name: 'sqlite-storage', 47 | location: 'default' 48 | }; 49 | ``` 50 | 51 | The object return by `SQLiteStorage` function has 5 methods and each of the method returns `Promise` as well as callback upon completion of any operation (compatable with redux-persist 5.x.x version) 52 | 53 | Following functions are supported 54 | 55 | ```Javascript 56 | getItem(key: string, [callback]: ?(error: ?Error, result: ?string) => void) 57 | ``` 58 | ```Javascript 59 | setitem(key: string, value: string, [callback]: ?(error: ?Error) => void) 60 | ``` 61 | ```Javascript 62 | removeItem(key: string, [callback]: ?(error: ?Error) => void) 63 | ``` 64 | ```Javascript 65 | getAllKeys([callback]: ?(error: ?Error, keys: ?Array) => void) 66 | ``` 67 | ```Javascript 68 | clear([callback]: ?(error: ?Error) => void) 69 | ``` 70 | 71 | Above methods confirms to `AsyncStorage` method signatures 72 | 73 | # Tested under following enviornments 74 | Examples are located at `examples\rn` directory 75 | 76 | 1. `redux-persist@4.5.0` 77 | 2. `redux-persist@5.9.1` 78 | 79 | # Future enhancements 80 | Will support all of the methods supported by AsyncStorage. 81 | -------------------------------------------------------------------------------- /__test__/test.js: -------------------------------------------------------------------------------- 1 | import SQLiteStorage from '../index'; 2 | 3 | let SQLite = {}; 4 | let db = {}; 5 | beforeEach(() => { 6 | db = { transaction: () => { 7 | return { 8 | executeSql: (sql, param, sqlSuccess, sqlError) => { 9 | console.log(sql); 10 | } 11 | } 12 | } 13 | }; 14 | SQLite.openDatabase = (config, success, error) => { 15 | success(db); 16 | } 17 | }); 18 | 19 | test('initial db check', () => { 20 | console.log(SQLiteStorage(SQLite)); 21 | }); -------------------------------------------------------------------------------- /examples/rn/ReduxPersistSQLiteExample/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["react-native"] 3 | } 4 | -------------------------------------------------------------------------------- /examples/rn/ReduxPersistSQLiteExample/.buckconfig: -------------------------------------------------------------------------------- 1 | 2 | [android] 3 | target = Google Inc.:Google APIs:23 4 | 5 | [maven_repositories] 6 | central = https://repo1.maven.org/maven2 7 | -------------------------------------------------------------------------------- /examples/rn/ReduxPersistSQLiteExample/.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | ; We fork some components by platform 3 | .*/*[.]android.js 4 | 5 | ; Ignore "BUCK" generated dirs 6 | /\.buckd/ 7 | 8 | ; Ignore unexpected extra "@providesModule" 9 | .*/node_modules/.*/node_modules/fbjs/.* 10 | 11 | ; Ignore duplicate module providers 12 | ; For RN Apps installed via npm, "Libraries" folder is inside 13 | ; "node_modules/react-native" but in the source repo it is in the root 14 | .*/Libraries/react-native/React.js 15 | 16 | ; Ignore polyfills 17 | .*/Libraries/polyfills/.* 18 | 19 | ; Ignore metro 20 | .*/node_modules/metro/.* 21 | 22 | [include] 23 | 24 | [libs] 25 | node_modules/react-native/Libraries/react-native/react-native-interface.js 26 | node_modules/react-native/flow/ 27 | node_modules/react-native/flow-github/ 28 | 29 | [options] 30 | emoji=true 31 | 32 | module.system=haste 33 | 34 | munge_underscores=true 35 | 36 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub' 37 | 38 | module.file_ext=.js 39 | module.file_ext=.jsx 40 | module.file_ext=.json 41 | module.file_ext=.native.js 42 | 43 | suppress_type=$FlowIssue 44 | suppress_type=$FlowFixMe 45 | suppress_type=$FlowFixMeProps 46 | suppress_type=$FlowFixMeState 47 | 48 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) 49 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ 50 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy 51 | suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError 52 | 53 | [version] 54 | ^0.67.0 55 | -------------------------------------------------------------------------------- /examples/rn/ReduxPersistSQLiteExample/.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | -------------------------------------------------------------------------------- /examples/rn/ReduxPersistSQLiteExample/.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # Xcode 6 | # 7 | build/ 8 | *.pbxuser 9 | !default.pbxuser 10 | *.mode1v3 11 | !default.mode1v3 12 | *.mode2v3 13 | !default.mode2v3 14 | *.perspectivev3 15 | !default.perspectivev3 16 | xcuserdata 17 | *.xccheckout 18 | *.moved-aside 19 | DerivedData 20 | *.hmap 21 | *.ipa 22 | *.xcuserstate 23 | project.xcworkspace 24 | 25 | # Android/IntelliJ 26 | # 27 | build/ 28 | .idea 29 | .gradle 30 | local.properties 31 | *.iml 32 | 33 | # node.js 34 | # 35 | node_modules/ 36 | npm-debug.log 37 | yarn-error.log 38 | 39 | # BUCK 40 | buck-out/ 41 | \.buckd/ 42 | *.keystore 43 | 44 | # fastlane 45 | # 46 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 47 | # screenshots whenever they are needed. 48 | # For more information about the recommended setup visit: 49 | # https://docs.fastlane.tools/best-practices/source-control/ 50 | 51 | */fastlane/report.xml 52 | */fastlane/Preview.html 53 | */fastlane/screenshots 54 | 55 | # Bundle artifact 56 | *.jsbundle 57 | -------------------------------------------------------------------------------- /examples/rn/ReduxPersistSQLiteExample/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /examples/rn/ReduxPersistSQLiteExample/App.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Sample React Native App 3 | * https://github.com/facebook/react-native 4 | * @flow 5 | */ 6 | 7 | import React, { Component } from 'react'; 8 | import { 9 | Platform, 10 | StyleSheet, 11 | Text, 12 | View, 13 | ScrollView, 14 | Button 15 | } from 'react-native'; 16 | import { store, storeEngine} from './store'; 17 | import { Provider } from 'react-redux' 18 | import Todo from './components/todo'; 19 | 20 | const instructions = Platform.select({ 21 | ios: 'Press Cmd+R to reload,\n' + 22 | 'Cmd+D or shake for dev menu', 23 | android: 'Double tap R on your keyboard to reload,\n' + 24 | 'Shake or press menu button for dev menu', 25 | }); 26 | 27 | console.disableYellowBox = true; 28 | type Props = {}; 29 | export default class App extends Component { 30 | render() { 31 | return ( 32 | 33 | 34 | 35 |