in memory db

This commit is contained in:
Andrzej Stepien 2023-11-13 12:09:47 +01:00
parent 26d8dd1ec3
commit f2c639b4f2
5 changed files with 49 additions and 1 deletions

6
db.mjs
View File

@ -15,3 +15,9 @@ export const db = knex({
}, },
useNullAsDefault: true useNullAsDefault: true
}) })
const memoryDB = knex({
client:'sqlite3',
connection: ':memory:'
})

View File

@ -11,6 +11,9 @@ export default class Story extends Title{
get table(){ get table(){
return 'stories' return 'stories'
} }
get idName(){
return 'story_id'
}
constructor(data){ constructor(data){
super(data) super(data)
this._word_count=data?.word_count this._word_count=data?.word_count

View File

@ -38,6 +38,9 @@ export default class Submission extends Entity{
get table(){ get table(){
return 'subs' return 'subs'
} }
get idName(){
return 'sub_id'
}
constructor(data){ constructor(data){
super(data) super(data)
this._story_id=data?.story_id this._story_id=data?.story_id

View File

@ -32,4 +32,40 @@ export default class Title extends Entity{
this._genres = data?.genres this._genres = data?.genres
this._deleted = data?.deleted this._deleted = data?.deleted
} }
async updateGenres(db,genres){
const table = this.table+'_genres'
const relevantEntries = await db(table)
.select('*')
.where(this.idName,this.id)
//DELETE FALSES
const truesWithEntry= []
for (const entry of relevantEntries) {
const genreName = genres[entry.genre_id]
if(this.#genres[genreName]===false){
await db(table)
.where('id',entry.id)
.del()
continue
}
truesWithEntry.push(entry.genre_id)
}
//INSERT TRUES
for (const genre in this.#genres){
if(truesWithEntry.includes(genre)){continue}
await db(table)
.insert({
[this.idName]:this.id,
genre_id://GET GENRE ID???!!!
})
}
}
} }

Binary file not shown.