https://serverless-stack.com/ logo
#help
Title
# help
e

Ernie Francis

03/05/2022, 6:27 PM
When i construct the sst.Table instance. is there a way to mark a property as auto-increment? or no such animal in this case?
t

thdxr

03/05/2022, 6:28 PM
Auto incrementing is generally not a thing in distributed databases. There is a really sophisticated way of creating an auto increment scheme in dynamo but not recommended
e

Ernie Francis

03/05/2022, 6:30 PM
ah, im trying to build a chat group table and sort the messages based on order. unless when i call dynamoDB.put() it inserts the item at the bottom?
r

Ross Coundon

03/05/2022, 6:33 PM
You can use a ksuid or ulid as the ID which are unique but date sortable. If you use the SenseDeep OneTable library it has this built-in
e

Ernie Francis

03/05/2022, 6:58 PM
then again, i could just add a datetime property and use that as a sort key.
d

Devin

03/05/2022, 7:01 PM
Can you do transactWrite and then just do an pk / sk of the chat id and increment messages. Then use the SK as a gsi on sort order?
e

Ernie Francis

03/05/2022, 7:07 PM
@Devin imma write that one down 🙂
r

Ross Coundon

03/05/2022, 7:07 PM
@Ernie Francis the trouble with a datetime as a sort key is that, if you ever needed to uniquely identify a record by PK and SK, it's difficult to do so
e

Ernie Francis

03/05/2022, 7:07 PM
@Ross Gerbasi i do use UUIDv4 to generate unique PK's, even with that i would run into issues?
r

Ross Coundon

03/05/2022, 9:26 PM
Assume you meant me. Not issues, but UUIDs aren't datetime sortable whereas ULIDs and KSUIDs are
t

thdxr

03/05/2022, 9:39 PM
Second the recommendation for ulid or ksuid, it's definitely what you want for a situation like this
r

Ross Gerbasi

03/05/2022, 9:41 PM
Ah another summoning of the wrong Ross haha. However I also recommend ulid, haven't looked back.
t

thdxr

03/05/2022, 9:44 PM
we're going to need one of you to change your name thanks
r

Ross Gerbasi

03/05/2022, 9:45 PM
Or merge...
r

Ross Coundon

03/05/2022, 10:49 PM
OK, fair enough, let me get my deed poll docs done this week
Curious what a merge would be like, I've never looked as good in hats as Ross Gerbasi