title: Persisting JSON with sequelize-typescript
body: <p>I want to store a simple JSON-Array in a MariaDB using <code>sequelize-typescript</code>. Here's a basic Model that would work in PostgreSQL, SQLite and MySQL.</p>
  <pre><code>class MyModel extends Model&lt;MyModel&gt; {
    @Column({
      type: DataType.JSON
    })
    options!: string[]
  }
  </code></pre>
  <p>To get the same behaviour with MariaDB I tried four things:</p>
  <h2>1. Use <code>@AfterFind</code> or some other hook.</h2>
  <p><strong>Problem:</strong> As stated in this <a href="https://github.com/sequelize/sequelize/issues/4627" rel="noreferrer">issue in the github repo</a>, there's a known bug that hooks will not fire on included models, so no chance</p>
  <h2>2. Implement an own custom JSON Data-Type (preferred solution)</h2>
  <p><strong>Problem:</strong> Even copying the <a href="https://sequelize.org/v5/manual/data-types.html#extending-datatypes" rel="noreferrer">example in the sequelize-docs</a> throws various typescript compiler issues and even If I use <code>any</code> types and trick the TS-compiler I don't know how to tell my other models that there is a new DataType.</p>
  <h2>3. Use a getter/setter for the same property</h2>
  <pre><code>class MyModel extends Model&lt;MyModel&gt; {
    @Column({
      type: DataType.STRING
    })
    get options(): string[] {
      return JSON.parse(this.getDataValue('options'))
    }
  
    set options(value: string[]) {
      this.setDataValue('options', JSON.stringify(value))
    }
  }
  </code></pre>
  <p>This throws compiler errors for the <code>getDataValue</code>and <code>setDataValue</code> methods:</p>
  <pre><code>Argument of type 'string' is not assignable to parameter of type 'this[&quot;options&quot;]'
  Type 'string' is not assignable to type 'string[]'
  </code></pre>
  <h2>4. Use a getter/setter for a private property</h2>
  <p>What would work is to just store the Array as a string in the DB and use a getter/setter to access &amp; parse this property.</p>
  <pre><code>class MyModel extends Model&lt;MyModel&gt; {
    @Column
    _options!: string;
  
    get options(): string[] {
      return JSON.parse(this._options)
    }
  
    set options(value: string[]) {
      this._options = JSON.stringify(value)
    }
  }
  </code></pre>
  <p>As I said, that works, but I'd rather like to have something more generic that works faster for a larger number of fields, like a custom datatype.</p>
  <p>So my question is:<br />
  <strong>Is there a convenient, short, easy, dynamic and reusable way to store JSON in a MariaDB?</strong></p>