mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 13:39:01 +01:00 
			
		
		
		
	first experiments with note entity
This commit is contained in:
		
							parent
							
								
									52ad7f64b4
								
							
						
					
					
						commit
						9b53a17168
					
				
							
								
								
									
										17
									
								
								src/entities/note.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								src/entities/note.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,17 @@
 | 
			
		||||
"use strict";
 | 
			
		||||
 | 
			
		||||
class Note {
 | 
			
		||||
    constructor(sql, row) {
 | 
			
		||||
        this.sql = sql;
 | 
			
		||||
 | 
			
		||||
        for (const key in row) {
 | 
			
		||||
            this[key] = row[key];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async attributes() {
 | 
			
		||||
        return this.sql.getAll("SELECT * FROM attributes WHERE noteId = ?", [this.noteId]);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports = Note;
 | 
			
		||||
@ -6,6 +6,7 @@ const fs = require('fs');
 | 
			
		||||
const sqlite = require('sqlite');
 | 
			
		||||
const app_info = require('./app_info');
 | 
			
		||||
const resource_dir = require('./resource_dir');
 | 
			
		||||
const Note = require('../entities/note');
 | 
			
		||||
 | 
			
		||||
async function createConnection() {
 | 
			
		||||
    return await sqlite.open(dataDir.DOCUMENT_PATH, {Promise});
 | 
			
		||||
@ -133,6 +134,12 @@ async function getAll(query, params = []) {
 | 
			
		||||
    return await wrap(async db => db.all(query, ...params));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function getAllEntities(query, params = []) {
 | 
			
		||||
    const rows = await getAll(query, params);
 | 
			
		||||
 | 
			
		||||
    return rows.map(row => new Note(module.exports, row));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function getMap(query, params = []) {
 | 
			
		||||
    const map = {};
 | 
			
		||||
    const results = await getAll(query, params);
 | 
			
		||||
@ -266,6 +273,7 @@ module.exports = {
 | 
			
		||||
    getFirst,
 | 
			
		||||
    getFirstOrNull,
 | 
			
		||||
    getAll,
 | 
			
		||||
    getAllEntities,
 | 
			
		||||
    getMap,
 | 
			
		||||
    getFirstColumn,
 | 
			
		||||
    execute,
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user