Skip to content

Instantly share code, notes, and snippets.

@pcottle
Created December 27, 2015 00:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcottle/0435146cc7299b1d4165 to your computer and use it in GitHub Desktop.
Save pcottle/0435146cc7299b1d4165 to your computer and use it in GitHub Desktop.
DB caching
var SQLite = require('react-native-sqlite');
var rethrowOr = require('../utils/rethrowOr');
var _dbToTables = {};
var DBInfo = {
getTables: function(database, callback) {
var dbName = database.getName();
if (_dbToTables[dbName]) {
callback(dbName);
return;
}
var tables = [];
database.executeSQL(
`SELECT name FROM sqlite_master where type='table'`,
[],
(row) => tables.push(row.name),
rethrowOr(() => {
_dbToTables[dbName] = tables;
callback(tables);
}),
);
},
};
module.exports = DBInfo;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment