create db ok
This commit is contained in:
parent
75325543a8
commit
3f4dc96e97
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,3 @@
|
|||||||
/.env
|
/.env
|
||||||
masto_posts.db
|
*.db
|
||||||
node_modules
|
node_modules
|
Binary file not shown.
@ -19,15 +19,7 @@ const {sql} = require('@databases/sqlite');
|
|||||||
|
|
||||||
const db = connect(database_masto);
|
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() {
|
function createDatabase() {
|
||||||
@ -38,38 +30,39 @@ function createDatabase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createTables(newdb) {
|
function createTables(newdb) {
|
||||||
newdb.exec(`
|
async function prepare() {
|
||||||
create table posts_scheduled
|
await db.query(sql`
|
||||||
(
|
create table posts_scheduled
|
||||||
action_id int primary key not null,
|
(
|
||||||
post_username text not null,
|
action_id integer
|
||||||
content text not null,
|
constraint posts_scheduled_pk
|
||||||
medias text,
|
primary key autoincrement,
|
||||||
date_schedule datetime
|
post_username varchar not null,
|
||||||
);
|
content varchar not null,
|
||||||
insert into posts_scheduled
|
medias varchar,
|
||||||
values (NULL, "modominem", "un message d'example", "un jour")
|
datetime datetime
|
||||||
;
|
);
|
||||||
`, () => {
|
|
||||||
getAllPosts(newdb);
|
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) {
|
function getAllPosts(db) {
|
||||||
db.all(`
|
db.query(sql`SELECT * FROM posts_scheduled;`).then(
|
||||||
select *
|
(results) =>
|
||||||
from posts_scheduled p orderyby p.action_id desc`, "les posts", (err, rows) => {
|
{
|
||||||
if (rows) {
|
console.log(results)
|
||||||
rows.forEach(row => {
|
},
|
||||||
console.log(row.post_username + "\t" +
|
(err) => console.error(err),
|
||||||
row.content + "\t" +
|
);
|
||||||
row.medias);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
console.log('no rows')
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
router.get('/init-db', function (req, res, next) {
|
router.get('/init-db', function (req, res, next) {
|
||||||
|
Loading…
Reference in New Issue
Block a user