title: How to add a custom function/method in sqlalchemy model to do CRUD operations?
body: <p>Below I have a <code>Flask-SQLAlchemy</code> model for the table <code>User</code>.</p>
  
  <pre><code>class User(db.Model):
      __tablename__ = 'user'
  
      user_id = db.Column(db.Integer, primary_key=True)
      name = db.Column(db.String(30), nullable=False)
      created_at = db.Column(db.DateTime, nullable=False, server_default=db.text("CURRENT_TIMESTAMP"))
      updated_at = db.Column(db.DateTime, nullable=False, server_default=db.text("CURRENT_TIMESTAMP"))
  
      def __init__(self):
          #self.name = name
          self.name = None
  
      def add_user(self, name):
          self.name = name
  </code></pre>
  
  <p>Here <code>add_user</code> is a custom method. So if I call the <code>add_user</code> method it should add the name to the <code>User</code> table. </p>
  
  <p>Likewise how do I write custom methods for CRUD operations in that model itself?</p>