コード例 #1
0
ファイル: app.py プロジェクト: wishwisdom/mongodb
def index():
    from database import db, conn
    cols = db.get_collection('disaster')

    # test = {'create_date': '2019-10-09', 'location_id': 136, 'message':'[서울] 경기 지역에서 돼지열병 발원 의심되오니 해당 지역 이동에 유념하시기 바랍니다.'}
    #
    # cols.insert(test)

    resp = dumps([x for x in cols.find()], ensure_ascii=False)
    print(resp)
    conn.close()

    return resp
コード例 #2
0
cursor = conn.cursor()

cursor.execute("""CREATE TABLE users (
    id serial PRIMARY KEY,
    username VARCHAR (50) UNIQUE NOT NULL,
    email VARCHAR (50) UNIQUE NOT NULL,
    password VARCHAR (50) NOT NULL
    );
    
CREATE TABLE book (
    id serial PRIMARY KEY,
    title VARCHAR,
    author VARCHAR,
    year INTEGER NOT NULL,
    isbn VARCHAR UNIQUE NOT NULL
    );
    
CREATE TABLE review (
    id serial PRIMARY KEY,
    book_id INTEGER REFERENCES book(id),
    user_id INTEGER REFERENCES users(id),
    published TIMESTAMP,
    content VARCHAR (500) NOT NULL
    );
    """)

conn.commit()
cursor.close()
conn.close()