lister les messages en bdd

This commit is contained in:
Tykayn 2022-07-07 19:28:40 +02:00 committed by tykayn
parent 3f4dc96e97
commit b92e5bd049
4 changed files with 50 additions and 61 deletions

Binary file not shown.

View File

@ -8,3 +8,9 @@ a {
padding: 1em;
margin-right:1ch;
}
.post-message{
margin: 1em;
border-left: 3px solid #ccc;
padding-left: 1em;
}

View File

@ -20,8 +20,6 @@ const {sql} = require('@databases/sqlite');
const db = connect(database_masto);
function createDatabase() {
var newdb = new sqlite3.Database(database_masto, sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE, (err) => {
@ -52,17 +50,13 @@ function createTables(newdb) {
`);
console.log('requête de création faite')
}
const prepared = prepare();
}
function getAllPosts(db) {
db.query(sql`SELECT * FROM posts_scheduled;`).then(
(results) =>
{
console.log(results)
},
(err) => console.error(err),
);
return db.query(sql`SELECT *
FROM posts_scheduled;`)
}
router.get('/init-db', function (req, res, next) {
@ -76,57 +70,44 @@ router.get('/init-db', function (req, res, next) {
router.get('/list', function (req, res, next) {
// let posts_list = [{
// action_id: 1,
// post_username: "modominem",
// content: "demo post list",
// medias: "media file name from assets folder",
// date_schedule: "2022-07-07 "
// }]
var db = new sqlite3.Database('../masto_posts.db', sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE, (err) => {
if (err && err.code == "SQLITE_CANTOPEN") {
createDatabase();
return;
} else if (err) {
console.log("Getting error " + err);
exit(1);
}
getAllPosts(db);
});
let posts_list = [{
action_id: 1,
post_username: "modominem",
content: "demo post list",
medias: "media file name from assets folder",
date_schedule: "2022-07-07 "
}]
getAllPosts(db)
res.render('database', {posts_list: posts_list});
getAllPosts(db).then(
(results) => {
console.log( "liste de posts " ,results)
res.render('database', {posts_list: results});
},
(err) => console.error(err),
);
});
router.get('/add-to-db-example', function (req, res, next) {
let db = connect(database_masto);
var db = new sqlite3.Database('../masto_posts.db',
sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE,
(err) => {
if (err && err.code == "SQLITE_CANTOPEN") {
createDatabase();
return;
} else if (err) {
console.log("Getting error " + err);
exit(1);
}
db.exec(`
async function prepare() {
await db.query(sql`
insert into posts_scheduled
values (NULL, "modominem", "un message d'example", "un jour")
;
`).then(resp => {
console.log(resp)
`);
});
let posts_list = []
res.render('database', {posts_list: posts_list});
},
err => {
console.log(err)
});
}
}
);
// publier le message en db dans la file

View File

@ -3,7 +3,9 @@ extends layout
block content
h1 Liste des prochains posts prévus
div.posts
h2 posts_list.length + " posts"
// for p in posts_list
// span.author = p.post_username
// span.content = p.content
h2= posts_list.length + " posts"
for p in posts_list
div.post-message
strong.author= p.post_username
div.content= p.content