pydbantic icon indicating copy to clipboard operation
pydbantic copied to clipboard

Find a way to generate automatically PrimaryKeys instead of coding them

Open sorasful opened this issue 4 years ago • 1 comments

IMHO, It would be essential that PrimaryKey() generates automatically an id, it could even depend on the type we are passing, for example :

class Employee(DataBaseModel):
    id: str = PrimaryKey()  # could use uuid.uuid4()
    id: int = PrimaryKey()  # could use random.randint(0, 9e99) (just an example, would need something better)

A possibility would also to set PrimaryKey as Optional, what do you think ?

sorasful avatar Nov 15 '21 22:11 sorasful

I probably answered this question in #5 , where you would need to use PrimaryKey(default=) passing in an argument-less method that will be used to generate almost any type of data at instantiation.

codemation avatar Nov 16 '21 08:11 codemation