Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pr for demo alternate store #7521

Closed

Conversation

joshuafontany
Copy link
Contributor

@joshuafontany joshuafontany commented Jun 5, 2023

Not sure if I should have merged main into demo-alternate-store before working, but this is the result.

The actual changes are in: plugins/tiddlywiki/demo-alternate-store/rawmarkup.js

I just pulled the bare minimum functions from boot.js into here to test. serves tw5.com-server and can write tiddlers back to disk, but many of the tests in ./bin/test.sh are failing (not sure why atm).

Mahalo (thanks) for starting this.

Jermolene and others added 8 commits March 4, 2023 21:08
This is the very barebones beginnings of a demo implementation of an alternate tiddler store. It is not functional. If using the Vercel builds, open developer tools in the browser to see it failing due to the absence of basic wiki methods.

The plan is to build it up into the smallest possible plain JS wiki store implementation, sharing as much implementation as possible with the existing core implementation with as little code duplication as possible. It could then serve as the basis for future experiments with wiki stores based on SQLite (@linonetwo), or a custom append only database (@yaisog).
@vercel
Copy link

vercel bot commented Jun 5, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
tiddlywiki5 ✅ Ready (Inspect) Visit Preview Jun 5, 2023 10:08am

@saqimtiaz
Copy link
Member

@joshuafontany you may need to rebase the PR, currently it is shown a lot of unrelated commits which makes it difficult to review.

@joshuafontany joshuafontany changed the base branch from demo-alternate-store to master June 5, 2023 10:27
@joshuafontany
Copy link
Contributor Author

@joshuafontany you may need to rebase the PR, currently it is shown a lot of unrelated commits which makes it difficult to review.

Thanks @saq. That helps, as now the demo code is clearly readable.

@pmario
Copy link
Member

pmario commented Jun 5, 2023

What's the purpose of this PR?

@saqimtiaz
Copy link
Member

@pmario this is an extension of the work in #7329

@pmario
Copy link
Member

pmario commented Jun 5, 2023

I know, but what's the purpose of this implementation. Is it just an experiment?
If yes it should be a draft. If no, there should be an advantage over the existing implementation

@saqimtiaz
Copy link
Member

If no, there should be an advantage over the existing implementation

We do not have an existing working implementation of an alternate store and this furthers the so far incomplete work in #7329.

Yes, this might be more suitable as a draft PR at this time. However I would hope that we could endeavour to request clarification on such things in a manner that would be less prone to coming across as hostile to contributors.

@pmario
Copy link
Member

pmario commented Jun 5, 2023

What's the purpose of this PR?

It is meant as a question. I wanted to get more information about the plugin. That's it. No pun intended.

@joshuafontany
Copy link
Contributor Author

Hi @pmario @saqimtiaz. Thanks for clarifying. Yes, this has taken the changes that @Jermolene made in his PR in boot/boot.js, which opens up defining a $tw.Wiki module before booting the whole TW code. The new example code in plugins/tiddlywiki/demo-alternate-store/rawmarkup.js is a straight up copy/paste out of boot.js, with a few required helper methods from $tw.utils copied over and renamed to allow the $tw.Wiki parallel code to work.

@joshuafontany joshuafontany marked this pull request as draft June 6, 2023 00:37
@Jermolene
Copy link
Member

Thank you @joshuafontany this is exactly what I was planning to do in #7329 before I got distracted. Could you retarget this PR to target the branch for #7329? I think that would make the history easier to follow.

@Jermolene
Copy link
Member

By the way @joshuafontany would you be interested in working on an SQLite implementation? It was that idea that triggered #7329.

@linonetwo
Copy link
Contributor

linonetwo commented Jun 9, 2023

Latest prerelease of TidGi https://github.com/tiddly-gittly/TidGi-Desktop/releases/tag/v0.8.0-prerelease11

has a better-sqlite3 instance at $tw.utils.Sqlite. Which is accessable for server side plugin. (TidGi is a launcher for nodejs wiki)

And there is a predefined table https://github.com/tiddly-gittly/TidGi-Desktop/blob/5651ea70c6301bbabacf45126b84a60b630b3a4b/src/services/database/index.ts#L47-L59

CREATE TABLE IF NOT EXISTS tiddlers (
          title TEXT PRIMARY KEY,
          text TEXT,
          type TEXT,
          created INTEGER,
          modified INTEGER,
          tags TEXT,
          fields TEXT,
          creator TEXT,
          modifier TEXT
          );

You can try this from wiki frontent using zx script https://talk.tiddlywiki.org/t/interactive-code-executing-in-tiddlygit-like-ipython-notebook/780

Usage is like

// pure nodejs context
console.log(`## Hi!`);
let aaa = 3;

/** tw */

// now in worker_thread with $tw wiki access

let filterExample = $tw.wiki.filterOperators.sum((callback) => {callback({}, String(aaa));callback({}, String(aaa))})
console.log(filterExample)

// use Sqlite
const db = $tw.utils.Sqlite
const stmt = db.prepare('SELECT title, text FROM tiddlers');
const result = stmt.pluck().all()
console.log(result)

click this icon to execute zx script
图片

See $:/plugins/linonetwo/zx-script in plugin list for more usage. For example it says only code after /** tw */ can access $tw


(function() {

// Need to initialise these because we run before bootprefix.js and boot.js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not do these in bootprefix.js or boot.js, seems you init them but not used.

}
}
},
hop = function(object,property) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we redefining too many things? I thought we just need to define some hooks to do "hydration"

};

// Add a tiddler to the store
this.addTiddler = function(tiddler) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we only need to define these fuctions in the plugin?

@Jermolene
Copy link
Member

Hi @joshuafontany – are you in a position to be able to retarget this PR to the branch demo-alternate-store?

Jermolene added a commit that referenced this pull request Jun 22, 2023
And make the demo storage areas switchable

@joshuafontany's implementation was in #7521
@Jermolene
Copy link
Member

Hi @joshuafontany I hope you don't mind, but I've merged your updated plain JS wiki implementation in 1d0b928

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants