Part 1: http://msprogrammer.serviciipeweb.ro/2018/10/08/literary-awardspart-1/
Part 2: http://msprogrammer.serviciipeweb.ro/2018/10/15/literary-awardspart-2/
Part 3: http://msprogrammer.serviciipeweb.ro/2018/10/22/literary-awardspart-3/
Part 4: http://msprogrammer.serviciipeweb.ro/2018/10/29/literary-awardspart-4/
Part 5: http://msprogrammer.serviciipeweb.ro/2018/11/05/literary-awardspart-5/
The data – this was the difficult part. As I said, I wanted the data to be local – but how can I put the first time ? And where ? I cannot be cookie, since the authors are a large database for cookies…
There are 3 options : LocalStorage, WebSql and IndexedDB . You can read about those at https://nolanlawson.com/2015/09/29/indexeddb-websql-localstorage-what-blocks-the-dom/ . I choose LocalStorage because it was simpler – however, this is making the startup of the application slower!
Now, how can I store the data ? For me, a database with select it was fine – but can I find one that works in the browser ? And with javascript ? Apparently, yes! There is a port from C to js of SQLite – https://github.com/kripken/sql.js/ . That means , I can have a SQLIte database and access via Select. Add I can persist too – see https://github.com/kripken/sql.js/wiki/Persisting-a-Modified-Database .
With all those, now I am ready to have the Nobel authoirs in my application – but how can I introduce to my application ? The list exists on Wikipedia( https://en.wikipedia.org/wiki/List_of_Nobel_laureates_in_Literature) and at Nobel site (https://www.nobelprize.org/prizes/literature/) . How can I load those into my SQLite LocalStorage database ?
Here comes another pet project of mine, stankins . With this I can transform the wikipedia page into this:
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | db.run( "INSERT INTO tableAuthors (Year,Laureate,Languages,Citation,Genres,PictureUrl,LaureateFullWiki,name) VALUES (?,?,?,?,?,?,?,?)" , [
"1901" ,
"Sully Prudhomme" ,
"French" ,
'"in special recognition of his poetic composition, which gives evidence of lofty idealism, artistic perfection and a rare combination of the qualities of both heart and intellect"[12]' ,
"poetry, essay" ,
"//upload.wikimedia.org/wikipedia/commons/thumb/3/39/Sully-Prudhomme.jpg/75px-Sully-Prudhomme.jpg" ,
"Sully_Prudhomme"
]);
db.run( "INSERT INTO tableAuthors (Year,Laureate,Languages,Citation,Genres,PictureUrl,LaureateFullWiki,name) VALUES (?,?,?,?,?,?,?,?)" , [
"1902" ,
"Theodor Mommsen" ,
"German" ,
'"the greatest living master of the art of historical writing, with special reference to his monumental work, A History of Rome"[13]' ,
"history, law" ,
"//upload.wikimedia.org/wikipedia/commons/thumb/e/e9/T-mommsen-2.jpg/75px-T-mommsen-2.jpg" ,
"Theodor_Mommsen"
]);
|
Obvious, it is not perfect – but it works!
What can I do with upgrades * because , obvious, each year I should add the Nobel authors ? Nothing simpler: I will modify the name of the database with the application version from package.json
In environement.ts ( and in prod)
1 | VERSION: require( '../../package.json' ).version
|
In the typescript class:
1 | public version: string = environment.VERSION;
|
Finally , in the create database
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | this .dbPers = new SQL.PersistentDatabase(
"nobel_v" + this .version,
async function (sender) {
self.createDatabase(sender).then(()=>{
sender.save();
});
},
function (e) {
alert( "database failed" + e);
}
);
|
The source code is at github:https://github.com/ignatandrei/LiteraryAwards