temp.ts
//async function haveSomeFun() {
//
// Seed Database
//
//console.log("Seeding database with some contacts...");
//await db.transaction('rw', db.contacts, async function () {
// Populate a contact
//let adamId = await db.contacts.add();
//console.log(adamId);
//let adam = new Contact('Adam', 'Tensta');
//console.log(adam);
//await saveContact(adam, db);
//db.notes.put({name: 'test'});
// Populate some emails and phone numbers for the contact
/*db.emails.add({ contactId: adamId, type: 'home', email: 'adam@tensta.se' });
db.phones.add({ contactId: adamId, type: 'work', phone: '88888888' });*/
//});
//
// For fun - add a phone number to Adam
//
// Now, just to examplify how to use the save() method as an alternative
// to db.phones.add(), we will add yet another phone number
// to an existing contact and then re-save it:
//console.log("Playing a little: adding another phone entry for Adam Tensta...");
//let adam = await db.contacts.orderBy('lastName').last();
/*console.log(`Found contact: ${adam.firstName} ${adam.lastName} (id: ${adam.id})`);
// To add another phone number to adam, the straight forward way would be this:
await db.phones.add({contactId: adam.id, type: "custom", phone: "+46 7777777"});
// But now let's do that same thing by manipulating navigation property instead:
// Load emails and phones navigation properties
await loadNavigationProperties(adam, db);
// Now, just push another phone number to adam.phones navigation property:
adam.phones.push({
contactId: adam.id,
type: 'custom',
phone: '112'
});*/
//}
//db.notes.put({name: 'test'});
//db.notes.clear();
//getAll();
/*class App extends Component<{}, State> {
state = {
newNote: {
id: 1,
name: ""
//text: ""
},
notes: []
};
render() {
return (
<div>
<h2>Hello React TS!</h2>
<FormName
note={this.state.newNote}
onAdd={this.addNote}
onChange={this.handleNoteChange}
/>
<NotesList notes={this.state.notes} onDelete={this.deleteNote} />
</div>
);
}
private addNote = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
db.notes.put({name: this.state.newNote.name});
getAll();
this.setState(previousState => ({
newNote: {
id: previousState.newNote.id + 1,
name: ""
//text: ""
},
notes: [...previousState.notes, previousState.newNote]
}));
//console.log(this.state.notes);
//console.log(this.state.newNote);
};
private handleNoteChange = (event: React.ChangeEvent<HTMLInputElement>) => {
this.setState({
newNote: {
...this.state.newNote,
name: event.target.value
}
});
};
private deleteNote = (noteToDelete: Note) => {
this.setState(previousState => ({
notes: [
...previousState.notes.filter(note => note.id !== noteToDelete.id)
]
}));
};
}*/
//async function getAll() {
/*console.log("Получаем все записи");
db.notes.each(function (note) {
console.log("Найдено: " + note.id + ' Название =' + note.name)
}).catch(function (error) {
console.error(error);
});*/
/*await db.transaction('rw', db.notes, async () => {
// Transaction block
let numberOfOldFriends = await db.notes.where('id').above(0).toArray();
console.log(numberOfOldFriends);
});*/
//}