65
submitted 1 month ago* (last edited 1 month ago) by matcha_addict@lemy.lol to c/linux@lemmy.ml

Hi all,

I am looking for a local database that is easily accessible via the command line.

It can be SQL or non-SQL

Whats my use case? I want to use it kinda like a second brain. A place to save ~~my notes~~, my todo lists, my book reading lists, links / articles to read later, etc.

I want it to be a good CLI citizen so that I can script its commands to create simpler abstractions, rather than writing out the full queries every time.

Maybe sqlite is what I need, but is that ideal for my use case?

Edit: removed notes, as evidently they aren't suitable for this and aren't like the rest.

top 50 comments
sorted by: hot top controversial new old
[-] AnnaFrankfurter@lemmy.ml 37 points 1 month ago

I wouldn't recommend a DB for note taking purpose. You can use Markdown with vim.

[-] fmstrat@lemmy.nowsci.com 2 points 1 month ago

Agreed. You can still do tags with filenames like ===Category===Tag 1---Tag 2===Note name.md or some such format.

[-] matcha_addict@lemy.lol 1 points 1 month ago

Perhaps I shouldn't have said note taking. But the rest still applies.

[-] Emperor@feddit.uk 27 points 1 month ago

Counter-proposal: Perhaps use Obsidian instead?

[-] Brewchin@lemmy.world 5 points 1 month ago

I second this, as it's my use case.

Providing you lay out each note correctly with appropriate frontmatter, Dataview's DQL and DataviewJS give you all the SQL-like functionality you could want.

Plus a load of useful functionality beyond a plain DB.

[-] asap@lemmy.world 6 points 1 month ago* (last edited 1 month ago)

Add in the local REST API as well if you want to easily interact with your notes programmatically:

https://github.com/coddingtonbear/obsidian-local-rest-api

[-] Brewchin@lemmy.world 5 points 1 month ago

Had no idea about this. Very useful, thanks!

[-] matcha_addict@lemy.lol 1 points 1 month ago

I want something I can use from the command line, so that I can integrate and interface it with other unix tools and scripts.

[-] Emperor@feddit.uk 3 points 1 month ago
[-] matcha_addict@lemy.lol 1 points 1 month ago

Oh wow that's pretty cool. From my understanding this is good for notes, but would it work for tasks / todos?

[-] Emperor@feddit.uk 1 points 1 month ago

It has a huge number of plugins - this is a list of the productivity ones. You'd need to do some reading to see if it has what you require.

[-] cy_narrator@discuss.tchncs.de 15 points 1 month ago

Using a database for notes is like going 2km in a plane.

You can use any relational database for this though but why would you subject yourself to this?

[-] matcha_addict@lemy.lol 2 points 1 month ago

I think you're right about notes, but what about the other use cases?

[-] cy_narrator@discuss.tchncs.de 1 points 6 days ago

If you are generally interested in designing databases its a good exercise to try and build one yourself. That is the only situation I recommend you go this route

[-] Emperor@feddit.uk 1 points 1 month ago

Obsidian has a huge number of plug-ins, that cover a wide range of uses. I also use Zettel Notes as a quick md file editor and that has the ability to capture pages in markdown to read later. And/or you can use Omnivore.

[-] OneCardboardBox@lemmy.sdf.org 14 points 1 month ago* (last edited 1 month ago)

Are you an emacs user?

Try org-roam. It's a similar system to obsidian, but fully open source. You have all the note taking techniques of org-mode, and all the scripting power of emacs.

[-] sem@lemmy.ml 3 points 1 month ago

There is also a "web-version" of org-roam named "orgnote": https://github.com/Artawower/orgnote

[-] pe1uca@lemmy.pe1uca.dev 10 points 1 month ago

I can't imagine this flow working with any DB without an UI to manage it.
How are you going to store all that in an easy yet flexible way to handle all with SQL?

A table for notes?
What fields would it have? Probably just a text field.
Creating it is simple: insert "initial note"... How are you going to update it? A simple update to the ID won't work since you'll be replacing all the content, you'd need to query the note, copy it to a text editor and then copy it back to a query (don't forget to escape it).
Then probably you want to know which is your oldest note, so you need to include created_at and updated_at fields.
Maybe a title per note is a nice addition, so a new field to add title.

