Skip to content

Commit

Permalink
데이터베이스 orientdb12 웹앱제작-편집2 예제
Browse files Browse the repository at this point in the history
  • Loading branch information
egoing committed Mar 16, 2016
1 parent 9ecfe74 commit 68c81a2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
32 changes: 27 additions & 5 deletions app_orientdb.js
Expand Up @@ -34,10 +34,6 @@ app.post('/upload', upload.single('userfile'), function(req, res){
app.get('/topic/add', function(req, res){
var sql = 'SELECT FROM topic';
db.query(sql).then(function(topics){
if(topics.length === 0){
console.log('There is no topic record.');
res.status(500).send('Internal Server Error');
}
res.render('add', {topics:topics});
});
});
Expand All @@ -56,7 +52,33 @@ app.post('/topic/add', function(req, res){
res.redirect('/topic/'+encodeURIComponent(results[0]['@rid']));
});
});

app.get('/topic/:id/edit', function(req, res){
var sql = 'SELECT FROM topic';
var id = req.params.id;
db.query(sql).then(function(topics){
var sql = 'SELECT FROM topic WHERE @rid=:rid';
db.query(sql, {params:{rid:id}}).then(function(topic){
res.render('edit', {topics:topics, topic:topic[0]});
});
});
});
app.post('/topic/:id/add', function(req, res){
var sql = 'UPDATE topic SET title=:t, description=:d, author=:a WHERE @rid=:rid';
var id = req.params.id;
var title = req.body.title;
var desc = req.body.description;
var author = req.body.author;
db.query(sql, {
params:{
t:title,
d:desc,
a:author,
rid:id
}
}).then(function(topics){
res.redirect('/topic/'+encodeURIComponent(id));
});
});
app.get(['/topic', '/topic/:id'], function(req, res){
var sql = 'SELECT FROM topic';
db.query(sql).then(function(topics){
Expand Down
24 changes: 24 additions & 0 deletions views_orientdb/edit.jade
@@ -0,0 +1,24 @@
doctype html
html
head
meta(charset='utf-8')
body
h1
a(href='/topic') Server Side JavaScript
ul
each topic in topics
li
- rid = encodeURIComponent(topic['@rid'])
a(href='/topic/'+rid)= topic.title
artcle
- rid = encodeURIComponent(topic['@rid'])
form(action='/topic/'+rid+'/add' method='post')
p
input(type='text' name='title' placeholder='title' value=topic.title)
p
textarea(name='description' placeholder='description')
=topic.description
p
input(type='text' name='author' placeholder='author' value=topic.author)
p
input(type='submit')

0 comments on commit 68c81a2

Please sign in to comment.