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.

  • Anna@lemmy.ml
    link
    fedilink
    arrow-up
    37
    ·
    4 months ago

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

  • cy_narrator@discuss.tchncs.de
    link
    fedilink
    arrow-up
    15
    ·
    4 months 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?

  • OneCardboardBox@lemmy.sdf.org
    link
    fedilink
    English
    arrow-up
    14
    ·
    edit-2
    4 months 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.

  • pe1uca@lemmy.pe1uca.dev
    link
    fedilink
    arrow-up
    10
    ·
    4 months 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.lolOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      4 months 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.

      • pe1uca@lemmy.pe1uca.dev
        link
        fedilink
        arrow-up
        1
        ·
        4 months ago

        Ah, that makes sense!
        Yes, a DB would let you build this. But the point is in the word “build”, you need to think about what is needed, in which format, how to properly make all the relationships to have data consistency and flexibility, etc.
        For example, you might implement the tags as a text field, then we still have the same issue about addition, removal, and reorder. One fix could be have a many tags to one task table. Then we have the problem of mistyping a tag, you might want to add TODO but you forgot you have it as todo, which might not be a problem if the field is case insensitive, but what about to-do?
        So there are still a lot of stuff you might oversight which will come up to sidetrack you from creating and doing your tasks even if you abstract all of this into a script.

        Specifically for todo list I selfhost https://vikunja.io/
        It has OAS so you can easily generate a library for any language for you to create a CLI.
        Each task has a lot of attributes, including the ones you want: relation between tasks, labels, due date, assignee.

        Maybe you can have a project for your book list, but it might be overkill.

        For links and articles to read I’d say a simple bookmark software could be enough, even the ones in your browser.
        If you want to go a bit beyond that I’m using https://github.com/goniszewski/grimoire
        I like it because it has nested categories plus tags, most other bookmark projects only have simple categories or only tags.
        It also has a basic API but is enough for most use cases.
        Other option could be an RSS reader if you want to get all articles from a site. I’m using https://github.com/FreshRSS/FreshRSS which has the option to retrieve data form sites using XMLPath in case they don’t offer RSS.


        If you still want to go the DB route, then as others have mentioned, since it’ll be local and single user, sqlite is the best option.
        I’d still encourage you to use any existing project, and if it’s open source you can easily contribute the code you’d have done for you to help improve it for the next person with your exact needs.

        (Just paid attention to your username :P
        I also love matcha, not an addict tho haha)

  • tmk@social.lugal.io
    link
    fedilink
    arrow-up
    10
    ·
    4 months 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.

    • matcha_addict@lemy.lolOP
      link
      fedilink
      English
      arrow-up
      1
      arrow-down
      2
      ·
      4 months ago

      I don’t think it would suffice. It would work for notes, but I want to also have a todo list in there, for example. Be able to check things off, query by due date, by assignee or task, etc.

      • subignition@fedia.io
        link
        fedilink
        arrow-up
        13
        ·
        4 months ago

        I don’t think a database is a good fit for your use case at all, unless you’re willing to reinvent a lot of wheels.

        • matcha_addict@lemy.lolOP
          link
          fedilink
          English
          arrow-up
          2
          ·
          4 months ago

          What would then? I haven’t found anything that has command line interface and supports dependent tasks and a flexible, queryable tag system

          • subignition@fedia.io
            link
            fedilink
            arrow-up
            1
            ·
            4 months ago

            I’m sorry, I don’t have a suggestion. If it were me I would not be looking at a CLI solution for this at all.

      • atzanteol@sh.itjust.works
        link
        fedilink
        English
        arrow-up
        5
        arrow-down
        1
        ·
        4 months ago

        For todo stuff there’s the excellent “todo-txt” for cli use. Though not great for notes. Perhaps separate tools would be fine?

        • matcha_addict@lemy.lolOP
          link
          fedilink
          English
          arrow-up
          1
          ·
          4 months ago

          Todo txt lacked some features I needed, which would be trivial to implement as a SQL column.

          I do not remember what it was… Maybe it was dependent tasks? I believe so.

  • Daeraxa@lemmy.ml
    link
    fedilink
    arrow-up
    9
    ·
    4 months 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
    link
    fedilink
    arrow-up
    8
    ·
    4 months 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

    • matcha_addict@lemy.lolOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      4 months 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
    link
    fedilink
    English
    arrow-up
    6
    ·
    4 months ago

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

    Could even go fancy and use markdown.

    • matcha_addict@lemy.lolOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      4 months ago

      I definitely considered this approach. The only problem is it is difficult to represent linking items to each other. For example, dependent tasks or sub tasks.

  • Nibodhika@lemmy.world
    link
    fedilink
    arrow-up
    5
    ·
    4 months 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
    link
    fedilink
    arrow-up
    5
    ·
    4 months 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.

  • 0x0
    link
    fedilink
    arrow-up
    5
    ·
    4 months ago

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