What about the todo lists? Will they be stored in the same notes table?
If so, then the same problem, how are you going to update them? Include new items, mark items as done, remove them, reorder them.
Maybe a dedicated table, well, two tables, list metadata and list items.
In metadata almost the same fields as notes, but description instead of text. The list items will have status and text.

Maybe you can reuse the todo tables for your book list and links/articles to read.

so that I can script its commands to create simpler abstractions, rather than writing out the full queries every time.

This already exists, several note taking apps which wrap around either the filesystem or a DB so you only have to worry about writing your ideas into them.
I'd suggest to not reinvent the wheel unless nothing satisfies you.

What are the pros of using a DB directly for your use case?
What are the cons of using a note taking app which will provide a text editor?

If you really really want to use a DB maybe look into https://github.com/zadam/trilium
It uses sqlite to store the notes, so maybe you can check the code and get an idea if it's complicated or not for you to manually replicate all of that.
If not, I'd also recommend obsidian, it stores the notes in md files, so you can open them with any software you want and they'll have a standard syntax.

[-] matcha_addict@lemy.lol 1 points 1 month ago

First, I want to apologize for mentioning notes. Notes should be separate from the rest, and I agree with you on what you said about notes.

For the rest, I've asked before on suggestions for apps to save my todos, links, etc. There were a couple issues

  • I couldn't find something that gives me the same interface for all of these. They are all lists of things with some attributes and relations, but most apps out there handled each one of these separately and differently

  • they lacked features I wanted. For example, dependent tasks, a flexible tag system I can query by, etc.

A DB would let me do all of that.

load more comments (1 replies)
[-] tmk@social.lugal.io 10 points 1 month ago

@matcha_addict Anything beyond SQLite is too heavy, but if it were me I would use a lightweight wiki like dokuwiki. Having to run SQL to do all these sorts of things sounds like it would just get in the way of both getting and consuming your thoughts.

load more comments (9 replies)
[-] Daeraxa@lemmy.ml 9 points 1 month ago

Joplin is a note taking app that stores its data in an sqlite database (easy to query but not a good idea to write to it) but there is also a command line version and both versions support access via a data API.

[-] terminal@lemmy.ml 8 points 1 month ago

I think you would be better off using something like org-roam. It’s all text so script can still be used and it can be searched fast with ripgrep. Also org mode has loads of features that a homegrown system will never be able to catch up with

[-] delirious_owl@discuss.online 7 points 1 month ago

Is their any DB that doesn't have a CLI?

[-] matcha_addict@lemy.lol 1 points 1 month ago

I think what I'm looking for doesn't exist, but what I meant by CLI is something I can pipe things into and interface with other unix tools easily.

But you're right, they all have a way to open a session via CLI.

[-] csm10495@sh.itjust.works 6 points 1 month ago

Unless your lists are 1000s of items long, just use text files in a folder.

Could even go fancy and use markdown.

load more comments (1 replies)
[-] 0x0@programming.dev 5 points 1 month ago

SQLite seems ideal but if notetaking is your usecase there are apps for that.

[-] Nibodhika@lemmy.world 5 points 1 month ago

What if instead you used something that's meant to be used to take notes but that also has querying capabilities?

I have been using Silverbullet for a while and I absolutely love it. It uses Markdown files in disk so it's very easy to backup, have secondary instances running and even just edit files directly with any other program. But also provides some extra syntax to define objects and query them, so you can for example build a library of recipes and have a page that lists all of the ones that have a specific tag or take less than X time to cook or whatever.

[-] elltee@lemmy.one 5 points 1 month ago

Joplin can do all that and has: Plugin support for nearly anything you want Runs on sqlite if you want to access the data direct Is 100% open source.

[-] lazylion_ca@lemmy.ca 1 points 1 month ago

Also has (or had) a cli interface.

