generateCreateTableScript method

String generateCreateTableScript(
  1. String? className
)

Implementation

String generateCreateTableScript(String? className) {
  // 모델 타입의 인스턴스를 생성하여 속성을 가져옵니다.
  className ??= type.toString().replaceAll('ExModelType.', "creta_");
  String fields = '';
  toMap().forEach(
    (key, value) {
      if (value is String) {
        if (key == 'mid') {
          fields += '$key TEXT PRIMARY KEY,';
        } else {
          fields += '$key TEXT,';
        }
      } else if (value is double) {
        fields += '$key NUMERIC,';
      } else if (value is int) {
        fields += '$key INTEGER,';
      } else if (value is DateTime) {
        fields += '$key TIMESTAMP,';
      } else if (value is Timestamp) {
        fields += '$key TIMESTAMP,';
      } else if (value is bool) {
        fields += '$key BOOLEAN,';
      } else if (value is List) {
        if (value.isNotEmpty) {
          if (value.first is String) {
            fields += '$key TEXT[],';
          } else if (value.first is double) {
            fields += '$key NUMERIC[],';
          } else if (value.first is int) {
            fields += '$key INTEGER[],';
          } else if (value.first is bool) {
            fields += '$key BOOLEAN[],';
          } else {
            fields += '$key TEXT[],';
          } // Add more types as needed
        } else {
          fields += '$key TEXT[],';
        }
      } else {
        fields += '$key TEXT,';
      }
    },
  );
  if (fields.endsWith(',')) {
    fields = fields.substring(0, fields.length - 1);
  }

  return 'CREATE TABLE $className ($fields);';
}