Using TW as database

576 views
Skip to first unread message

Claudio

unread,
Aug 18, 2010, 2:36:12 AM8/18/10
to TiddlyWiki
Hi All,

To imitate this good app (http://www.thepapertiger.com/), here're
something I want to try.

1. Append "serial number" to a custom field so that when I add a
tiddler, it will be labeled 001, and subsequent tiddlers 002,
003....,etc. Better if this field is not user-editable.

2. Optionally display tiddlers as rows, with a "preview" column that
displays the first few lines of the content.
|Serial|Title|Tag|Content|Last Modified|Custom Field 1|Custom Field 2|
|023|Test Tiddler|This is a testing tiddler that...|2010-08-08|CF1|
CF2|

Click on a title displays the tiddler the standard way.


Any ideas?

FND

unread,
Aug 18, 2010, 4:54:39 AM8/18/10
to tiddl...@googlegroups.com
> Append "serial number" to a custom field so that when I add a
> tiddler, it will be labeled 001, and subsequent tiddlers 002,
> 003....,etc.

You could hijack the saveTiddler method, automatically adding this
custom field (presumably determining the latest ID on startup):
http://trac.tiddlywiki.org/browser/Trunk/core/js/TiddlyWiki.js?rev=12238#L309

That might look something like this:

(function() {

// assumes SERIALID has been initialized

var _saveTiddler = TiddlyWiki.prototype.saveTiddler;
TiddlyWiki.prototype.saveTiddler = function() {
var tiddler = _saveTiddler.apply(this, arguments);
if(!tiddler.fields.serialid) {
SERIALID++;
tiddler.fields.serialid = SERIALID.toString();
}
};

})();

(Note that field names must be lower case and values are strings.)

> Better if this field is not user-editable.

There's no access control in regular TiddlyWikis, as it's all happening
client-side.
So unless you're using some server-side, that's not really enforceable -
however, it might be sufficient to not make it easy for users to change
this data.

> 2. Optionally display tiddlers as rows, with a "preview" column that
> displays the first few lines of the content.

Shouldn't be hard to create a macro for this.
In fact, there are probably ForEachTiddler scripts out there that do
very similar things - you might wanna search the group archives.

HTH.


-- F.

Kashgarinn

unread,
Aug 18, 2010, 7:08:44 PM8/18/10
to TiddlyWiki
I'd recommend checking out tagglytagging plugin from MPTW:
http://mptw.tiddlyspot.com/

Basically you turn a tiddler upside down making the tiddler unique,
but the tags the common link between information.

Tiddler names are unique, so use that as your identifier, have the
unique information inside the tiddler, then just use tagglytagging and
tags to make sense of the information like you'd want.

I'm not so sure it's exactly what you need or want, but tags to me is
a main reason why TW is so great.

K.

okido

unread,
Aug 19, 2010, 12:37:00 PM8/19/10
to TiddlyWiki
Hi Claudio,

You could use autoNumber plugin form http://members.home.nl/zonborgele/autoNumber.html

But it requires Datatiddler plugin write now.
A re-write is in the make that can create a tiddler tiddler in the
format:
>> Leading text 123456 trailing text <<.
It will longer depend on Datatiddler plugin and text can be left out.

To make a table the following script could be used as an example:

<script>
var out=[];
out.push("|!Title|!Date|"); //create tabel header
var tids=store.getTaggedTiddlers('specific'); //get tiddlers
tagged with: specific
for( i = 0 ; i < tids.length ; i++) {
out.push( "|" + "[[" + tids[i].title + "|" + tids[i].title +
"]] " + "|" + tids[i].created +"|"); // add a table entry for every
tiddler
}
return out.join('\n'); // print it
</script>

Past it in a tiddler and of you go, just expand the line that creates
the table entries and the header, InlineJavaScript plugin required.

Have a nice day, Okido

Okido

Alex Hough

unread,
Aug 19, 2010, 12:54:46 PM8/19/10
to tiddl...@googlegroups.com
I like the idea of a serial number field and was thinking how a
database model could be applied to TiddlySpace. The idea would be to
have a collection of TWs each having their own serial numbers - the
same method of numbering in each space.

But I suppose that you could make the tiddler.title the ID and
automatically generate that starting from 001. Then use a custom field
for the content that would go in the tiddler's title field. That way
you'd enforce uniqueness on the title, and be allowed to have more
than one tiddler of the same "title".

just some thoughts coming off the top of my head right now - not sure
if i make sense. Always get confused when i start thinking about
messing with tiddlers - that MPTW fealing all over again.

Alex

> --
> You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
> To post to this group, send email to tiddl...@googlegroups.com.
> To unsubscribe from this group, send email to tiddlywiki+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/tiddlywiki?hl=en.
>
>

PMario

unread,
Aug 19, 2010, 1:56:02 PM8/19/10
to TiddlyWiki
On Aug 19, 6:54 pm, Alex Hough <r.a.ho...@gmail.com> wrote:
> I like the idea of a serial number field and was thinking how a
> database model could be applied to TiddlySpace. The idea would be to
> have a collection of TWs each having their own serial numbers - the
> same method of numbering in each space.
I think there will be a hash soon in tiddlyspace. which will be a
unique number. I don't know, if the new .revision counter is unique?
FND will know.

FND

unread,
Aug 19, 2010, 3:20:04 PM8/19/10
to tiddl...@googlegroups.com
> I think there will be a hash soon in tiddlyspace. which will be a
> unique number.

Well, the hash will be calculated from the tiddler body, so tiddlers
with the same content but different metadata (e.g. tags) will have the
same hash.

> I don't know, if the new .revision counter is unique?

You mean the revision numbers of tiddlers in TiddlySpace? While those
are indeed unique, that is an artifact of the store implementation being
used on the server (a MySQL database) - so I wouldn't rely on it.


-- F.

Alex Hough

unread,
Aug 20, 2010, 4:52:40 AM8/20/10
to tiddl...@googlegroups.com
>> I think there will be a hash soon in tiddlyspace. which will be a
>> unique number.
will the hash be unique in the world, or unique to the space?

alex

Jeremy Ruston

unread,
Aug 20, 2010, 5:23:29 AM8/20/10
to tiddl...@googlegroups.com
>>> I think there will be a hash soon in tiddlyspace. which will be a
>>> unique number.
> will the hash be unique in the world, or unique to the space?

The hashing will be just produced from the tiddler text, and therefore
the same tiddler content in a different space, or on a different
server, would carry the same hash identifier.

This means that it should be possible to use the hashes to track
tiddlers that are copied between tiddlywikis/spaces.

Cheers

Jeremy

--
Jeremy Ruston
mailto:jer...@osmosoft.com
http://www.tiddlywiki.com

FND

unread,
Aug 20, 2010, 6:05:13 AM8/20/10
to tiddl...@googlegroups.com
>> I think there will be a hash soon in tiddlyspace. which will be a
>> unique number.
>
> will the hash be unique in the world, or unique to the space?

To expand on what Jeremy has already said, TiddlySpace's hashing is not
meant to be used as unique identifier[1][2] for individual tiddlers, but
is gonna be a checksum[3] of the contents.


-- F.


[1] http://en.wikipedia.org/wiki/Universally_unique_identifier
[2] http://en.wikipedia.org/wiki/Globally_unique_identifier
[3] http://en.wikipedia.org/wiki/Checksum

will

unread,
Aug 20, 2010, 11:04:12 AM8/20/10
to TiddlyWiki
Hello hello Claudio and all.

I am feeling 'at home' here concerning this idea. Before I go on,
have you blokes seen CouchApp and CouchDB?

* http://books.couchdb.org/relax/

It uses a jQuery framework to serve up 'text' based on some namespace
(table) and name hash (index column). No offence intended with such
gross over-simplifications.

One thing I thought of, might be to use 'couchdb' with TiddlyWiki to
fabricate a shared. distributed REST-ful TiddlyWiki style wiki.
Everything is the 'same', but everyone involved has their tiddlers
replicated (shadowed) in a couchDB back-end (foundation? store -- For
want of a better name).

Returning specifically to the database theme (but). A little while
ago, I wanted to use TiddlyWiki for a prototype engine to demonstrate
web site models 'fast'. And the database functionality came up when
considering that idea. Mostly because Most web sites of enough
complexity depend on a way to change stuff and personalise/customise
the rendered pages.

The idea I had for mock-ups was to use transclusions to bring in
rows. Yes, I concede it was quick and dirty. It had the advantage of
making a Tiddler =0= one table. I made the 'rows' were like a primary
key, using a heading. Example:

Table_one
| col 1 | col 2 | col 3 |
<<tiddler [[Table_one##key=001]]>>
<<tiddler [[Table_one##key=002]]>>
<<tiddler [[Table_one##key=003]]>>
-----------------------
Table_one_cols
!key=001
|col_01 | col_02| col_03 |
!key=002
|col_01 | col_02| col_03 |
!key=003
|col_01 | col_02| col_03 |
!(end)


Alas, it didn't quite work out, and I was reduced to making mock-up
via one table in Table_one.

As an alternative, you can transclude cell contents -- In that scheme
(which was too specific for my needs) ... You can have one table
transcluding cells via naming conventions for 'rows' and 'columns',
viz.

Table_one
| col 1 | col 2 | col 3 |
|<<tiddler [[tmp##row=001,col=001]]>> |<<tiddler
[[tmp##row=001,col=002]]>> |<<tiddler [[tmp##row=001,col=003]]>> |
|<<tiddler [[tmp##row=002,col=001]]>> |<<tiddler
[[tmp##row=002,col=002]]>> |<<tiddler [[tmp##row=002,col=003]]>> |
|<<tiddler [[tmp##row=003,col=001]]>> |<<tiddler
[[tmp##row=003,col=002]]>> |<<tiddler [[tmp##row=003,col=003]]>> |

----
tmp
!row=001,col=001
(1,1)
!row=002,col=001
(2,1)
!row=003,col=001
(3,1)
!row=001,col=002
(1,2)
!row=002,col=002
(2,2)
!row=003,col=002
(3,2)
!row=001,col=003
(1,3)
!row=002,col=003
(2,3)
!row=003,col=003
(3,3)
!(end)

I thought you can have a tiddler per cell, this way at least all of
the table lives in one tiddler.

Harking back to the couchdb model, if you succeeded with that, I
thought each cell's contents could be 'couchdb document' indexed by
row/column tuples.

Intuitively I think there's probably a more elegant way to go. Like
generating the cell name dynamically (via a macro or function). This
is more or less a 'thunk' such that you can call-up a tiddler (cell)
"by name" or "by reference".

Hopefully that's food for thought. I have one question in return.
Most of the time I found databases need to be operated on -- Search/
Filter/Join or Combine/etc and basic set algebra operations -- To be
really helpful. Otherwise they just become mere tables.

I'm wondering how much functionality will your use-cases need from the
Tiddler-based-database?

Cheers,
Will

Claudio

unread,
Aug 23, 2010, 12:31:20 AM8/23/10
to TiddlyWiki
Thanks Okido.

Your script works nice. But what if I want to add a column for a
custom field called Keyword?
I think can modify the out.push line to add "!keyword|" but I'm not
sure how to get its value shown in a table row.



On 8月20日, 上午12時37分, okido <bkn...@gmail.com> wrote:
> Hi Claudio,
>
> You could use autoNumber plugin formhttp://members.home.nl/zonborgele/autoNumber.html
> > K.- 隱藏被引用文字 -
>
> - 顯示被引用文字 -

FND

unread,
Aug 23, 2010, 3:07:29 AM8/23/10
to tiddl...@googlegroups.com
> Your script works nice. But what if I want to add a column for a
> custom field called Keyword?

out.push("|!Title|!Date|!Keyword|h"); // create tabel header
[...]
out.push( "|[[" + tids[i].title + "]] " + "|" + tids[i].created +"|" +
tids[i].fields.keyword +"|");

(Personally, I'd construct the table using the DOM rather than
wikification, but that's not directly relevant here.)

HTH.


-- F.

Claudio Li

unread,
Aug 23, 2010, 3:13:13 AM8/23/10
to tiddl...@googlegroups.com
Thx. FND. One more question there. Can I change the date format? It shows "Mon Aug 23 2010 14:26:00 GMT+080", which is too long...

FND

unread,
Aug 23, 2010, 3:13:58 AM8/23/10
to tiddl...@googlegroups.com
> One thing I thought of, might be to use 'couchdb' with TiddlyWiki to
> fabricate a shared. distributed REST-ful TiddlyWiki style wiki.

Using CouchDB as backend would indeed be awesome.
There has been some interest in this before[1][2] - personally, I think
it'd be great if there was a couch app providing (a subset of) the
TiddlyWeb API, as that would mean a lot of existing code (e.g. the
adaptor) could simply be reused.


-- F.


[1] http://groups.google.com/group/tiddlywiki/t/f331501c09e10549
[2] http://groups.google.com/group/tiddlywiki/t/125feda2eae813a4

FND

unread,
Aug 23, 2010, 3:42:02 AM8/23/10
to tiddl...@googlegroups.com
> Can I change the date format?

tids[i].created.formatString("YYYY-0MM-0DD 0hh:0mm");

see http://tiddlywiki.org/wiki/Timestamps


-- F.

okido

unread,
Aug 23, 2010, 11:50:22 AM8/23/10
to TiddlyWiki
Hi FND,

Could you give us an example how to build a table by changing the DOM
directly.
I am interested because I have a large table that builds rather slow,
120rows and 6 cols, it is sortable by clicking on the headers.
I thought it might be quicker when a would replace the script by a
plugin.
But direct manipulation of the DOM might probably even faster.

Have a nice day, Okido


FND

unread,
Aug 24, 2010, 3:25:46 AM8/24/10
to tiddl...@googlegroups.com
> Could you give us an example how to build a table by changing the DOM
> directly.

Sure:

---------------

(function($) { // use "$" as local alias for jQuery

var table = $("<table />");
$("<tr />").
append("<th>Title</th>").
append("<th>Date</th>").
appendTo(table);

var tiddlers = store.getTaggedTiddlers("foo");
for(var i = 0; i < tiddlers.length; i++) {
var tiddler = tiddlers[i];
var link = createTiddlyLink(null, tiddler.title, true);
var timestamp = tiddler.created.
formatString("YYYY-0MM-0DD 0hh:0mm");
var row = $("<tr />").appendTo(table);
$("<td />").append(link).appendTo(row);
$("<td />").append(timestamp).appendTo(row);
}

table.appendTo(place); // assumes "place" is a DOM element

})(jQuery);

---------------

(I've kept it basic - there are ways to optimize this and to make it
more elegant, but would have made this example more complex.)


-- F.

okido

unread,
Aug 24, 2010, 11:08:33 AM8/24/10
to TiddlyWiki
Thanks FND, worked instantly and l have the impression that it is
faster.
I will try to get some basic understanding about the jquery stuff.
The code looks more readable too me than most of the javasript that
have around for generating tables etc.

Have a nice day, Okido

UnclePhil

unread,
Sep 5, 2010, 3:21:57 PM9/5/10
to TiddlyWiki
to FND and all other

This (http://unclephil.couchone.com/mytw/MyTw/index.html) is a first
step.
A simple save of the whole tw inn couchdb with ability to create
backup.

For the future, i'm busy to split the TW file structure in the
couchapp one, and then i'll try to fine tune the result during my
freetime
But freetime means no money ... and i don't know why my wife is not
fully ok with this.....

So be patient ... or faster than me

Unclephil

FND

unread,
Sep 6, 2010, 2:02:01 PM9/6/10
to tiddl...@googlegroups.com
> For the future, i'm busy to split the TW file structure in the
> couchapp one, and then i'll try to fine tune the result during my
> freetime [...] So be patient ... or faster than me

Actually, why don't we combine our efforts? I don't have a whole lot of
experience with CouchDB, but wanted to get back to playing with it
anyway - and having worked on the TiddlyWiki<->TiddlyWeb side of things
a lot, I could probably help move things along.

If you could provide some guidance on design documents, views and such,
I could quickly come up with some exemplary code to store and retrieve
tiddlers (preferably over on [twdev] to keep the noise down).


-- F.

UnclePhil

unread,
Sep 7, 2010, 5:43:03 AM9/7/10
to TiddlyWiki
I know you have write it because i try to reverse it in the "couch
concept"
The big difference between tiddlyweb (that i use also) and couch is
the notion of recipe and bag, and the fact that tiddlyweb build
automatically all list needed by the framework.
This is not true in couch and we need to build every view & list to
match the two concept

So to port TW on couch, we have 2 solutions ,the port the tiddlyweb
concept on another db backend like it was done with mysql for Tspace
(i think), or the build of a new TW adaptator who's more couch
specific

And i think the second one is my first path

Another thing is to know if we do the port " a la couchapp" (splitting
of the code & more elegant in the couch world) or "a la TW" everything
in one file and the data outside (more compatibility with future TW
development)

So for the moment that's more try and error (with many error)

Ph Koenig
Aka Unclephil

FND

unread,
Sep 7, 2010, 1:20:58 PM9/7/10
to tiddl...@googlegroups.com
> I know you have write it because i try to reverse it in the "couch
> concept" [...] tiddlyweb (that i use also)

Oh, good to know.

> So to port TW on couch, we have 2 solutions ,the port the tiddlyweb
> concept on another db backend like it was done with mysql for Tspace
> (i think), or the build of a new TW adaptator who's more couch specific
> And i think the second one is my first path

I agree an adaptor is the right approach, as TiddlyWiki is perfectly
capable of interacting with CouchDB by itself. We can worry about
compatibility with TiddlyWeb's HTTP API (or a subset thereof) later.

(TiddlyWeb's MySQL store is just an extension of the server-side's
storage layer, with no impact on the HTTP API. I had experimented with
such a store implementation using CouchDB a while back*.)

> Another thing is to know if we do the port " a la couchapp" (splitting
> of the code & more elegant in the couch world) or "a la TW" everything
> in one file and the data outside

The way TiddlyWebWiky handles this is to store each tiddler individually
and populating an empty TiddlyWiki template by adding the appropriate
HTML representation for each tiddler to the HTML document (above the
"<!--POST-STOREAREA-->" marker present in each TiddlyWiki).
I'm not sure which facilities CouchDB offers for such server-side
processing though.


-- F.


* http://gist.github.com/310251

Reply all
Reply to author
Forward
0 new messages