load more comments (1 replies)
[-] mvirts@lemmy.world 5 points 1 month ago
[-] bionicjoey@lemmy.ca 4 points 1 month ago

Definitely sounds like sqlite.

[-] audaxdreik@pawb.social 4 points 1 month ago

Check out https://www.giuspen.net/cherrytree/, lightweight note-taking app with interesting scripting function built in.

Even if that's not your cup of tea, it has the option to save your notebook to a single sqlite file, so I take that as good enough proof it'll work for your similar purposes as well.

[-] h0bbl3s@lemmy.world 3 points 1 month ago* (last edited 1 month ago)

They aren't exactly CLI but I really like obsidian for taking notes. It's not open source though. Logseq is good too and is OSS. Both use markdown for formatting so if you are familiar with writing pages on GitHub you'll have no trouble. Even if not markdown is super easy to learn. That and all of your data stays local and in open formats. I edit my stuff in a terminal anyway.

Just look up obsidian OSINT on YouTube you'll find some good stuff on how to use it.

Another thought is just use markdown files and a directory structure in a private git repo. You'd be able to interact with it locally entirely in the terminal with vim etc and have the option of going online and searching or organizing etc. You could probably even use a cli browser for that part if you wanted.

[-] gramgan@lemmy.ml 3 points 1 month ago

Hey!

I’ve wanted something very similar—specifically, a plain-text database. I recently came across GNU recutils, which I haven’t had time to play around with yet, but which seems like it fits the bill (at least for me). There’s a couple YouTube videos on it—I encourage you to check it out!

[-] olafurp@lemmy.world 2 points 1 month ago* (last edited 1 month ago)

You can always log into a database and use raw SQL. For automation of your tasks you can put in some functions and stored procedures and later on you can always do something more graphical or even more SQL. You can do something like "exec create_note('Name of note')" and "exec notes()" and whatnot.

Then if you want to do something more elaborate than viewing tables and do some formatting programming languages are pretty nice do make stringified versions of the notes and a nice way to browse them.

Then to finish up using some nice bash packages to create a CLI interface is very fun. I like charmbracelet's stuff because it just looks nice and is easy to use. Here's a thing you can use to create something to select a note to view: https://github.com/charmbracelet/gum

[-] steeznson@lemmy.world 2 points 1 month ago

sqlite is exactly what you want. You can even load a CSV file directly into a new table. Everything is a string, it's extremely fast and ubiquitous on moderns OS's.

[-] floofloof@lemmy.ca 2 points 1 month ago

If you want something a bit more powerful than SQLite, MySQL and PostgreSQL both support CLI interactions and scripting too.

[-] 0x0@programming.dev 2 points 1 month ago

For note-taking and to-do lists both seem a bit overkill, and I'd recommend MariaDB instead of MySQL.

[-] floofloof@lemmy.ca 2 points 1 month ago

I agree they're overkill. I'd use something like Joplin for note taking and to-do lists, which stores its data in SQLite anyway.

[-] yogthos@lemmy.ml 1 points 1 month ago* (last edited 1 month ago)

take a look at Apache Ignite https://ignite.apache.org/docs/latest/tools/sqlline

there's also datafusion that lets you run SQL commands via CIL on CSV and JSON https://datafusion.apache.org/user-guide/cli/usage.html

[-] vipaal@aussie.zone 1 points 1 month ago

Tangential answer. Consider looking into Prolog, Picat, Mercury languages. You can effectively let the database design be taken care of by the language. In return you get more time to reflect on your knowledge base and ask it all sorts of questions and get a range of possible answers.

Org-roam and its web cousin webnotes both have solved designing the database for note taking purpose using g sqlite as a back end. Good options.

[-] muad_dibber@lemmygrad.ml 1 points 1 month ago

Notes, Todo lists and links? A DB is not what you need.

These are all different concerns each with specialized software for them.

For todos and lists, I like tasks.org

For Notes and links, use a folder of markdown files, and an editor like Obsidian or Markor.

load more comments
view more: next ›
this post was submitted on 23 Jul 2024
65 points (97.1% liked)

Linux

47344 readers
1334 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS