Skip to content

Instantly share code, notes, and snippets.

@silviud
Forked from lly365/pg_uuid.py
Created August 17, 2022 14:16
Show Gist options
  • Save silviud/cfc4d1b81804b77f3722dfede891d3e3 to your computer and use it in GitHub Desktop.
Save silviud/cfc4d1b81804b77f3722dfede891d3e3 to your computer and use it in GitHub Desktop.
Flask-SQLAlchemy UUID
# -*- coding: utf-8 -*-
"""
pg_uuid
~~~~~~~~~~~~~~~~
<NO DESCRIPTION>.
:copyright: (c) 2018 by WRDLL <4ever@wrdll.com>
"""
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy import text as sa_text
SECRET_KEY = 'aa'
SQLALCHEMY_DATABASE_URI = 'postgresql://ling:@localhost/test'
SQLALCHEMY_ECHO = True
app = Flask(__name__)
app.config.from_object(__name__)
db = SQLAlchemy(app)
class UuidTest(db.Model):
__tablename__ = 'uuid_test'
id = db.Column(UUID(as_uuid=True), primary_key=True, server_default=sa_text("uuid_generate_v4()"))
name = db.Column(db.String(10))
if __name__ == '__main__':
app.run(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment