"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
 * Get SQL table information.
 */
exports.tablesRead = "\n  SELECT\n    o.object_id,\n    o.type,\n    s.name AS [schema],\n    o.name\n  FROM\n    sys.objects o\n    JOIN sys.schemas s ON o.schema_id = s.schema_id\n  where\n    o.type = 'U'\n    AND o.is_ms_shipped = 0\n  ORDER BY\n    s.name,\n    o.name\n";
/**
 * Get SQL column information.
 */
exports.columnsRead = "\n  SELECT\n    c.object_id,\n    c.name,\n    tp.name AS [datatype],\n    c.max_length,\n    c.is_computed,\n    c.precision,\n    c.scale AS [scale],\n    c.collation_name,\n    c.is_nullable,\n    dc.definition,\n    ic.is_identity,\n    ic.seed_value,\n    ic.increment_value,\n    cc.definition AS [formula]\n  FROM\n    sys.columns c\n    JOIN sys.types tp ON c.user_type_id = tp.user_type_id\n    LEFT JOIN sys.computed_columns cc ON c.object_id = cc.object_id AND c.column_id = cc.column_id\n    LEFT JOIN sys.default_constraints dc ON\n      c.default_object_id != 0\n      AND c.object_id = dc.parent_object_id\n      AND c.column_id = dc.parent_column_id\n    LEFT JOIN sys.identity_columns ic ON\n      c.is_identity = 1\n      AND c.object_id = ic.object_id\n      AND c.column_id = ic.column_id\n";
/**
 * Get SQL primary key information.
 */
exports.primaryKeysRead = "\n  SELECT\n    c.object_id,\n    ic.is_descending_key,\n    k.name,\n    c.name AS [column]\n  FROM\n    sys.index_columns ic\n    JOIN sys.columns c ON c.object_id = ic.object_id AND c.column_id = ic.column_id\n    LEFT JOIN sys.key_constraints k ON k.parent_object_id = ic.object_id\n  WHERE\n    ic.is_included_column = 0\n    AND ic.index_id = k.unique_index_id\n    AND k.type = 'PK'\n";
/**
 * Get SQL foreign key information.
 */
exports.foreignKeysRead = "\n  SELECT\n    po.object_id,\n    k.constraint_object_id,\n    fk.is_not_trusted,\n    c.name AS [column],\n    rc.name AS [reference],\n    fk.name,\n    SCHEMA_NAME(ro.schema_id) AS [schema],\n    po.name AS [table],\n    SCHEMA_NAME(ro.schema_id) AS [parent_schema],\n    ro.name AS [parent_table],\n    fk.delete_referential_action,\n    fk.update_referential_action\n  FROM\n    sys.foreign_key_columns k\n    JOIN sys.columns rc ON rc.object_id = k.referenced_object_id AND rc.column_id = k.referenced_column_id\n    JOIN sys.columns c ON c.object_id = k.parent_object_id AND c.column_id = k.parent_column_id\n    JOIN sys.foreign_keys fk ON fk.object_id = k.constraint_object_id\n    JOIN sys.objects ro ON ro.object_id = fk.referenced_object_id\n    JOIN sys.objects po ON po.object_id = fk.parent_object_id\n";
/**
 * Get SQL index information.
 */
exports.indexesRead = "\n  SELECT\n    ic.object_id,\n    ic.index_id,\n    ic.is_descending_key,\n    ic.is_included_column,\n    i.is_unique,\n    i.name,\n    c.name AS [column],\n    SCHEMA_NAME(ro.schema_id) AS [schema],\n    ro.name AS [table]\n  FROM\n    sys.index_columns ic\n    JOIN sys.columns c ON ic.object_id = c.object_id AND ic.column_id = c.column_id\n    JOIN sys.indexes i ON i.object_id = c.object_id AND i.index_id = ic.index_id AND i.is_primary_key = 0 AND i.type = 2\n    INNER JOIN sys.objects ro ON ro.object_id = c.object_id\n  where\n    ro.is_ms_shipped = 0\n    AND ic.is_included_column = 0\n  ORDER BY\n    ro.schema_id,\n    ro.name,\n    c.object_id\n";
/**
 * Get SQL information for user defined types.
 */
exports.typesRead = "\n  SELECT\n    o.object_id,\n    o.type,\n    s.name AS [schema],\n    t.name\n  FROM\n    sys.table_types t\n    INNER JOIN sys.objects o ON o.object_id = t.type_table_object_id\n    JOIN sys.schemas s ON t.schema_id = s.schema_id\n  where\n    o.type = 'TT'\n    AND t.is_user_defined = 1\n  ORDER BY\n    s.name,\n    o.name\n";
/**
 * Get SQL information for procs, triggers, functions, etc.
 */
exports.objectsRead = "\n    SELECT\n        OBJECT_NAME(sm.object_id) AS name ,\n        s.name as [schema],\n        o.type,\n        sm.definition as text\n    FROM sys.sql_modules AS sm JOIN sys.objects AS o ON sm.object_id = o.object_id\n    left join sys.schemas As s on s.schema_id = o.schema_id\n    where type in ('P', 'V', 'TF', 'IF', 'FN', 'TR')\n    ORDER BY name\n";
//# sourceMappingURL=mssql.js.map