Skip to content

Commit

Permalink
feat: auto-add Start and End bookmarks on build
Browse files Browse the repository at this point in the history
  • Loading branch information
sarabveer committed Jun 14, 2023
1 parent d8e8a72 commit abb4048
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
17 changes: 17 additions & 0 deletions lib/build-database.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,13 +425,30 @@ const importBanis = async trx => {
) )
} ) )

// Insert Bookmarks
await trx.insert( {
line_id: lines[ 0 ].start_line,
name_gurmukhi: 'ArMB',
name_english: 'Start',
bani_id: id,
order_id: 0,
} ).into( 'bani_bookmarks' )

await Promise.all( (
bookmarks.map( ( bookmark, bookmarkIndex ) => trx.insert( {
...bookmark,
bani_id: id,
order_id: bookmarkIndex + 1,
} ).into( 'bani_bookmarks' ) )
) )

await trx.insert( {
line_id: lines[ lines.length - 1 ].end_line,
name_gurmukhi: 'smwpqI',
name_english: 'End',
bani_id: id,
order_id: bookmarks.length + 1,
} ).into( 'bani_bookmarks' )
} ) )

console.log( 'Successfully imported tables banis, bani_lines'.success )
Expand Down
2 changes: 2 additions & 0 deletions lib/build-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ const processBanis = async () => {
.select( [ 'line_id', 'name_gurmukhi', 'name_english' ] )
.from( 'bani_bookmarks' )
.where( 'bani_id', id )
.whereNot( 'name_english', 'Start' )
.whereNot( 'name_english', 'End' )
.orderBy( 'order_id' )

return [ ...( await compiled ), { id, ...data, lines, bookmarks } ]
Expand Down
2 changes: 1 addition & 1 deletion lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ const createSchema = ( knex, type ) => knex.schema
table.string( 'name_gurmukhi' ).notNullable()
table.string( 'name_english' ).notNullable()
table.integer( 'order_id' ).notNullable()
table.primary( [ 'line_id', 'bani_id' ] )
table.primary( [ 'line_id', 'bani_id', 'order_id' ] )
} )

module.exports = createSchema

0 comments on commit abb4048

Please sign in to comment.