diff --git a/.gitignore b/.gitignore index b0c16e5..a1d95fc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ /.env -masto_posts.db +*.db node_modules \ No newline at end of file diff --git a/mastodon_multi_accounts.db b/mastodon_multi_accounts.db index 00fc4e7..91b2953 100644 Binary files a/mastodon_multi_accounts.db and b/mastodon_multi_accounts.db differ diff --git a/routes/index.js b/routes/index.js index 1dfa658..2968312 100644 --- a/routes/index.js +++ b/routes/index.js @@ -19,15 +19,7 @@ const {sql} = require('@databases/sqlite'); const db = connect(database_masto); -async function prepare() { - await db.query(sql` - CREATE TABLE IF NOT EXISTS app_data ( - id VARCHAR NOT NULL PRIMARY KEY, - value VARCHAR NOT NULL - ); - `); -} -const prepared = prepare(); + function createDatabase() { @@ -38,38 +30,39 @@ function createDatabase() { } function createTables(newdb) { - newdb.exec(` - create table posts_scheduled - ( - action_id int primary key not null, - post_username text not null, - content text not null, - medias text, - date_schedule datetime - ); - insert into posts_scheduled - values (NULL, "modominem", "un message d'example", "un jour") - ; - `, () => { - getAllPosts(newdb); - }); + async function prepare() { + await db.query(sql` + create table posts_scheduled + ( + action_id integer + constraint posts_scheduled_pk + primary key autoincrement, + post_username varchar not null, + content varchar not null, + medias varchar, + datetime datetime + ); + + create unique index posts_scheduled_action_id_uindex + on posts_scheduled (action_id); + + insert into posts_scheduled + values (NULL, "modominem", "un message d'example", NULL); + + `); + console.log('requête de création faite') + } + const prepared = prepare(); } function getAllPosts(db) { - db.all(` - select * - from posts_scheduled p orderyby p.action_id desc`, "les posts", (err, rows) => { - if (rows) { - rows.forEach(row => { - console.log(row.post_username + "\t" + - row.content + "\t" + - row.medias); - }); - } else { - console.log('no rows') - } - - }); + db.query(sql`SELECT * FROM posts_scheduled;`).then( + (results) => + { + console.log(results) + }, + (err) => console.error(err), + ); } router.get('/init-db', function (req, res, next) {