generated from dave/wails-template
193 lines
8.4 KiB
Markdown
193 lines
8.4 KiB
Markdown
Good evening, Claude
|
|
Is it proper to say "Good evening Claude" or "Good evening, Claude"?
|
|
|
|
Anyway, I'm wanting to create a little journal application in Golang using Wails
|
|
I want it to record journal entries which will be pure text
|
|
But I also want to add images and possibly files (files would be cool)
|
|
Now I want files to be embedded into the text...
|
|
Which means that A) I would have to save them in the same row in the database
|
|
And B) somehow embed them into text
|
|
|
|
Now I'm seeking your guidance
|
|
How do you think I should embed files into text?
|
|
For images I think I can just easily b64 them
|
|
How would I do it for other forms of files?
|
|
pdf files maybe?
|
|
|
|
Is this a good idea?
|
|
Should I use a different method?
|
|
I'd really like the files to be embedded into text
|
|
So I can say hey look at this stinky ^
|
|
But then I'd probably have to limit their size and have a modal and stuff... Hmm...
|
|
Maybe b64 a thumbnail and save the whole image in a separate table... But that would be complicated...
|
|
|
|
What do you think?
|
|
|
|
|
|
Good evening, Claude. (The comma is correct in this greeting.)
|
|
|
|
Your idea for a journal application in Golang using Wails sounds interesting. Let's break down your requirements and discuss some approaches:
|
|
|
|
1. Embedding files into text:
|
|
- For images: Your idea of using base64 encoding is a good start.
|
|
- For other file types (like PDFs): You could use a similar approach with base64 encoding.
|
|
|
|
2. Database storage:
|
|
- Storing everything in one row might work for small files, but it could become problematic for larger files or numerous entries.
|
|
|
|
3. Embedding in text:
|
|
- You could use a custom markup syntax to indicate where files should be embedded, e.g., `[file:unique_identifier]`.
|
|
|
|
Here's a potential approach:
|
|
|
|
1. File handling:
|
|
- For images: Create thumbnails, base64 encode them for inline display.
|
|
- For other files: Generate an icon or small preview if possible.
|
|
|
|
2. Database structure:
|
|
- Main table: journal_entries (id, date, content)
|
|
- Secondary table: attachments (id, journal_entry_id, file_type, file_path, thumbnail)
|
|
|
|
3. Content storage:
|
|
- In the journal_entries table, store the text with placeholders: "Look at this stinky [file:1]"
|
|
- In the attachments table, store file metadata and paths to the actual files on disk.
|
|
|
|
4. UI rendering:
|
|
- When displaying entries, replace placeholders with thumbnails/icons.
|
|
- Implement a modal or popup to show full-size images or file previews when clicked.
|
|
|
|
This approach offers several advantages:
|
|
1. Keeps the database size manageable
|
|
2. Allows for efficient querying and indexing of text content
|
|
3. Provides flexibility for handling various file types
|
|
4. Enables easier backup and file management
|
|
|
|
Considerations:
|
|
- Implement file size limits to prevent performance issues.
|
|
- Use a consistent file storage system (e.g., organized by date or entry ID).
|
|
- Implement proper error handling for file operations.
|
|
|
|
This method is more complex than storing everything in one table, but it offers better scalability and performance. It also allows you to implement features like file type filtering or attachment management more easily in the future.
|
|
|
|
Would you like me to elaborate on any part of this approach or discuss alternatives?
|
|
|
|
|
|
You're right that SQLite does natively support storing files. It offers a datatype called BLOB (Binary Large Object) which can be used to store binary data directly in the database. This feature could potentially simplify your design. Let's explore this option:
|
|
|
|
|
|
|
|
```sql
|
|
CREATE TABLE journal_entries (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
date TEXT NOT NULL,
|
|
content TEXT NOT NULL
|
|
);
|
|
|
|
CREATE TABLE attachments (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
journal_entry_id INTEGER,
|
|
file_name TEXT NOT NULL,
|
|
file_type TEXT NOT NULL,
|
|
file_data BLOB,
|
|
FOREIGN KEY (journal_entry_id) REFERENCES journal_entries (id)
|
|
);
|
|
|
|
```
|
|
|
|
Using SQLite's BLOB support, you could implement your journal application like this:
|
|
|
|
1. Main journal entries table to store text content
|
|
2. Attachments table to store file metadata and the actual file data as BLOB
|
|
|
|
This approach offers several benefits:
|
|
1. Simplified storage: All data is in the database, no need for separate file system management.
|
|
2. Easier backups: The entire journal (including attachments) is in one SQLite file.
|
|
3. Portability: The journal can be easily moved or copied as a single file.
|
|
|
|
However, there are also some considerations:
|
|
1. Database size: Storing large files in the database will increase its size significantly.
|
|
2. Performance: Reading/writing large BLOBs can be slower than file system operations.
|
|
3. Memory usage: Loading large BLOBs into memory could be resource-intensive.
|
|
|
|
For your use case of a personal journal application, these drawbacks might not be significant unless you're dealing with very large files or a huge number of entries.
|
|
|
|
To embed files in text, you could still use a placeholder system:
|
|
1. When saving an entry with an attachment, insert a placeholder like `[file:ID]` in the text.
|
|
2. When retrieving entries, replace these placeholders with appropriate HTML for displaying thumbnails or icons.
|
|
|
|
This design is simpler than the previous suggestion while still maintaining good organization and flexibility. It's a good balance between simplicity and functionality for a personal journal application.
|
|
|
|
Would you like me to elaborate on how to implement this in Go with Wails, or do you have any questions about this approach?
|
|
|
|
You're right to reconsider the storage approach. Storing files in a folder instead of the database can indeed be a better solution in many cases. Let's explore this idea:
|
|
|
|
Advantages of storing files in a folder:
|
|
|
|
1. Reduced database size and complexity
|
|
2. Easier file management (backup, migration, direct access)
|
|
3. Potentially better performance, especially for larger files
|
|
4. Ability to easily use external tools to manipulate files if needed
|
|
|
|
Here's a high-level approach for this method:
|
|
|
|
1. Store journal entries in the SQLite database
|
|
2. Save images (and potentially other files) in a dedicated folder structure
|
|
3. Use references to these files in your database
|
|
|
|
|
|
|
|
```sql
|
|
-- Database schema
|
|
CREATE TABLE journal_entries (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
date TEXT NOT NULL,
|
|
content TEXT NOT NULL
|
|
);
|
|
|
|
CREATE TABLE attachments (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
journal_entry_id INTEGER,
|
|
file_name TEXT NOT NULL,
|
|
file_path TEXT NOT NULL,
|
|
mime_type TEXT NOT NULL,
|
|
FOREIGN KEY (journal_entry_id) REFERENCES journal_entries (id)
|
|
);
|
|
|
|
-- Folder structure
|
|
journal_app/
|
|
├── database.sqlite
|
|
└── attachments/
|
|
├── 2024/
|
|
│ ├── 08/
|
|
│ │ ├── 28/
|
|
│ │ │ ├── 1_image.jpg
|
|
│ │ │ └── 2_document.pdf
|
|
│ │ └── 29/
|
|
│ │ └── 3_image.png
|
|
│ └── 09/
|
|
└── 2025/
|
|
|
|
```
|
|
|
|
This structure offers several benefits:
|
|
|
|
1. Clear organization: Files are stored in a date-based folder structure for easy navigation.
|
|
2. Scalability: Can handle a large number of files without impacting database performance.
|
|
3. Flexibility: Easy to implement additional features like file type filtering or thumbnail generation.
|
|
|
|
Implementation considerations:
|
|
|
|
1. When saving an attachment, generate a unique filename (e.g., using a timestamp or UUID) and store it in the appropriate date-based folder.
|
|
2. In the database, store the relative path to the file (e.g., "2024/08/28/1_image.jpg").
|
|
3. When rendering journal entries, you can still use placeholders in the text content (e.g., `[file:1]`) and replace them with appropriate HTML when displaying.
|
|
4. Implement a simple file serving mechanism in your Wails backend to display images and other files.
|
|
|
|
This approach maintains the simplicity you're looking for while providing better scalability and easier file management. It's not significantly more complicated than storing files in the database, but it offers more flexibility for future enhancements.
|
|
|
|
Does this file-based approach align better with what you had in mind? Would you like to discuss any specific aspects of this design?
|
|
|
|
But I'm thinking maybe, if we store on disk, we forget all about the database file table bullshit
|
|
And just put filename into content
|
|
So embed files into content (ie. [somebullshit.png])
|
|
And then have go look up something like
|
|
resources/<ISO datetime>/somebullshit.png |