1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-14 18:27:44 +02:00
joplin/ReactNativeClient/lib/models/ResourceLocalState.js
Laurent Cozic 9289dbdf77
All: Refactor Markdown rendering (#1315)
* Refactoring MdToHtml to avoid manually rendering tokens

* Minor fix

* Fixed loading of resources

* Handle clicking on checkboxes

* Added back Katex support

* Fixed issues with Katex and note rendering

* Added back support for links

* Restored code block highlighting support

* clean up

* Applying update to mobile

* Fixed handling of links and cleaned up to share more code between mobile and desktop

* Restored content caching and improved handling of additional assets

* Clean up and a few fixes

* Applied more updates to mobile and added code highlighting support
2019-03-08 17:14:17 +00:00

47 lines
1.2 KiB
JavaScript

const BaseModel = require('lib/BaseModel.js');
const Resource = require('lib/models/Resource.js');
const { Database } = require('lib/database.js');
class ResourceLocalState extends BaseModel {
static tableName() {
return 'resource_local_states';
}
static modelType() {
return BaseModel.TYPE_RESOURCE_LOCAL_STATE;
}
static async byResourceId(resourceId) {
if (!resourceId) throw new Error('Resource ID not provided'); // Sanity check
const result = await this.modelSelectOne('SELECT * FROM resource_local_states WHERE resource_id = ?', [resourceId]);
if (!result) {
const defaultRow = this.db().createDefaultRow(this.tableName());
delete defaultRow.id;
defaultRow.resource_id = resourceId;
return defaultRow;
}
return result;
}
static async save(o) {
const queries = [
{ sql: 'DELETE FROM resource_local_states WHERE resource_id = ?', params: [o.resource_id] },
Database.insertQuery(this.tableName(), o),
];
return this.db().transactionExecBatch(queries);
}
static batchDelete(ids, options = null) {
options = options ? Object.assign({}, options) : {};
options.idFieldName = 'resource_id';
return super.batchDelete(ids, options);
}
}
module.exports = ResourceLocalState;