2019-12-11 00:07:07 +00:00
var sqlite3 = require ( 'sqlite3' ) . verbose ( ) ;
2022-10-16 17:37:37 +00:00
var db = new sqlite3 . Database ( './menu.dbDocker' ) ;
2019-12-11 00:07:07 +00:00
const _ = require ( 'lodash' ) ;
const shortHash = require ( 'short-hash' ) ;
const SchemaCheck = require ( 'schema-check' ) ;
const { promisify } = require ( 'util' ) ;
const eachAsync = promisify ( db . each ) ;
const meats = [ 'Chicken' , 'Beef' , 'Pork' ] ;
const mealTypes = [ 'Meal' , 'Soup' ] ;
const runSetup = false ;
const obj = {
'name' : 'garlic pulled pork' ,
'url' : 'https://www.marksdailyapple.com/garlic-pulled-pork' ,
'md' : ` Garlic Pulled Pork
===
[ Source ] ( https : //www.marksdailyapple.com/garlic-pulled-pork)
Ingredients :
-- -
- 1 pork shoulder cut ( butt or picnic ) , weighing 3 - 4 pounds
- 1 - 2 tablespoons kosher salt
- 1 / 2 teaspoon cumin
- 1 teaspoon of black pepper
- 1 - 2 tablespoons of granulated garlic or garlic powder
- optional : 6 fresh garlic cloves , peeled
- The juice of one lime ( or sour orange , if you can get one )
- 1 onion
- 1 bay leaf
Instructions :
-- -
1. Mix together salt , cumin , black pepper and granulated garlic .
1. Juice the lime over the seasonings and rub the mixture all over the pork .
1. If you love garlic as much as Pat does , you might want to use fresh garlic , too . Use a knife to slice six thin cuts in the pork and push each clove securely inside each cut . You don ’ t want the fresh garlic to fall out and touch the cooking vessel or it will burn and affect the flavor of the meat .
1. The meat should sit out of refrigeration a half hour before you put it in the oven . This ensures that it will cook evenly throughout . If you want to let the meat marinate in the rub longer than this , put it in the fridge for an hour or even overnight .
1. When you ’ re ready to cook , preheat the oven to 250 degrees Fahrenheit . Place the roast in a pan with one sliced onion and a bay leaf . Cover and roast for three to four hours , or until the middle of the roast reads about 190 degrees and falls apart easily when pulled with a fork .
1. Let the roast rest for twenty minutes or so , then uncover . You ’ ll notice a lot of liquid at the bottom . Use it as a sauce for the meat , which you will now viciously attack with two forks . It ’ ll fall apart pretty readily , and you ’ ll get the idea of the shredding method after a couple of pulls . Enjoy !
` ,
'meat' : 1 ,
'mealtype' : 1
} ;
const objB = {
'name' : 'Tom Kha Gai -- Thai Coconut Soup' ,
'url' : 'https://www.angsarap.net/2012/03/08/tom-kha-gai/' ,
'md' : ` # Tom Kha Gai
[ Source ] ( https : //www.angsarap.net/2012/03/08/tom-kha-gai/)
# # Ingredients
- 600 g chicken breast , sliced
- 6 cups chicken stock
- 1 cup coconut milk
- 4 pcs long tamarind , wrapped in muslin cloth
- 3 stalks lemongrass , white part
- 4 pcs kaffir limes leaves
- 1 1 / 2 cup straw mushrooms , cut in half
- 1 thumb size galangal , cut into 4 pieces
- 3 pcs dried chili , chopped
- 1 tbsp brown sugar
- handful fresh coriander leaves
- handful fresh basil leaves
- fish sauce or sea salt , according to taste
# # Method
1. Pour in chicken stock in a pot and bring it to a boil .
2. Once boiling add chicken , galangal , mushrooms , lemon grass , kaffir , chilli and tamarind .
3. Simmer for 8 minutes .
4. Press muslin cloth with tamarind on top of the pot to extract the juices then discard .
5. Add coconut milk , fish sauce , sugar and simmer for another 2 minutes .
6. Place in bowls then top with basil and coriander .
` ,
'meat' : 1 ,
'mealtype' : 2
} ;
const newRaw = {
'name' : 'Asian pepper steak crock pot recipe' ,
'url' : 'https://www.marksdailyapple.com/asian-pepper-steak-crock-pot-recipe' ,
'md' : 'Asian Pepper Steak Crock Pot Recipe\n ===\n [Source](https://www.marksdailyapple.com/asian-pepper-steak-crock-pot-recipe/)\n \n Ingredients:\n ---\n * 2 lbs. steak (sirloin is preferable, but any other good cut will do)\n * 2 tbsp coconut oil\n * 1-2 cloves of garlic, minced\n * 1/4 cup wheat-free tamari (similar to soy sauce)\n * 1 16 oz can bean sprouts, drained\n * 1 16 oz can diced tomatoes\n * 1 large green pepper, sliced in thin strips\n * 1 small onion, sliced\n * Salt and pepper to taste\n \n Method:\n ---\n 1. On a chopping board, cut the steak on an angle to make strips about a ½ inch thick. \n \n 2. In a large frying pan, add the oil and heat. Saute the steak until it lightly browns. \n \n 3. Drain excess fat, liberally coat the meat with ground pepper and put the meat in the crock pot. \n \n 4. Add garlic and tamari, and mix so that the steak is thoroughly coated.\n \n 5. Cook in a crock pot on low for 6 hours. \n \n 6. One hour before serving, add sprouts, tomatoes, green peppers and onions and turn crock pot to high. \n \n 7. Cook for one hour and then serve piping hot.' ,
'meat' : 2 ,
'mealtype' : 1
} ;
const lorem = {
'_id' : 6 ,
'name' : 'Lorem ipsum dolor sit amet' ,
'url' : 'https://www.marksdailyapple.com/asian-pepper-steak-crock-pot-recipe' ,
'md' : 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.' ,
'short' : 'asian-pepper-steak-crock-pot-recipe' ,
'hash' : 'eac12bae' ,
'meat' : 2 ,
'mealtype' : 1 ,
'lastused' : 0
} ;
function prepareData ( _obj ) {
const newObj = Object . assign ( { } , _obj ) ;
newObj . short = _ . kebabCase ( newObj . name ) ;
newObj . hash = shortHash ( newObj . name ) ;
return newObj ;
}
function insertRecord ( newObj ) {
const workObj = prepareData ( newObj ) ;
db . serialize ( ( ) => {
const stmt = db . prepare ( 'INSERT INTO menu VALUES (?,?,?,?,?,?,?,?,?)' ) ;
stmt . run ( null , workObj . name , workObj . url , workObj . md , workObj . short , workObj . hash , workObj . meat , workObj . mealtype , 0 ) ;
stmt . finalize ( ) ;
} ) ;
}
if ( runSetup ) {
// Create table
db . serialize ( ( ) => {
db . run ( ` CREATE TABLE "menu" (
\ t "_id" \ tINTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE ,
\ t "name" \ tTEXT ,
\ t "url" \ tTEXT ,
\ t "md" \ tTEXT ,
\ t "short" \ tTEXT UNIQUE ,
\ t "hash" \ tTEXT UNIQUE ,
\ t "meat" \ tINTEGER NOT NULL DEFAULT 0 ,
\ t "mealtype" \ tINTEGER NOT NULL DEFAULT 0 ,
\ t "lastused" \ tINTEGER NOT NULL DEFAULT 0
) ; ` );
} ) ;
// Insert record
insertRecord ( obj ) ;
insertRecord ( objB ) ;
}
function getAll ( ) {
const outgoing = [ ] ;
const sql = 'SELECT _id, short, hash, name FROM menu' ;
return new Promise ( ( resolve , reject ) => {
db . all ( sql , [ ] , ( err , rows ) => {
if ( err )
reject ( err ) ;
rows . forEach ( ( row ) => {
outgoing . push ( row ) ;
} ) ;
resolve ( outgoing ) ;
} ) ;
} ) ;
}
function getOne ( hash ) {
const sql = 'SELECT * FROM menu WHERE hash = ?' ;
return new Promise ( ( resolve , reject ) => {
db . get ( sql , [ hash ] , ( err , row ) => {
if ( err )
reject ( err ) ;
if ( ! err ) resolve ( row ) ;
} ) ;
} ) ;
}
function insertOne ( data ) {
const sql = 'INSERT INTO menu VALUES (?,?,?,?,?,?,?,?,?)' ;
const workObj = prepareData ( data ) ;
return new Promise ( ( resolve , reject ) => {
db . run ( sql , [ null , workObj . name , workObj . url , workObj . md , workObj . short , workObj . hash , workObj . meat , workObj . mealtype , 0 ] , function ( err ) {
if ( err )
reject ( err ) ;
resolve ( { 'msg' : 'Row inserted' , '_id' : this . lastID } ) ;
} ) ;
} ) ;
}
function deleteOne ( hash ) {
const sql = 'DELETE FROM menu WHERE hash=?' ;
return new Promise ( ( resolve , reject ) => {
db . run ( 'DELETE FROM menu WHERE hash=?' , hash , function ( err ) {
if ( err )
reject ( err ) ;
resolve ( { 'msg' : 'Row deleted' , 'changes' : this . changes } ) ;
} ) ;
} ) ;
}
function updateOne ( data ) {
const oldHash = data . hash ;
const workObj = prepareData ( data ) ;
const sql = ` UPDATE menu
SET name = ? , url = ? , md = ? , short = ? , hash = ? , meat = ? , mealtype = ? , lastused = ?
WHERE hash = ? ` ;
const newData = [ workObj . name , workObj . url , workObj . md , workObj . short , workObj . hash , workObj . meat , workObj . mealtype , workObj . lastused , oldHash ] ;
return new Promise ( ( resolve , reject ) => {
db . run ( sql , newData , function ( err ) {
if ( err )
reject ( err ) ;
resolve ( { 'msg' : 'Row updated' , 'changes' : this . changes } ) ;
} ) ;
} ) ;
}
/ * d e l e t e O n e ( ' e a c 1 2 b a e ' )
. then ( ( d ) => {
console . log ( 'deleteOne' , d ) ;
} )
. catch ( ( err ) => {
console . error ( err ) ;
} ) ; * /
/ * d e l e t e O n e ( ' e a c 1 2 b a e ' )
. then ( ( d ) => {
console . log ( 'deleteOne' , d ) ;
} )
. catch ( ( err ) => {
console . error ( err ) ;
} ) ; * /
insertOne ( newRaw )
. then ( ( v ) => {
console . log ( 'inserted' , v ) ;
} )
. catch ( ( err ) => {
console . error ( err ) ;
} ) ;
getAll ( ) . then ( ( d ) => {
console . log ( 'then' , d ) ;
} ) ;
let oldRec ;
getOne ( 'eac12bae' )
. then ( ( d ) => {
console . log ( 'One' , d ) ;
oldRec = d ;
lorem [ '_id' ] = oldRec [ '_id' ] ;
updateOne ( lorem )
. then ( ( v ) => {
console . log ( 'updated' , v ) ;
} )
. catch ( ( err ) => {
console . error ( err ) ;
} ) ;
} )
. catch ( ( err ) => {
console . error ( err ) ;
} ) ;
getOne ( 'eac12bae' )
. then ( ( d ) => {
console . log ( 'One' , d ) ;
oldRec = d ;
} )
. catch ( ( err ) => {
console . error ( err ) ;
} ) ;
// console.log(obj);
2022-10-16 17:37:37 +00:00
// dbDocker.insert(obj);
2019-12-11 00:07:07 +00:00
/ *
2022-10-16 17:37:37 +00:00
dbDocker . insert ( { name : 'Peter ' } ) ;
dbDocker . insert ( { name : 'Lucia' } ) ;
dbDocker . insert ( { name : 'Igor' } ) ;
dbDocker . insert ( { name : 'Stano' } ) ;
dbDocker . insert ( { name : 'Jozef' } ) ;
2019-12-11 00:07:07 +00:00
* /
// console.log(r);
2022-10-16 17:37:37 +00:00
// dbDocker.update({ name: 'Jozef', age: 33 }).where('name', 'Jozef');