How to use the summer.db.connect.connect_db function in summer

To help you get started, we’ve selected a few summer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gaowhen / summer / tool / fillup.py View on Github external
with open(name) as f:
                print name
                _file = f.read().decode('utf-8')
                if _file:
                    meta = _file.split('---')[0]
                    content = _file.split('---')[1]

                    title = yaml.load(meta)['title']
                    slug = os.path.splitext(ntpath.basename(f.name))[0]
                    create_time = yaml.load(meta)['date']
                    category = (','.join(yaml.load(meta)['categories'])
                                if yaml.load(meta)['categories'] else '')
                    tag = (','.join(yaml.load(meta)['tags'])
                           if yaml.load(meta)['tags'] else '')

                    with closing(connect_db()) as db:
                        db.execute('insert into entries (title, slug, '
                                   'content, create_time, category, tag, '
                                   'status) values '
                                   '(?, ?, ?, ?, ?, ?, "draft")',
                                   (title, slug, content, create_time,
                                    category, tag))
                        db.commit()

        except IOError as exc:
            if exc.errno != errno.EISDIR:
                raise
github gaowhen / summer / tool / fillup.py View on Github external
with open(name) as f:
                print name
                _file = f.read().decode('utf-8')
                if _file:
                    meta = _file.split('---')[0]
                    content = _file.split('---')[1]

                    title = yaml.load(meta)['title']
                    slug = os.path.splitext(ntpath.basename(f.name))[0]
                    create_time = yaml.load(meta)['date']
                    category = (','.join(yaml.load(meta)['categories'])
                                if yaml.load(meta)['categories'] else '')
                    tag = (','.join(yaml.load(meta)['tags'])
                           if yaml.load(meta)['tags'] else '')

                    with closing(connect_db()) as db:
                        db.execute('insert into entries '
                                   '(title, slug, content, '
                                   'create_time, category, tag) '
                                   'values '
                                   '(?, ?, ?, ?, ?, ?)',
                                   [title, slug, content, create_time,
                                    category, tag])
                        db.commit()

        except IOError as exc:
            if exc.errno != errno.EISDIR:
                raise
github gaowhen / summer / tool / initdb.py View on Github external
def init_db():
    app = create_app('product')
    _context = app.app_context()
    _context.push()
    with closing(connect_db()) as db:
        with open('./summer/schema.sql', mode='r') as f:
            db.cursor().executescript(f.read())
            db.commit()
github gaowhen / summer / summer / middleware / db.py View on Github external
def before_request():
    g.db = connect_db()
    g.debug = True