Skip to content

Commit ddeb786

Browse files
author
Christopher J. Brody
committed
start react-native-sqlite-plugin-support-dev
with React Native module support for Android and iOS based on custom React Native module generated by reate-react-native-module 0.3.0 (known to be missing some needed components) including initial demotestapp (missing React Native build artifacts, dependencies & devDependencies updates needed) TBD MISSING ReactNativeJson.java module which is needed to deal with the background SQL batches on Android. FUTURE TODO: it is desired to find a more efficient way to deal with the background SQL batch objects, with a nicer abstraction between Cordova and React Native. FUTURE TODO: some of these changes should be cleaned up at some point FUTURE TBD improve the abstraction of differences between Cordova and React Native
1 parent 22127ad commit ddeb786

31 files changed

+1351
-97
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.pbxproj -text

.gitignore

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,51 @@
1+
# OSX
2+
#
13
.DS_Store
24
.metadata/*
35
*.swp
46
*~
57

6-
node_modules
8+
# node.js
9+
#
10+
node_modules/
711
package-lock.json
12+
npm-debug.log
813
yarn.lock
9-
14+
yarn-error.log
1015

1116
spec/myplugin
1217
spec/plugins
1318
spec/platforms
1419

15-
*.xcworkspace
20+
# Xcode
21+
#
22+
build/
23+
*.pbxuser
24+
!default.pbxuser
25+
*.mode1v3
26+
!default.mode1v3
27+
*.mode2v3
28+
!default.mode2v3
29+
*.perspectivev3
30+
!default.perspectivev3
31+
xcuserdata
32+
*.xccheckout
33+
*.moved-aside
34+
DerivedData
35+
*.hmap
36+
*.ipa
37+
*.xcuserstate
38+
project.xcworkspace
39+
40+
# Android/IntelliJ
41+
#
42+
build/
43+
.idea
44+
.gradle
45+
local.properties
46+
*.iml
47+
48+
# BUCK
49+
buck-out/
50+
\.buckd/
51+
*.keystore

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
demotestapp

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changes
22

3+
###### react-native-sqlite-plugin-support-dev 0.0.1-dev
4+
5+
- Add React Native module support, based on custom React Native module generated by create-react-native-module 0.3.0 (known to be missing some needed components)
6+
37
##### cordova-sqlite-storage-ext-commoncore 1.0.0
48

59
- Some CoffeeScript / JavaScript updates

README.md

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
# Cross-platform SQLite storage plugin for Cordova/PhoneGap - cordova-sqlite-storage plugin version
1+
# Cross-platform SQLite storage plugin for React Native - react-native-sqlite-plugin-support-dev version branch - known to be missing some needed components
22

33
Native SQLite component with API based on HTML5/[Web SQL (DRAFT) API](http://www.w3.org/TR/webdatabase/) for the following platforms:
44
- Android
55
- iOS
6+
7+
Platforms not supported by this version branch:
8+
69
- macOS ("osx" platform)
710
- Windows 10 (UWP) DESKTOP and MOBILE (see below for major limitations)
811

12+
<!-- FUTURE TBD:
913
Browser platform is currently supported with some limitations as described in [browser platform usage notes](#browser-platform-usage-notes) section below, will be supported with more features such as numbered parameters and SQL batch API in the near future.
14+
- -->
1015

1116
**LICENSE:** MIT (see [LICENSE.md](./LICENSE.md) for details, including third-party components used by this plugin)
1217

@@ -16,6 +21,69 @@ __WARNING: Multiple SQLite problem on all platforms__ _with possible corruption
1621

1722
The primary author and maintainer [@brodybits (Chris Brody)](https://github.com/brodybits) is happy to offer free consulting for a limited time period - please see <https://xpbrew.consulting> for more information.
1823

24+
<!-- Installation & usage instructions as generated: -->
25+
26+
# Getting started on React Native
27+
28+
`$ npm install react-native-sqlite-plugin-support-dev --save`
29+
30+
### Mostly automatic installation
31+
32+
`$ react-native link react-native-sqlite-plugin-support-dev`
33+
34+
### Manual installation
35+
36+
NOTE THAT MANUAL INSTALLATION OF THIS REACT NATIVE MODULE IS NOT TESTED AND NOT SUPPORTED.
37+
38+
#### iOS
39+
40+
1. In XCode, in the project navigator, right click `Libraries``Add Files to [your project's name]`
41+
2. Go to `node_modules``react-native-sqlite-plugin-support-dev` and add `SQLiteSupport.xcodeproj`
42+
3. In XCode, in the project navigator, select your project. Add `libSQLiteSupport.a` to your project's `Build Phases``Link Binary With Libraries`
43+
4. Run your project (`Cmd+R`)<
44+
45+
#### Android
46+
47+
1. Open up `android/app/src/main/java/[...]/MainApplication.java`
48+
- Add `import io.sqlc.SQLiteSupportPackage;` to the imports at the top of the file
49+
- Add `new SQLiteSupportPackage()` to the list returned by the `getPackages()` method
50+
51+
2. Append the following lines to `android/settings.gradle`:
52+
53+
```
54+
include ':react-native-sqlite-plugin-support-dev'
55+
project(':react-native-sqlite-plugin-support-dev').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sqlite-plugin-support-dev/android')
56+
```
57+
58+
3. Insert the following lines inside the dependencies block in `android/app/build.gradle`:
59+
60+
```
61+
compile project(':react-native-sqlite-plugin-support-dev')
62+
```
63+
64+
# Usage
65+
66+
```javascript
67+
import sqlitePlugin from 'react-native-sqlite-plugin-support-dev';
68+
69+
const db = sqlitePlugin.openDatabase({name:'demo.db', location: 'default'});
70+
71+
db.transaction((tx) => {
72+
tx.executeSql('SELECT UPPER(?) as upperText', ['Some ASCII text'], (tx, rs) => {
73+
this.setState({
74+
...this.state,
75+
upperText: rs.rows.item(0).upperText
76+
});
77+
});
78+
});
79+
```
80+
81+
# Original documentation from Cordova
82+
83+
**IMPORTANT NOTICE:** On React Native the `sqlitePlugin` object must be imported as documented above and used instead of `window.sqlitePlugin`. And there is no `deviceready` event to wait for on React Native.
84+
85+
DOC TODO: UPDATE DOCUMENTATION BELOW TO REFLECT CORRECT IMPORT AND USE OF THE CORRECT API OBJECT AND NO DEVICE READY EVENT
86+
1987
## NEW MAJOR RELEASE Coming with BREAKING CHANGES
2088

2189
A new major release is planned as discussed in ([xpbrew/cordova-sqlite-storage#773](https://github.com/xpbrew/cordova-sqlite-storage/issues/773)).

SQLitePlugin.coffee.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
# Top-level SQLite plugin objects
88

9-
## root window object:
9+
## imported exec utility object:
1010

11-
root = @
11+
SQLiteSupport = require('./SQLiteSupport.js').default
1212

1313
## constant(s):
1414

@@ -79,7 +79,8 @@
7979

8080
getProxyFunction = (methodName) ->
8181
(argsArray, successCallback, errorCallback) ->
82-
cordova.exec successCallback, errorCallback, 'SQLitePlugin', methodName, argsArray
82+
SQLiteSupport[methodName] argsArray, successCallback, errorCallback || -> return
83+
return
8384

8485
SQLiteProxy =
8586
echoStringValue: getProxyFunction 'echoStringValue'
@@ -1043,7 +1044,10 @@
10431044
openDatabase: SQLiteFactory.openDatabase
10441045
deleteDatabase: SQLiteFactory.deleteDatabase
10451046

1046-
root.sqlitePlugin = sqlitePlugin
1047+
# keep for initial testing purposes
1048+
sampleMethod: SQLiteSupport.sampleMethod
1049+
1050+
module.exports = sqlitePlugin
10471051

10481052
## vim directives
10491053

SQLiteSupport.podspec

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require "json"
2+
3+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4+
5+
Pod::Spec.new do |s|
6+
s.name = "SQLiteSupport"
7+
s.version = package["version"]
8+
s.summary = package["description"]
9+
s.description = <<-DESC
10+
SQLiteSupport
11+
DESC
12+
s.homepage = "https://github.com/author/SQLiteSupport"
13+
s.license = "MIT"
14+
# s.license = { :type => "MIT", :file => "FILE_LICENSE" }
15+
s.author = { "author" => "author@domain.cn" }
16+
s.platform = :ios, "7.0"
17+
s.source = { :git => "https://github.com/author/SQLiteSupport.git", :tag => "#{s.version}" }
18+
19+
s.source_files = "ios/**/*.{h,m}"
20+
s.requires_arc = true
21+
22+
s.dependency "React"
23+
#s.dependency "others"
24+
end
25+

