Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- connect() {
- this.db = new Sequelize("sqlite:"+this.fp);
- return this.db.authenticate()
- .then(()=>console.log('Connected to:', this.fp))
- .catch(err=>console.log('Error connecting to database:', err))
- .then(()=>this.Card = this.db.define('card', { name: Sequelize.STRING }))
- .then(()=>this.Card.sync({ force: false }))
- .then(()=>this.Card.findAll())
- .then((cards) =>
- cards.map(c => c.get('name')).filter(c => (c && c != `''s`))
- .forEach(c => this.createCardTable(c))
- ).catch(err=>console.log('Error creating card table:', err))
- .then(()=>console.log('this.cards:', this.cards))
- .then(()=>this.db);
- }
- .then((cards) =>
- cards.map(c => c.get('name')).filter(c => (c && c != `''s`))
- .forEach(c => this.createCardTable(c))
- )
- createCardTable(card) {
- const newTable = this.db.define(card,
- {entry: Sequelize.STRING, content: Sequelize.STRING},
- {freezeTableName: true});
- return newTable.sync({ force: false })
- .then(()=>this.cards[card] = newTable)
- .then(()=>console.log('created table:', card))
- .catch(err=>console.log('Error creating table:', err));
- }
Add Comment
Please, Sign In to add comment