• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

typeorm / typeorm / 14796576772

02 May 2025 01:52PM UTC coverage: 45.367% (-30.9%) from 76.309%
14796576772

Pull #11434

github

web-flow
Merge ec4ce2d00 into fadad1a74
Pull Request #11434: feat: release PR releases using pkg.pr.new

5216 of 12761 branches covered (40.87%)

Branch coverage included in aggregate %.

11439 of 23951 relevant lines covered (47.76%)

15712.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

63.16
/src/schema-builder/view/View.ts
1
import {
2
    DataSource,
3
    Driver,
4
    EntityMetadata,
5
    SelectQueryBuilder,
6
    TableIndex,
7
} from "../.."
8
import { ViewOptions } from "../options/ViewOptions"
9

10
/**
11
 * View in the database represented in this class.
12
 */
13
export class View {
4✔
14
    readonly "@instanceof" = Symbol.for("View")
68✔
15

16
    // -------------------------------------------------------------------------
17
    // Public Properties
18
    // -------------------------------------------------------------------------
19

20
    /**
21
     * Database name that this view resides in if it applies.
22
     */
23
    database?: string
24

25
    /**
26
     * Schema name that this view resides in if it applies.
27
     */
28
    schema?: string
29

30
    /**
31
     * View name
32
     */
33
    name: string
34

35
    /**
36
     * Indicates if view is materialized.
37
     */
38
    materialized: boolean
39

40
    /**
41
     * View Indices
42
     */
43
    indices: TableIndex[]
44

45
    /**
46
     * View definition.
47
     */
48
    expression: string | ((connection: DataSource) => SelectQueryBuilder<any>)
49

50
    // -------------------------------------------------------------------------
51
    // Constructor
52
    // -------------------------------------------------------------------------
53

54
    constructor(options?: ViewOptions) {
55
        this.indices = []
68✔
56
        if (options) {
68✔
57
            this.database = options.database
50✔
58
            this.schema = options.schema
50✔
59
            this.name = options.name
50✔
60
            this.expression = options.expression
50✔
61
            this.materialized = !!options.materialized
50✔
62
        }
63
    }
64

65
    // -------------------------------------------------------------------------
66
    // Public Methods
67
    // -------------------------------------------------------------------------
68

69
    /**
70
     * Clones this table to a new table with all properties cloned.
71
     */
72
    clone(): View {
73
        return new View(<ViewOptions>{
×
74
            database: this.database,
75
            schema: this.schema,
76
            name: this.name,
77
            expression: this.expression,
78
            materialized: this.materialized,
79
        })
80
    }
81

82
    /**
83
     * Add index
84
     */
85
    addIndex(index: TableIndex): void {
86
        this.indices.push(index)
×
87
    }
88

89
    /**
90
     * Remove index
91
     */
92
    removeIndex(viewIndex: TableIndex): void {
93
        const index = this.indices.find(
×
94
            (index) => index.name === viewIndex.name,
×
95
        )
96
        if (index) {
×
97
            this.indices.splice(this.indices.indexOf(index), 1)
×
98
        }
99
    }
100

101
    // -------------------------------------------------------------------------
102
    // Static Methods
103
    // -------------------------------------------------------------------------
104

105
    /**
106
     * Creates view from a given entity metadata.
107
     */
108
    static create(entityMetadata: EntityMetadata, driver: Driver): View {
109
        const options: ViewOptions = {
46✔
110
            database: entityMetadata.database,
111
            schema: entityMetadata.schema,
112
            name: driver.buildTableName(
113
                entityMetadata.tableName,
114
                entityMetadata.schema,
115
                entityMetadata.database,
116
            ),
117
            expression: entityMetadata.expression!,
118
            materialized: entityMetadata.tableMetadataArgs.materialized,
119
        }
120

121
        return new View(options)
46✔
122
    }
123
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc