import stuff back from pandoc

This commit is contained in:
Christine Dodrill 2015-07-27 21:29:19 -07:00
parent 7daae052f6
commit 85e9ec60ba
1 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,24 @@
sqlite3 = require "lsqlite3"
db = assert sqlite3.open "../db/posts.db"
update_stmt = assert db\prepare "UPDATE Posts SET mdown=? WHERE id=?"
db\exec [[ BEGIN TRANSACTION; ]]
for post in db\nrows "SELECT * FROM Posts"
with fout = io.open "../raw/posts/#{post.id}.textile.md", "r"
unless fout
db\exec [[ ROLLBACK; ]]
error "can't open #{post.id}.textile.md"
body = fout\read("*a")
do
update_stmt\bind_values body, tonumber(post.id)
update_stmt\step!
update_stmt\reset!
fout\close!
db\exec [[ COMMIT; ]]