Electron100 / butane

An ORM for Rust with a focus on simplicity and on writing Rust, not SQL
Apache License 2.0
83 stars 11 forks source link

Remove ObjectState (breaking change) #151

Closed Electron100 closed 8 months ago

Electron100 commented 8 months ago

ObjectState never really took on as large a role I had originally envisioned, while at the same time being quite clunky -- an extra field automatically injected into all model types. It had a single member saved, which tracks whether the object had previously been saved or not. Most of the time this doesn't matter though, especially since #117 changed save to upsert. I believe the only remaining case where it does matter is for automatic creation of primary keys, and those were operating in a semantic grey area where creating an unitialized primary key required setting it to -1 or similar.

This change does the following

  1. Removes ObjectState and the auto-created state member for each model
  2. Adds a new AutoPk<T> type which is used as the type for fields which represent automatic primary keys. This tracks whether the primary key has already been generated or not.