/better-metadata

Primary LanguageKotlinApache License 2.0Apache-2.0

better-metadata

Provides wrapper classes and enums for Java's DatabaseMetadata class. Does not provide any additional error handling, so if a particular call to DatabaseMetadata throws an exception, the equivalent call here will too. Additionally, some jdbc drivers are not consistent in the data they return. As an example, the PostgreSQL driver will return tables under its 'pg_toast' schema, but won't return the columns for those tables.

Dependencies

Requires the Kotlin stdlib

Usage

Java

// configure your url, username, password...
Connection conn = DriverManager.getConnection(url, user, password);
DatabaseMetaData metadata = conn.getMetaData();

// to use without default catalog and schema filters
Database wrapper = new Database(metadata);

// or set defaults to work with a specific catalog/schema,
// replacing "catalogName" and "schemaName" with values appropriate to your database
Database wrapper = new Database(metadata,"catalogName", "schemaName");

// use wrapper as needed

// Database does no connection management, so you'll need to close it
// when finished
conn.close();

Kotlin

// configure your url, username, password...
val conn = DriverManager.getConnection(url, username, password)
val metadata = conn.metaData
// to use without default catalog and schema filters
val wrapper = new Database(metadata)

// or set defaults to work with a specific catalog/schema,
// replacing "catalogName" and "schemaName" with values appropriate to your database
val wrapper = new Database(metadata,"catalogName", "schemaName")
        
// use wrapper as needed

// Database does no connection management, so you'll need to close it
// when finished
conn.close()

Options

There is a type alias that allow nullable ints for columns such as DECIMAL_DIGITS where the DatabaseMetaData documentation indicates that nulls are returned. See the TypeDefinitions file for details.

Documentation

Java style

Kotlin style