Created
December 27, 2015 00:34
-
-
Save pcottle/0435146cc7299b1d4165 to your computer and use it in GitHub Desktop.
DB caching
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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