mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 13:01:31 +08:00 
			
		
		
		
	attributes can be inherited through special relation "inheritAttributes"
This commit is contained in:
		
							parent
							
								
									b0ed790edf
								
							
						
					
					
						commit
						ddbd4f73c8
					
				| @ -1,6 +1,6 @@ | |||||||
| <?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||||||
| <dataSource name="document.db"> | <dataSource name="document.db"> | ||||||
|   <database-model serializer="dbm" rdbms="SQLITE" format-version="4.9"> |   <database-model serializer="dbm" rdbms="SQLITE" format-version="4.11"> | ||||||
|     <root id="1"> |     <root id="1"> | ||||||
|       <ServerVersion>3.16.1</ServerVersion> |       <ServerVersion>3.16.1</ServerVersion> | ||||||
|     </root> |     </root> | ||||||
| @ -59,7 +59,6 @@ | |||||||
|     <index id="25" parent="6" name="sqlite_autoindex_api_tokens_1"> |     <index id="25" parent="6" name="sqlite_autoindex_api_tokens_1"> | ||||||
|       <NameSurrogate>1</NameSurrogate> |       <NameSurrogate>1</NameSurrogate> | ||||||
|       <ColNames>apiTokenId</ColNames> |       <ColNames>apiTokenId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|       <Unique>1</Unique> |       <Unique>1</Unique> | ||||||
|     </index> |     </index> | ||||||
|     <key id="26" parent="6"> |     <key id="26" parent="6"> | ||||||
| @ -128,7 +127,6 @@ | |||||||
|     <index id="38" parent="7" name="sqlite_autoindex_attributes_1"> |     <index id="38" parent="7" name="sqlite_autoindex_attributes_1"> | ||||||
|       <NameSurrogate>1</NameSurrogate> |       <NameSurrogate>1</NameSurrogate> | ||||||
|       <ColNames>attributeId</ColNames> |       <ColNames>attributeId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|       <Unique>1</Unique> |       <Unique>1</Unique> | ||||||
|     </index> |     </index> | ||||||
|     <key id="39" parent="7"> |     <key id="39" parent="7"> | ||||||
| @ -190,21 +188,17 @@ | |||||||
|     <index id="50" parent="8" name="sqlite_autoindex_branches_1"> |     <index id="50" parent="8" name="sqlite_autoindex_branches_1"> | ||||||
|       <NameSurrogate>1</NameSurrogate> |       <NameSurrogate>1</NameSurrogate> | ||||||
|       <ColNames>branchId</ColNames> |       <ColNames>branchId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|       <Unique>1</Unique> |       <Unique>1</Unique> | ||||||
|     </index> |     </index> | ||||||
|     <index id="51" parent="8" name="IDX_branches_noteId_parentNoteId"> |     <index id="51" parent="8" name="IDX_branches_noteId_parentNoteId"> | ||||||
|       <ColNames>noteId |       <ColNames>noteId | ||||||
| parentNoteId</ColNames> | parentNoteId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|     </index> |     </index> | ||||||
|     <index id="52" parent="8" name="IDX_branches_noteId"> |     <index id="52" parent="8" name="IDX_branches_noteId"> | ||||||
|       <ColNames>noteId</ColNames> |       <ColNames>noteId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|     </index> |     </index> | ||||||
|     <index id="53" parent="8" name="IDX_branches_parentNoteId"> |     <index id="53" parent="8" name="IDX_branches_parentNoteId"> | ||||||
|       <ColNames>parentNoteId</ColNames> |       <ColNames>parentNoteId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|     </index> |     </index> | ||||||
|     <key id="54" parent="8"> |     <key id="54" parent="8"> | ||||||
|       <ColNames>branchId</ColNames> |       <ColNames>branchId</ColNames> | ||||||
| @ -232,7 +226,6 @@ parentNoteId</ColNames> | |||||||
|     <index id="59" parent="9" name="sqlite_autoindex_event_log_1"> |     <index id="59" parent="9" name="sqlite_autoindex_event_log_1"> | ||||||
|       <NameSurrogate>1</NameSurrogate> |       <NameSurrogate>1</NameSurrogate> | ||||||
|       <ColNames>eventId</ColNames> |       <ColNames>eventId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|       <Unique>1</Unique> |       <Unique>1</Unique> | ||||||
|     </index> |     </index> | ||||||
|     <key id="60" parent="9"> |     <key id="60" parent="9"> | ||||||
| @ -289,7 +282,6 @@ parentNoteId</ColNames> | |||||||
|     <index id="70" parent="10" name="sqlite_autoindex_images_1"> |     <index id="70" parent="10" name="sqlite_autoindex_images_1"> | ||||||
|       <NameSurrogate>1</NameSurrogate> |       <NameSurrogate>1</NameSurrogate> | ||||||
|       <ColNames>imageId</ColNames> |       <ColNames>imageId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|       <Unique>1</Unique> |       <Unique>1</Unique> | ||||||
|     </index> |     </index> | ||||||
|     <key id="71" parent="10"> |     <key id="71" parent="10"> | ||||||
| @ -337,21 +329,17 @@ parentNoteId</ColNames> | |||||||
|     <index id="79" parent="11" name="sqlite_autoindex_note_images_1"> |     <index id="79" parent="11" name="sqlite_autoindex_note_images_1"> | ||||||
|       <NameSurrogate>1</NameSurrogate> |       <NameSurrogate>1</NameSurrogate> | ||||||
|       <ColNames>noteImageId</ColNames> |       <ColNames>noteImageId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|       <Unique>1</Unique> |       <Unique>1</Unique> | ||||||
|     </index> |     </index> | ||||||
|     <index id="80" parent="11" name="IDX_note_images_noteId_imageId"> |     <index id="80" parent="11" name="IDX_note_images_noteId_imageId"> | ||||||
|       <ColNames>noteId |       <ColNames>noteId | ||||||
| imageId</ColNames> | imageId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|     </index> |     </index> | ||||||
|     <index id="81" parent="11" name="IDX_note_images_noteId"> |     <index id="81" parent="11" name="IDX_note_images_noteId"> | ||||||
|       <ColNames>noteId</ColNames> |       <ColNames>noteId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|     </index> |     </index> | ||||||
|     <index id="82" parent="11" name="IDX_note_images_imageId"> |     <index id="82" parent="11" name="IDX_note_images_imageId"> | ||||||
|       <ColNames>imageId</ColNames> |       <ColNames>imageId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|     </index> |     </index> | ||||||
|     <key id="83" parent="11"> |     <key id="83" parent="11"> | ||||||
|       <ColNames>noteImageId</ColNames> |       <ColNames>noteImageId</ColNames> | ||||||
| @ -413,20 +401,16 @@ imageId</ColNames> | |||||||
|     <index id="94" parent="12" name="sqlite_autoindex_note_revisions_1"> |     <index id="94" parent="12" name="sqlite_autoindex_note_revisions_1"> | ||||||
|       <NameSurrogate>1</NameSurrogate> |       <NameSurrogate>1</NameSurrogate> | ||||||
|       <ColNames>noteRevisionId</ColNames> |       <ColNames>noteRevisionId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|       <Unique>1</Unique> |       <Unique>1</Unique> | ||||||
|     </index> |     </index> | ||||||
|     <index id="95" parent="12" name="IDX_note_revisions_noteId"> |     <index id="95" parent="12" name="IDX_note_revisions_noteId"> | ||||||
|       <ColNames>noteId</ColNames> |       <ColNames>noteId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|     </index> |     </index> | ||||||
|     <index id="96" parent="12" name="IDX_note_revisions_dateModifiedFrom"> |     <index id="96" parent="12" name="IDX_note_revisions_dateModifiedFrom"> | ||||||
|       <ColNames>dateModifiedFrom</ColNames> |       <ColNames>dateModifiedFrom</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|     </index> |     </index> | ||||||
|     <index id="97" parent="12" name="IDX_note_revisions_dateModifiedTo"> |     <index id="97" parent="12" name="IDX_note_revisions_dateModifiedTo"> | ||||||
|       <ColNames>dateModifiedTo</ColNames> |       <ColNames>dateModifiedTo</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|     </index> |     </index> | ||||||
|     <key id="98" parent="12"> |     <key id="98" parent="12"> | ||||||
|       <ColNames>noteRevisionId</ColNames> |       <ColNames>noteRevisionId</ColNames> | ||||||
| @ -493,12 +477,10 @@ imageId</ColNames> | |||||||
|     <index id="109" parent="13" name="sqlite_autoindex_notes_1"> |     <index id="109" parent="13" name="sqlite_autoindex_notes_1"> | ||||||
|       <NameSurrogate>1</NameSurrogate> |       <NameSurrogate>1</NameSurrogate> | ||||||
|       <ColNames>noteId</ColNames> |       <ColNames>noteId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|       <Unique>1</Unique> |       <Unique>1</Unique> | ||||||
|     </index> |     </index> | ||||||
|     <index id="110" parent="13" name="IDX_notes_type"> |     <index id="110" parent="13" name="IDX_notes_type"> | ||||||
|       <ColNames>type</ColNames> |       <ColNames>type</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|     </index> |     </index> | ||||||
|     <key id="111" parent="13"> |     <key id="111" parent="13"> | ||||||
|       <ColNames>noteId</ColNames> |       <ColNames>noteId</ColNames> | ||||||
| @ -539,7 +521,6 @@ imageId</ColNames> | |||||||
|     <index id="118" parent="14" name="sqlite_autoindex_options_1"> |     <index id="118" parent="14" name="sqlite_autoindex_options_1"> | ||||||
|       <NameSurrogate>1</NameSurrogate> |       <NameSurrogate>1</NameSurrogate> | ||||||
|       <ColNames>name</ColNames> |       <ColNames>name</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|       <Unique>1</Unique> |       <Unique>1</Unique> | ||||||
|     </index> |     </index> | ||||||
|     <key id="119" parent="14"> |     <key id="119" parent="14"> | ||||||
| @ -575,7 +556,6 @@ imageId</ColNames> | |||||||
|     <index id="125" parent="15" name="sqlite_autoindex_recent_notes_1"> |     <index id="125" parent="15" name="sqlite_autoindex_recent_notes_1"> | ||||||
|       <NameSurrogate>1</NameSurrogate> |       <NameSurrogate>1</NameSurrogate> | ||||||
|       <ColNames>branchId</ColNames> |       <ColNames>branchId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|       <Unique>1</Unique> |       <Unique>1</Unique> | ||||||
|     </index> |     </index> | ||||||
|     <key id="126" parent="15"> |     <key id="126" parent="15"> | ||||||
| @ -596,7 +576,6 @@ imageId</ColNames> | |||||||
|     <index id="129" parent="16" name="sqlite_autoindex_source_ids_1"> |     <index id="129" parent="16" name="sqlite_autoindex_source_ids_1"> | ||||||
|       <NameSurrogate>1</NameSurrogate> |       <NameSurrogate>1</NameSurrogate> | ||||||
|       <ColNames>sourceId</ColNames> |       <ColNames>sourceId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|       <Unique>1</Unique> |       <Unique>1</Unique> | ||||||
|     </index> |     </index> | ||||||
|     <key id="130" parent="16"> |     <key id="130" parent="16"> | ||||||
| @ -659,12 +638,10 @@ imageId</ColNames> | |||||||
|     <index id="143" parent="19" name="IDX_sync_entityName_entityId"> |     <index id="143" parent="19" name="IDX_sync_entityName_entityId"> | ||||||
|       <ColNames>entityName |       <ColNames>entityName | ||||||
| entityId</ColNames> | entityId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|       <Unique>1</Unique> |       <Unique>1</Unique> | ||||||
|     </index> |     </index> | ||||||
|     <index id="144" parent="19" name="IDX_sync_syncDate"> |     <index id="144" parent="19" name="IDX_sync_syncDate"> | ||||||
|       <ColNames>syncDate</ColNames> |       <ColNames>syncDate</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|     </index> |     </index> | ||||||
|     <key id="145" parent="19"> |     <key id="145" parent="19"> | ||||||
|       <ColNames>id</ColNames> |       <ColNames>id</ColNames> | ||||||
|  | |||||||
							
								
								
									
										6
									
								
								.idea/sqldialects.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								.idea/sqldialects.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @ -0,0 +1,6 @@ | |||||||
