Search
 
SCRIPT & CODE EXAMPLE
 

SQL

sqlalchemy sequence postgresql

#!/usr/bin/env python

from sqlalchemy import create_engine, Column, Integer, String, Sequence
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()
USER_ID_SEQ = Sequence('user_id_seq')  # define sequence explicitly
class User(Base):
    __tablename__ = 'users'
    # use sequence in column definition, and pass .next_value() as server_default
    id = Column(Integer, USER_ID_SEQ, primary_key=True, server_default=USER_ID_SEQ.next_value())
    name = Column(String(50))
    fullname = Column(String(50))
    password = Column(String(12))

    def __repr__(self):
        return "<User(name='%s', fullname='%s', password='%s')>" % (
                                self.name, self.fullname, self.password)

db_url = 'postgresql://localhost/serial'
engine = create_engine(db_url, echo=True)
Base.metadata.create_all(engine)
Comment

PREVIOUS NEXT
Code Example
Sql :: importing multiple xml files in azure sql database 
Sql :: python sqlalchemy get the last row id 
Sql :: query to check temp space in oracle 
Sql :: mysql readable output 
Sql :: sql joins explained 
Sql :: sql trigger 
Sql :: delete duplicate sql 
Sql :: correlated subquery 
Sql :: oracle find constraints referencing a table 
Sql :: sql server interview questions 
Sql :: in condition in sql 
Sql :: sql select statement 
Sql :: bigquery javascript 
Sql :: why do we need data structure in sql 
Sql :: xamarin sql lite create table if not exist 
Sql :: luu ckeditor vao mysql 
Csharp :: unity reset scene 
Csharp :: c# random float between two numbers 
Csharp :: aspx textarea 
Csharp :: how to set serial number in gridview in asp net 
Csharp :: Check object is in layermask unity 
Csharp :: Character Controller unity isGrounded is false 
Csharp :: unity createassetmenu 
Csharp :: how get url in laravel 
Csharp :: c# print to console 
Csharp :: unity change text color 
Csharp :: c# random boolean 
Csharp :: is letter c# 
Csharp :: C# cycle through directory 
Csharp :: how to edit Camera.size property unity 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =