import { entityKind } from "../../entity.js";
import { CockroachColumn, CockroachColumnBuilder } from "./common.js";
class CockroachJsonbBuilder extends CockroachColumnBuilder {
  static [entityKind] = "CockroachJsonbBuilder";
  constructor(name) {
    super(name, "json", "CockroachJsonb");
  }
  /** @internal */
  build(table) {
    return new CockroachJsonb(
      table,
      this.config
    );
  }
}
class CockroachJsonb extends CockroachColumn {
  static [entityKind] = "CockroachJsonb";
  constructor(table, config) {
    super(table, config);
  }
  getSQLType() {
    return "jsonb";
  }
  mapToDriverValue(value) {
    return JSON.stringify(value);
  }
  mapFromDriverValue(value) {
    if (typeof value === "string") {
      try {
        return JSON.parse(value);
      } catch {
        return value;
      }
    }
    return value;
  }
}
function jsonb(name) {
  return new CockroachJsonbBuilder(name ?? "");
}
export {
  CockroachJsonb,
  CockroachJsonbBuilder,
  jsonb
};
//# sourceMappingURL=jsonb.js.map