|  | <?xml version="1.0" encoding="UTF-8"?> | ||||||
|  | <project version="4"> | ||||||
|  |   <component name="SqlDialectMappings"> | ||||||
|  |     <file url="PROJECT" dialect="SQLite" /> | ||||||
|  |   </component> | ||||||
|  | </project> | ||||||
| @ -72,15 +72,26 @@ class Note extends Entity { | |||||||
| 
 | 
 | ||||||
|     async getAttributes() { |     async getAttributes() { | ||||||
|         const attributes = await repository.getEntities(` |         const attributes = await repository.getEntities(` | ||||||
|         WITH RECURSIVE tree(noteId, level) AS ( |             WITH RECURSIVE | ||||||
|  |             tree(noteId, level) AS ( | ||||||
|                 SELECT ?, 0 |                 SELECT ?, 0 | ||||||
|                 UNION |                 UNION | ||||||
|                 SELECT branches.parentNoteId, tree.level + 1 FROM branches |                 SELECT branches.parentNoteId, tree.level + 1 FROM branches | ||||||
|                     JOIN tree ON branches.noteId = tree.noteId |                     JOIN tree ON branches.noteId = tree.noteId | ||||||
|                     JOIN notes ON notes.noteId = branches.parentNoteId |                     JOIN notes ON notes.noteId = branches.parentNoteId | ||||||
|             WHERE notes.isDeleted = 0 AND branches.isDeleted = 0 |                 WHERE notes.isDeleted = 0 | ||||||
|  |                   AND branches.isDeleted = 0 | ||||||
|  |             ), | ||||||
|  |             treeWithAttrs(noteId, level) AS ( | ||||||
|  |                 SELECT * FROM tree | ||||||
|  |                 UNION | ||||||
|  |                 SELECT attributes.value, treeWithAttrs.level + 1 FROM attributes | ||||||
|  |                      JOIN treeWithAttrs ON treeWithAttrs.noteId = attributes.noteId | ||||||
|  |                 WHERE attributes.isDeleted = 0 | ||||||
|  |                   AND attributes.type = 'relation' | ||||||
|  |                   AND attributes.name = 'inheritAttributes' | ||||||
|                 ) |                 ) | ||||||
|         SELECT attributes.* FROM attributes JOIN tree ON attributes.noteId = tree.noteId  |             SELECT attributes.* FROM attributes JOIN treeWithAttrs ON attributes.noteId = treeWithAttrs.noteId | ||||||
|             WHERE attributes.isDeleted = 0 AND (attributes.isInheritable = 1 OR attributes.noteId = ?) |             WHERE attributes.isDeleted = 0 AND (attributes.isInheritable = 1 OR attributes.noteId = ?) | ||||||
|             ORDER BY level, noteId, position`, [this.noteId, this.noteId]);
 |             ORDER BY level, noteId, position`, [this.noteId, this.noteId]);
 | ||||||
|         // attributes are ordered so that "closest" attributes are first
 |         // attributes are ordered so that "closest" attributes are first
 | ||||||
|  | |||||||
| @ -20,7 +20,8 @@ const BUILTIN_ATTRIBUTES = [ | |||||||
|     // relation names
 |     // relation names
 | ||||||
|     { type: 'relation', name: 'runOnNoteView' }, |     { type: 'relation', name: 'runOnNoteView' }, | ||||||
|     { type: 'relation', name: 'runOnNoteTitleChange' }, |     { type: 'relation', name: 'runOnNoteTitleChange' }, | ||||||
|     { type: 'relation', name: 'runOnAttributeChange' } |     { type: 'relation', name: 'runOnAttributeChange' }, | ||||||
|  |     { type: 'relation', name: 'inheritAttributes' } | ||||||
| ]; | ]; | ||||||
| 
 | 
 | ||||||
| async function getNotesWithLabel(name, value) { | async function getNotesWithLabel(name, value) { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 azivner
						azivner