diff --git a/scripts/importfrompandoc.moon b/scripts/importfrompandoc.moon new file mode 100644 index 0000000..13b1bbb --- /dev/null +++ b/scripts/importfrompandoc.moon @@ -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; ]]