Guest User

Untitled

a guest
Jun 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. connect() {
  2. this.db = new Sequelize("sqlite:"+this.fp);
  3. return this.db.authenticate()
  4. .then(()=>console.log('Connected to:', this.fp))
  5. .catch(err=>console.log('Error connecting to database:', err))
  6. .then(()=>this.Card = this.db.define('card', { name: Sequelize.STRING }))
  7. .then(()=>this.Card.sync({ force: false }))
  8. .then(()=>this.Card.findAll())
  9. .then((cards) =>
  10. cards.map(c => c.get('name')).filter(c => (c && c != `''s`))
  11. .forEach(c => this.createCardTable(c))
  12. ).catch(err=>console.log('Error creating card table:', err))
  13. .then(()=>console.log('this.cards:', this.cards))
  14. .then(()=>this.db);
  15. }
  16.  
  17. .then((cards) =>
  18. cards.map(c => c.get('name')).filter(c => (c && c != `''s`))
  19. .forEach(c => this.createCardTable(c))
  20. )
  21.  
  22. createCardTable(card) {
  23. const newTable = this.db.define(card,
  24. {entry: Sequelize.STRING, content: Sequelize.STRING},
  25. {freezeTableName: true});
  26. return newTable.sync({ force: false })
  27. .then(()=>this.cards[card] = newTable)
  28. .then(()=>console.log('created table:', card))
  29. .catch(err=>console.log('Error creating table:', err));
  30. }
Add Comment
Please, Sign In to add comment