You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Convert the static book model into actual database queries. The follwing two queries will help initialize the data (you can execute them with sql.executeInsert() and sql.executeUpdate()):
createtableif not exists books (id intprimary key auto_increment, title varchar(255), content varchar(255))
merge into books (id, title, content) key (id) values (0, 'Book 1', 'Stuff')
To query books, you can use the sql.rows() method, then turn the result into a collection of Book objects. The SQL query for reading the books is left as an exercise for the student.
5. Creating Books
Remove the code that statically initializes the book data.
Add a handler block for the create URI path. The create path should respond to GET and POST verbs. Use the byMethod method to contain both of these handlers.
The GET handler should render the create.html template.
The POST handler should parse the input form, create a new book with sql.executeInsert(), and redirect to a URL that displays the new book. (NOTE: a handler for this URL already exists.)