switch to peewee orm
parent
b2468bcb21
commit
0dd1ac0a2b
@ -1,31 +1,45 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from sqlalchemy.sql import func
|
import peewee as pw
|
||||||
|
from peewee import PostgresqlDatabase, SQL, ForeignKeyField
|
||||||
|
|
||||||
from xmrbackers.factory import db
|
|
||||||
from xmrbackers import config
|
from xmrbackers import config
|
||||||
|
|
||||||
|
|
||||||
|
db = PostgresqlDatabase(
|
||||||
|
config.DB_NAME,
|
||||||
|
user=config.DB_USER,
|
||||||
|
password=config.DB_PASS,
|
||||||
|
host=config.DB_HOST,
|
||||||
|
)
|
||||||
|
|
||||||
def rand_id():
|
def rand_id():
|
||||||
return uuid4().hex
|
return uuid4().hex
|
||||||
|
|
||||||
class Creator(db.Model):
|
|
||||||
__tablename__ = 'creators'
|
|
||||||
|
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
class Creator(pw.Model):
|
||||||
# id = db.Column(db.String(80), primary_key=True, default=rand_id) # hex based id
|
id = pw.AutoField()
|
||||||
register_date = db.Column(db.DateTime, server_default=func.now())
|
register_date = pw.DateTimeField(default=datetime.now)
|
||||||
last_login_date = db.Column(db.DateTime, nullable=True)
|
last_login_date = pw.DateTimeField(default=datetime.now)
|
||||||
wallet_address = db.Column(db.String(150))
|
wallet_address = pw.CharField()
|
||||||
password = db.Column(db.String(150))
|
username = pw.CharField(unique=True)
|
||||||
email = db.Column(db.String(150))
|
email = pw.CharField(unique=True)
|
||||||
handle = db.Column(db.String(150))
|
password = pw.CharField(unique=True)
|
||||||
|
bio = pw.CharField()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
database = db
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return self.id
|
|
||||||
|
|
||||||
class Backer(db.Model):
|
class Backer(pw.Model):
|
||||||
__tablename__ = 'backers'
|
id = pw.AutoField()
|
||||||
|
register_date = pw.DateTimeField(default=datetime.now)
|
||||||
|
last_login_date = pw.DateTimeField(default=datetime.now)
|
||||||
|
wallet_address = pw.CharField()
|
||||||
|
username = pw.CharField(unique=True)
|
||||||
|
email = pw.CharField(unique=True)
|
||||||
|
password = pw.CharField(unique=True)
|
||||||
|
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
class Meta:
|
||||||
|
database = db
|
||||||
|
Loading…
Reference in New Issue