Giter Site home page Giter Site logo

Comments (1)

ernests avatar ernests commented on August 17, 2024 4

I got it working.

Here is my approach:

from sqlalchemy import (
    Boolean,
    Column,
    DateTime,
    ForeignKey,
    Integer,
    String,
    Text
)

import sqlalchemy.dialects.postgresql as postgresql
import uuid
from sqlalchemy.sql import func

Base = declarative_base()

class Column(Base):
    _id = Column(postgresql.UUID(as_uuid=True),
        primary_key=True,
        default=uuid.uuid4,
        unique=True
    )
    _created = Column(DateTime,
                      default=func.now())
    _updated = Column(DateTime,
                      default=func.now(),
                      onupdate=func.now())
    _etag = Column(Text)

I had to set type of _id for each column to be "uuid - DOMAIN["tasks"]["schema"]["_id"]["type"] = "uuid"

Implemented UUIDValidator and UUIDEncoder from here - https://docs.python-eve.org/en/latest/tutorials/custom_idfields.html#custom-jsonencoder

and passed it to Eve app:

app = Eve(validator= UUIDValidator,
              json_encoder= UUIDEncoder,
              data=SQL)

One key aspect is that you have to generate _id yourself - uuid.uuid4().hex - and pass it as part of POST. It is not needed when you add straight to db.

Hope it helps someone :)

from eve-sqlalchemy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.