44 lines
862 B
JavaScript
44 lines
862 B
JavaScript
// __mocks__/expo-sqlite.js
|
|
const sqlite3 = require('sqlite3').verbose();
|
|
|
|
class SQLiteDatabase {
|
|
constructor(name) {
|
|
this.db = new sqlite3.Database(':memory:');
|
|
}
|
|
|
|
runAsync(sql, params = []) {
|
|
return new Promise((resolve, reject) => {
|
|
this.db.run(sql, params, function (err) {
|
|
if (err) {
|
|
reject(err);
|
|
} else {
|
|
resolve({ changes: this.changes });
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
execAsync(sql) {
|
|
return new Promise((resolve, reject) => {
|
|
this.db.exec(sql, err => {
|
|
if (err) {
|
|
reject(err);
|
|
} else {
|
|
resolve();
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
closeAsync() {
|
|
return new Promise(resolve => {
|
|
this.db.close(() => resolve());
|
|
});
|
|
}
|
|
}
|
|
|
|
const SQLite = {
|
|
openDatabaseAsync: jest.fn(name => new SQLiteDatabase(name)),
|
|
};
|
|
|
|
module.exports = SQLite; |