Joshua Wise |
|
I've also been doing some other random stuff lately. RiciLake suggested that I start documenting stuff, so as I find interesting things that I've done, I'll post them here. Like him, I can be found on the IRC channel, which is available at irc://irc.freenode.net/#lua -- my username is usually joshua_. If you're looking for me elsewhere on the web, try http://joshuawise.com/ .
require"lails" require"luasql.sqlite" env = luasql.sqlite() conn = env:connect("/home/joshua/mirror-objects.sqlite") db = lails.db:new(conn){ tables = { objects = { primkey = "hash" } } } test = db.objects dofile("objects.lua") conn:execute("BEGIN TRANSACTION;") for k,v in pairs(objects) do test[k] = { moddate = v.moddate, mimetype = v.mimetype, mirrored = v.mirrored, length = v.length, lastaccessed = v.lastaccessed, url = v.url } end conn:execute("COMMIT;")I whipped this up in about 25 minutes this afternoon. The neat bit about this is that when I convert the user of the datastore over, I won't really have to change much -- the only difference will be that I won't have to load and store the datastore, I can just act directly on the database. More on how Lails actually works later.
sqlite> INSERT INTO users (id, username) VALUES (1, "joshua"); sqlite> INSERT INTO users (id, username) VALUES (2, "someone"); sqlite> INSERT INTO acls (id, resource, user) VALUES (1, "/", 1); sqlite> INSERT INTO acls (id, resource, user) VALUES (2, "/home/someone", 2); sqlite> INSERT INTO acls (id, resource, user) VALUES (3, "/tmp", 2);Slick, huh? Did this 2007-02-04 (early in the morning; if you saw it mid day 2007-02-04, you're already out of date)
#define function main() { int i = 0; function --i; printf("Hello, world!\n"); } /* x() print("Hello, world!") end x() -- */