android/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
README
2+
======
3+
4+
If you want to publish the lib as a maven dependency, follow these steps before publishing a new version to npm:
5+
6+
1. Be sure to have the Android [SDK](https://developer.android.com/studio/index.html) and [NDK](https://developer.android.com/ndk/guides/index.html) installed
7+
2. Be sure to have a `local.properties` file in this folder that points to the Android SDK and NDK
8+
```
9+
ndk.dir=/Users/{username}/Library/Android/sdk/ndk-bundle
10+
sdk.dir=/Users/{username}/Library/Android/sdk
11+
```
12+
3. Delete the `maven` folder
13+
4. Run `sudo ./gradlew installArchives`
14+
5. Verify that latest set of generated files is in the maven folder with the correct version number

android/build.gradle

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
buildscript {
2+
repositories {
3+
google()
4+
jcenter()
5+
}
6+
7+
dependencies {
8+
// Matches the RN Hello World template
9+
// https://github.com/facebook/react-native/blob/1e8f3b11027fe0a7514b4fc97d0798d3c64bc895/local-cli/templates/HelloWorld/android/build.gradle#L8
10+
classpath 'com.android.tools.build:gradle:3.2.1'
11+
}
12+
}
13+
14+
apply plugin: 'com.android.library'
15+
apply plugin: 'maven'
16+
17+
def safeExtGet(prop, fallback) {
18+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
19+
}
20+
21+
def DEFAULT_COMPILE_SDK_VERSION = 28
22+
def DEFAULT_BUILD_TOOLS_VERSION = "28.0.2"
23+
def DEFAULT_MIN_SDK_VERSION = 16
24+
def DEFAULT_TARGET_SDK_VERSION = 27
25+
26+
android {
27+
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
28+
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
29+
30+
defaultConfig {
31+
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
32+
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
33+
versionCode 1
34+
versionName "1.0"
35+
}
36+
lintOptions {
37+
abortOnError false
38+
}
39+
}
40+
41+
repositories {
42+
maven {
43+
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
44+
// Matches the RN Hello World template
45+
// https://github.com/facebook/react-native/blob/1e8f3b11027fe0a7514b4fc97d0798d3c64bc895/local-cli/templates/HelloWorld/android/build.gradle#L21
46+
url "$projectDir/../node_modules/react-native/android"
47+
}
48+
mavenCentral()
49+
}
50+
51+
dependencies {
52+
compile 'com.facebook.react:react-native:+'
53+
54+
// THANKS to @andpor (Andrzej Porebski)
55+
// https://github.com/andpor
56+
compile files('../../cordova-sqlite-storage-dependencies/libs/sqlite-connector.jar')
57+
compile files('../../cordova-sqlite-storage-dependencies/libs/sqlite-native-driver.jar')
58+
}
59+
60+
def configureReactNativePom(def pom) {
61+
def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text)
62+
63+
pom.project {
64+
name packageJson.title
65+
artifactId packageJson.name
66+
version = packageJson.version
67+
group = "io.sqlc"
68+
description packageJson.description
69+
url packageJson.repository.baseUrl
70+
71+
licenses {
72+
license {
73+
name packageJson.license
74+
url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename
75+
distribution 'repo'
76+
}
77+
}
78+
79+
developers {
80+
developer {
81+
id packageJson.author.username
82+
name packageJson.author.name
83+
}
84+
}
85+
}
86+
}
87+
88+
afterEvaluate { project ->
89+
90+
task androidJavadoc(type: Javadoc) {
91+
source = android.sourceSets.main.java.srcDirs
92+
classpath += files(android.bootClasspath)
93+
classpath += files(project.getConfigurations().getByName('compile').asList())
94+
include '**/*.java'
95+
}
96+
97+
task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
98+
classifier = 'javadoc'
99+
from androidJavadoc.destinationDir
100+
}
101+
102+
task androidSourcesJar(type: Jar) {
103+
classifier = 'sources'
104+
from android.sourceSets.main.java.srcDirs
105+
include '**/*.java'
106+
}
107+
108+
android.libraryVariants.all { variant ->
109+
def name = variant.name.capitalize()
110+
task "jar${name}"(type: Jar, dependsOn: variant.javaCompile) {
111+
from variant.javaCompile.destinationDir
112+
}
113+
}
114+
115+
artifacts {
116+
archives androidSourcesJar
117+
archives androidJavadocJar
118+
}
119+
120+
task installArchives(type: Upload) {
121+
configuration = configurations.archives
122+
repositories.mavenDeployer {
123+
// Deploy to react-native-event-bridge/maven, ready to publish to npm
124+
repository url: "file://${projectDir}/../android/maven"
125+
126+
configureReactNativePom pom
127+
}
128+
}
129+
}

android/src/main/AndroidManifest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="io.sqlc">
3+
4+
</manifest>

0 commit comments

Comments
 (0)