On Mon, 10 Nov 2014 15:12:15 -0600
"'Terry Brown' via leo-editor" <leo-editor@googlegroups.com> wrote:

> It's pretty trivial to translate Leo's data structure to these tables,

So just for amusement, here's some code that does that:

import sqlite3
con = sqlite3.connect(":memory:")
cur = con.cursor()
cur.execute("create table node (node gnx, head text, body text)")
cur.execute("create table link (parentnode gnx, childnode gnx, childposition 
int)")
for nd in c.all_unique_nodes():
    cur.execute("insert into node values (?, ?, ?)", [nd.gnx, nd.h, nd.b])
    for n, child in enumerate(nd.children):
        cur.execute("insert into link values (?, ?, ?)", [nd.gnx, child.gnx, n])
ans = cur.execute("select count(*) from node")
g.es(ans.fetchone()[0], 'nodes')
ans = cur.execute("select count(*) from link")
g.es(ans.fetchone()[0], 'links')

using SQLite3 (included in Python) and PEP 249
http://legacy.python.org/dev/peps/pep-0249/

SQLite3 has loose typing so it accepts the unknown type name "gnx", you
could use "text" in another RDMS.  The code doesn't create indexes or
enforce the existence of a corresponding Node record for each link
record, but that could be added.  The question is, now that the
outline's in a RDB, what to do with it?

Cheers -Terry

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To post to this group, send email to leo-editor@googlegroups.com.
Visit this group at http://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to