package dev.kkorolyov.sqlob.construct;

/**
 * A representation of a SQL datatype.
 * Composed of a typecode and String representation of the type.
 */
public enum SqlType {
	/** The 'boolean' equivalent. */
	BOOLEAN("BOOLEAN", java.sql.Types.BIT, Boolean.class),	// Boolean is a bit in postgres
	
	/** The 'short' equivalent. */
	SMALLINT("SMALLINT", java.sql.Types.SMALLINT, Short.class),
	/** The 'int' equivalent. */
	INTEGER("INTEGER", java.sql.Types.INTEGER, Integer.class),
	/** The 'long' equivalent. */
	BIGINT("BIGINT", java.sql.Types.BIGINT, Long.class),
	/** The 'float' equivalent. */
	REAL("REAL", java.sql.Types.REAL, Float.class),
	/** The 'double' equivalent. */
	DOUBLE("DOUBLE PRECISION", java.sql.Types.DOUBLE, Double.class),
	
	/** The 'char' equivalent. */
	CHAR("CHAR", java.sql.Types.CHAR, Character.class),
	/** The 'String' equivalent. */
	VARCHAR("VARCHAR", java.sql.Types.VARCHAR, String.class);
	
	private String typeName;
	private int typeCode;
	private Class<? extends Object> typeClass;
	
	private SqlType(String typeName, int typeCode, Class<? extends Object> typeClass) {
		this.typeName = typeName;
		this.typeCode = typeCode;
		this.typeClass = typeClass;
	}
	
	/**
	 * Returns the {@code SqlType} for a specified type code.
	 * @param typeCode type code from {@link java.sql.Types}
	 * @return appropriate {@code SqlType} or {@code null} if not found
	 */
	public static SqlType get(int typeCode) {
		for (SqlType type : SqlType.values()) {
			if (type.getTypeCode() == typeCode)
				return type;
		}
		return null;
	}
	
	/** @return {@code String} representation of the type */
	public String getTypeName() {
		return typeName;
	}
	/** @return respective type code from {@link java.sql.Types} */
	public int getTypeCode() {
		return typeCode;
	}
	/** @return respective Java class type */
	public Class<? extends Object> getTypeClass() {
		return typeClass;
	}
}

@@ -33,16 +33,165 @@
 truct;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.List;%0A%0Aimport dev.kkorolyov.sqlob.connection.DatabaseConnection.DatabaseType;%0A%0A
 /**%0A * A
@@ -1696,24 +1696,565 @@
  null;%0A%09%7D%0A%09%0A
+%09/**%0A%09 * Returns all %7B@code SqlTypes%7D available to a specific %7B@code DatabaseType%7D.%0A%09 * @param dbType database type to filter by%0A%09 * @return all %7B@code SqlTypes%7D available to %7B@code dbType%7D%0A%09 */%0A%09public static SqlType%5B%5D values(DatabaseType dbType) %7B%0A%09%09switch (dbType) %7B%0A%09%09case POSTGRESQL:%0A%09%09%09return values();%0A%09%09case SQLITE:%0A%09%09%09List%3CSqlType%3E values = new ArrayList%3C%3E(Arrays.asList(values()));%0A%09%09%09values.remove(SqlType.BOOLEAN);%09// SQLite boolean is an integer%0A%09%09%09%0A%09%09%09return values.toArray(new SqlType%5Bvalues.size()%5D);%0A%09%09%7D%0A%09%09return null;%0A%09%7D%0A%09%0A
 %09/** @return

Add DatabaseType-filtered SqlType#values()