ayush2917 commited on
Commit
06cd6c3
·
verified ·
1 Parent(s): 156abc2

Update database.py

Browse files
Files changed (1) hide show
  1. database.py +6 -1
database.py CHANGED
@@ -3,7 +3,7 @@ from flask import g
3
 
4
  def init_db(app):
5
  with app.app_context():
6
- db = get_db()
7
  db.execute('''
8
  CREATE TABLE IF NOT EXISTS news (
9
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -24,6 +24,11 @@ def get_db(app):
24
  g.db.row_factory = sqlite3.Row
25
  return g.db
26
 
 
 
 
 
 
27
  def cache_news(app, articles):
28
  db = get_db(app)
29
  for article in articles:
 
3
 
4
  def init_db(app):
5
  with app.app_context():
6
+ db = get_db(app)
7
  db.execute('''
8
  CREATE TABLE IF NOT EXISTS news (
9
  id INTEGER PRIMARY KEY AUTOINCREMENT,
 
24
  g.db.row_factory = sqlite3.Row
25
  return g.db
26
 
27
+ def close_db(e=None):
28
+ db = g.pop('db', None)
29
+ if db is not None:
30
+ db.close()
31
+
32
  def cache_news(app, articles):
33
  db = get_db(app)
34
  for article in articles: