Skip to content

Commit

Permalink
Remove old rnpm for react-native 0.60 (#361)
Browse files Browse the repository at this point in the history
* remvoe old rnpm

* fix project props

* remove dependency

* fix indentation

* start enable autolink

* change directory

* remove configs

* remove config

* move files

* change source_files path

* remove log from production

* remove console from core

* export plugin log

* change platfoms path again

* fix ios platform podspec path
  • Loading branch information
carlosroberto555 authored and andpor committed Aug 22, 2019
1 parent 04c34d2 commit 24d0182
Show file tree
Hide file tree
Showing 54 changed files with 62 additions and 50 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ xcuserdata
*.xcuserstate
*.xcscmblueprint
*.xcscheme
.vscode

android/.gradle/
# node.js
Expand Down
83 changes: 45 additions & 38 deletions lib/sqlite.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,17 @@ argsArray = function(fun) {

plugin.exec = function(method, options, success, error) {
if (plugin.sqlitePlugin.DEBUG){
console.log('SQLite.' + method + '(' + JSON.stringify(options) + ')');
plugin.log('SQLite.' + method + '(' + JSON.stringify(options) + ')');
}
NativeModules["SQLite"][method](options,success,error);
};

plugin.log = function(...messages) {
if (plugin.sqlitePlugin.DEBUG) {
console.log(...messages)
}
}

SQLitePlugin = function(openargs, openSuccess, openError) {
var dbname;
if (!(openargs && openargs['name'])) {
Expand All @@ -102,10 +108,10 @@ SQLitePlugin = function(openargs, openSuccess, openError) {
this.openSuccess = openSuccess;
this.openError = openError;
this.openSuccess || (this.openSuccess = function() {
console.log("DB opened: " + dbname);
plugin.log("DB opened: " + dbname);
});
this.openError || (this.openError = function(e) {
console.log(e.message);
plugin.log(e.message);
});
this.open(this.openSuccess, this.openError);
};
Expand All @@ -128,9 +134,9 @@ SQLitePlugin.prototype.addTransaction = function(t) {
this.startNextTransaction();
} else {
if (this.dbname in this.openDBs) {
console.log('new transaction is waiting for open operation');
plugin.log('new transaction is waiting for open operation');
} else {
console.log('database is closed, new transaction is [stuck] waiting until db is opened again!');
plugin.log('database is closed, new transaction is [stuck] waiting until db is opened again!');
}
}
};
Expand Down Expand Up @@ -158,12 +164,12 @@ SQLitePlugin.prototype.startNextTransaction = function() {
return function() {
var txLock;
if (!(_this.dbname in _this.openDBs) || _this.openDBs[_this.dbname] !== DB_STATE_OPEN) {
console.log('cannot start next transaction: database not open');
plugin.log('cannot start next transaction: database not open');
return;
}
txLock = txLocks[self.dbname];
if (!txLock) {
console.log('cannot start next transaction: database connection is lost');
plugin.log('cannot start next transaction: database connection is lost');
} else if (txLock.queue.length > 0 && !txLock.inProgress) {
txLock.inProgress = true;
txLock.queue.shift().start();
Expand Down Expand Up @@ -227,7 +233,7 @@ SQLitePlugin.prototype.sqlBatch = function(sqlStatements, success, error) {
if (!!error) {
return error(e);
} else {
console.log("Error handler not provided: ",e);
plugin.log("Error handler not provided: ",e);
}
};

Expand All @@ -239,19 +245,19 @@ SQLitePlugin.prototype.open = function(success, error) {
var openerrorcb, opensuccesscb;

if (this.dbname in this.openDBs && this.openDBs[this.dbname] === DB_STATE_OPEN) {
console.log('database already open: ' + this.dbname);
plugin.log('database already open: ' + this.dbname);
nextTick((function(_this) {
return function() {
success(_this);
};
})(this));
} else {
console.log('OPEN database: ' + this.dbname);
plugin.log('OPEN database: ' + this.dbname);
opensuccesscb = (function(_this) {
return function() {
var txLock;
if (!_this.openDBs[_this.dbname]) {
console.log('database was closed during open operation');
plugin.log('database was closed during open operation');
}
if (_this.dbname in _this.openDBs) {
_this.openDBs[_this.dbname] = DB_STATE_OPEN;
Expand All @@ -267,7 +273,7 @@ SQLitePlugin.prototype.open = function(success, error) {
})(this);
openerrorcb = (function(_this) {
return function() {
console.log('OPEN database: ' + _this.dbname + ' failed, aborting any pending transactions');
plugin.log('OPEN database: ' + _this.dbname + ' failed, aborting any pending transactions');
if (!!error) {
error(newSQLError('Could not open database'));
}
Expand All @@ -283,16 +289,16 @@ SQLitePlugin.prototype.open = function(success, error) {
SQLitePlugin.prototype.close = function(success, error) {
if (this.dbname in this.openDBs) {
if (txLocks[this.dbname] && txLocks[this.dbname].inProgress) {
console.log('cannot close: transaction is in progress');
plugin.log('cannot close: transaction is in progress');
error(newSQLError('database cannot be closed while a transaction is in progress'));
return;
}
console.log('CLOSE database: ' + this.dbname);
plugin.log('CLOSE database: ' + this.dbname);
delete this.openDBs[this.dbname];
if (txLocks[this.dbname]) {
console.log('closing db with transaction queue length: ' + txLocks[this.dbname].queue.length);
plugin.log('closing db with transaction queue length: ' + txLocks[this.dbname].queue.length);
} else {
console.log('closing db with no transaction lock state');
plugin.log('closing db with no transaction lock state');
}
let mysuccess = function(t, r) {
if (!!success) {
Expand All @@ -303,13 +309,13 @@ SQLitePlugin.prototype.close = function(success, error) {
if (!!error) {
return error(e);
} else {
console.log("Error handler not provided: ",e);
plugin.log("Error handler not provided: ",e);
}
};
plugin.exec("close",{path: this.dbname}, mysuccess, myerror);
} else {
var err = 'cannot close: database is not open';
console.log(err);
plugin.log(err);
if (error) {
nextTick(function() {
return error(err);
Expand All @@ -321,11 +327,11 @@ SQLitePlugin.prototype.close = function(success, error) {
SQLitePlugin.prototype.attach = function(dbNameToAttach, dbAlias, success, error) {
if (this.dbname in this.openDBs) {
if (txLocks[this.dbname] && txLocks[this.dbname].inProgress) {
console.log('cannot attach: transaction is in progress');
plugin.log('cannot attach: transaction is in progress');
error(newSQLError('database cannot be attached while a transaction is in progress'));
return;
}
console.log('ATTACH database ' + dbNameToAttach + ' to ' + this.dbname + ' with alias ' + dbAlias);
plugin.log('ATTACH database ' + dbNameToAttach + ' to ' + this.dbname + ' with alias ' + dbAlias);

let mysuccess = function(t, r) {
if (!!success) {
Expand All @@ -336,7 +342,7 @@ SQLitePlugin.prototype.attach = function(dbNameToAttach, dbAlias, success, error
if (!!error) {
return error(e);
} else {
console.log("Error handler not provided: ",e);
plugin.log("Error handler not provided: ",e);
}
};
plugin.exec("attach",{path: this.dbname, dbName: dbNameToAttach, dbAlias}, mysuccess, myerror);
Expand All @@ -353,29 +359,29 @@ SQLitePlugin.prototype.attach = function(dbNameToAttach, dbAlias, success, error
SQLitePlugin.prototype.detach = function(dbAlias, success, error) {
if (this.dbname in this.openDBs) {
if (txLocks[this.dbname] && txLocks[this.dbname].inProgress) {
console.log('cannot attach: transaction is in progress');
plugin.log('cannot attach: transaction is in progress');
error(newSQLError('database cannot be attached while a transaction is in progress'));
return;
}
console.log('DETACH database ' + dbAlias + ' from ' + this.dbname);
plugin.log('DETACH database ' + dbAlias + ' from ' + this.dbname);

let mysuccess = function(t, r) {
if (!!success) {
return success(r);
}
};
let myerror = function(e) {
console.log('ERR', e);
plugin.log('ERR', e);
if (!!error) {
return error(e);
} else {
console.log("Error handler not provided: ",e);
plugin.log("Error handler not provided: ",e);
}
};
this.executeSql('DETACH DATABASE ' + dbAlias, [], mysuccess, myerror)
} else {
var err = 'cannot attach: database is not open';
console.log(err);
plugin.log(err);
if (error) {
nextTick(function() {
return error(err);
Expand All @@ -395,7 +401,7 @@ SQLitePlugin.prototype.executeSql = function(statement, params, success, error)
if (!!error) {
return error(e);
} else {
console.log("Error handler not provided: ",e);
plugin.log("Error handler not provided: ",e);
}
};
myfn = function(tx) {
Expand Down Expand Up @@ -476,7 +482,7 @@ SQLitePluginTransaction.prototype.executeSql = function(sql, values, success, er
if (!!error) {
return error(e);
} else {
console.log("Error handler not provided: ",e);
plugin.log("Error handler not provided: ",e);
}
};
that.addStatement(sql, values, mysuccess, myerror);
Expand All @@ -498,10 +504,10 @@ SQLitePluginTransaction.prototype.addStatement = function(sql, values, success,
}
else if (t !== 'function') {
params.push(v.toString());
console.warn('addStatement - parameter of type <'+t+'> converted to string using toString()')
plugin.warn('addStatement - parameter of type <'+t+'> converted to string using toString()')
} else {
let errorMsg = 'Unsupported parameter type <'+t+'> found in addStatement()';
console.error(errorMsg);
plugin.error(errorMsg);
error(newSQLError(errorMsg));
return;
}
Expand All @@ -516,13 +522,13 @@ SQLitePluginTransaction.prototype.addStatement = function(sql, values, success,
};

SQLitePluginTransaction.prototype.handleStatementSuccess = function(handler, response) {
// console.log('handler response:',response,response.rows);
// plugin.log('handler response:',response,response.rows);
var payload, rows;
if (!handler) {
return;
}
rows = response.rows || [];
// console.log('handler rows now:',rows);
// plugin.log('handler rows now:',rows);
payload = {
rows: {
item: function(i) {
Expand All @@ -540,7 +546,7 @@ SQLitePluginTransaction.prototype.handleStatementSuccess = function(handler, res
rowsAffected: response.rowsAffected || 0,
insertId: response.insertId || void 0
};
// console.log('handler response payload:',payload);
// plugin.log('handler response payload:',payload);
handler(this, payload);
};

Expand Down Expand Up @@ -573,7 +579,7 @@ SQLitePluginTransaction.prototype.run = function() {
} catch (err) {
let errorMsg = JSON.stringify(err);
if(errorMsg === "{}") errorMsg = err.toString();
console.log("warning - exception while invoking a callback: " + errorMsg);
plugin.log("warning - exception while invoking a callback: " + errorMsg);
}

if (!didSucceed) {
Expand Down Expand Up @@ -629,7 +635,7 @@ SQLitePluginTransaction.prototype.run = function() {
};

var myerror = function(error) {
console.log("batch execution error: ",error);
plugin.log("batch execution error: ",error);
};

plugin.exec("backgroundExecuteSqlBatch",{
Expand Down Expand Up @@ -713,7 +719,7 @@ dblocations = {
SQLiteFactory = function(){};

SQLiteFactory.prototype.DEBUG = function(debug) {
console.log("Setting debug to:",debug);
plugin.log("Setting debug to:",debug);
plugin.sqlitePlugin.DEBUG = debug;
};

Expand Down Expand Up @@ -821,7 +827,7 @@ SQLiteFactory.prototype.deleteDatabase = function(first,success, error) {
if (!!error) {
return error(e);
} else {
console.log("deleteDatabase error handler not provided: ",e);
plugin.log("deleteDatabase error handler not provided: ",e);
}
};

Expand All @@ -831,7 +837,8 @@ SQLiteFactory.prototype.deleteDatabase = function(first,success, error) {
plugin.sqlitePlugin = {
SQLiteFactory : SQLiteFactory,
SQLitePluginTransaction : SQLitePluginTransaction,
SQLitePlugin : SQLitePlugin
SQLitePlugin : SQLitePlugin,
log: plugin.log
};

module.exports = plugin.sqlitePlugin;
8 changes: 0 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,5 @@
"homepage": "https://github.com/andpor/react-native-sqlite-storage",
"peerDependencies": {
"react-native": ">=0.14.0"
},
"rnpm": {
"ios": {
"project": "src/ios/SQLite.xcodeproj"
},
"android": {
"sourceDir": "src/android"
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion react-native-sqlite-storage.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Pod::Spec.new do |s|
s.osx.deployment_target = '10.10'

s.preserve_paths = 'README.md', 'LICENSE', 'package.json', 'sqlite.js'
s.source_files = "src/ios/*.{h,m}"
s.source_files = "platforms/ios/*.{h,m}"

s.dependency 'React'
s.library = 'sqlite3'
Expand Down
12 changes: 12 additions & 0 deletions react-native.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
dependency: {
platforms: {
ios: {
project: './platforms/ios/SQLite.xcodeproj'
},
android: {
sourceDir: './platforms/android'
}
}
}
}
6 changes: 3 additions & 3 deletions sqlite.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function createCallbackRuntime() {
let [returnValueExpected,prototype,fn,argsNeedPadding,reverseCallbacks,rejectOnError]= entry;
plugin[prototype].prototype[fn] = originalFns[prototype + "." + fn];
});
console.log("Callback based runtime ready");
plugin.log("Callback based runtime ready");
}
function createPromiseRuntime() {
config.forEach(entry => {
Expand All @@ -63,7 +63,7 @@ function createPromiseRuntime() {
}
};
let error = function(err){
console.log('error: ',fn,...args,arguments);
plugin.log('error: ',fn,...args,arguments);
if (rejectOnError) {
reject(err);
}
Expand All @@ -78,7 +78,7 @@ function createPromiseRuntime() {
return promise;
}
});
console.log("Promise based runtime ready");
plugin.log("Promise based runtime ready");
}
SQLiteFactory.prototype.enablePromise = enablePromiseRuntime;

Expand Down

0 comments on commit 24d0182

Please sign in to comment.