MCPcopy
hub / github.com/mayneyao/eidos / createDataView

Method createDataView

packages/core/sdk/sql-data-view.ts:175–211  ·  view source on GitHub ↗
(
    id: string,
    createViewSql: string,
    isTemp: boolean = false
  )

Source from the content-addressed store, hash-verified

173 }
174
175 async createDataView(
176 id: string,
177 createViewSql: string,
178 isTemp: boolean = false
179 ) {
180 const viewName = `vw_${id}`
181 // delete temp view
182 await this.dataSpace.db.prepare(`DROP VIEW IF EXISTS ${viewName};`).run()
183 await this.dataSpace.view.deleteByTableId(id)
184 // Clean up existing column metadata for this view
185 await this.dataSpace.column.deleteByRawTableName(viewName)
186 await this.dataSpace.db.prepare("BEGIN TRANSACTION;").run()
187
188 try {
189 await this.dataSpace.db
190 .prepare(
191 `CREATE ${isTemp ? "TEMPORARY" : ""} VIEW IF NOT EXISTS ${viewName} AS \n ${createViewSql};`
192 )
193 .run()
194 await this.dataSpace.view.add({
195 id: shortenId(uuidv7()),
196 name: `New View`,
197 type: ViewTypeEnum.Grid,
198 table_id: id,
199 query: `select * from ${viewName}`,
200 })
201 // Parse column types from SQL comments and create column metadata
202 await this.createColumnMetadataFromComments(viewName, createViewSql)
203 } catch (error) {
204 await this.dataSpace.db.prepare("ROLLBACK;").run()
205 console.error("Error in createDataView transaction:", error)
206 throw error
207 } finally {
208 await this.dataSpace.db.prepare("COMMIT;").run()
209 }
210 return true
211 }
212
213 /**
214 * Create column metadata from SQL comments

Callers 4

createMethod · 0.80
createDataViewFunction · 0.80
useDataViewFunction · 0.80

Calls 8

shortenIdFunction · 0.90
deleteByTableIdMethod · 0.80
deleteByRawTableNameMethod · 0.80
runMethod · 0.65
prepareMethod · 0.65
addMethod · 0.65
errorMethod · 0.65

Tested by

no test coverage detected