當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript serverUtil.exec函數代碼示例

本文整理匯總了TypeScript中utils/server/serverUtil.exec函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript exec函數的具體用法?TypeScript exec怎麽用?TypeScript exec使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了exec函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: dataExport

async function dataExport() {
    await db.connect()

    const tmpFile = "/tmp/owid_chartdata.sql"

    const variablesToExportQuery = `
        SELECT DISTINCT cd.variableId FROM chart_dimensions cd
        WHERE NOT EXISTS (select * from tags t join chart_tags ct on ct.tagId = t.id where ct.chartId=cd.chartId and t.name='Private')
    `

    const variableIds = (await db.query(variablesToExportQuery)).map((row: any) => row.variableId)

    console.log(`Exporting data for ${variableIds.length} variables to ${tmpFile}`)

    await exec(`rm -f ${tmpFile}`)

    let count = 0
    for (const chunk of _.chunk(variableIds, 100)) {
        await exec(`mysqldump --no-create-info ${DB_NAME} data_values --where="variableId IN (${chunk.join(",")})" >> ${tmpFile}`)

        count += chunk.length
        console.log(count)
    }

    await db.end()
}
開發者ID:OurWorldInData,項目名稱:owid-grapher,代碼行數:26,代碼來源:exportChartData.ts

示例2: dataExport

async function dataExport() {
    await db.connect()

    console.log(`Exporting database structure and metadata to /tmp/owid_metadata.sql...`)

    // Dump all tables including schema but exclude the rows of data_values
    await exec(`mysqldump ${DB_NAME} --ignore-table=${DB_NAME}.sessions --ignore-table=${DB_NAME}.user_invitations --ignore-table=${DB_NAME}.data_values -r /tmp/owid_metadata.sql`)
    await exec(`mysqldump --no-data ${DB_NAME} sessions user_invitations data_values >> /tmp/owid_metadata.sql`)

    // Strip passwords
    await exec(`sed -i -e "s/bcrypt[^']*//g" /tmp/owid_metadata.sql`)

    // Add default admin user
    await fs.appendFile("/tmp/owid_metadata.sql", "INSERT INTO users (`password`, `isSuperuser`, `email`, `fullName`, `createdAt`, `updatedAt`, `isActive`) VALUES ('bcrypt$$2b$12$EXfM7cWsjlNchpinv.j6KuOwK92hihg5r3fNssty8tLCUpOubST9u', 1, 'admin@example.com', 'Admin User', '2016-01-01 00:00:00', '2016-01-01 00:00:00', 1);\n")

    await db.end()
}
開發者ID:OurWorldInData,項目名稱:owid-grapher,代碼行數:17,代碼來源:exportMetadata.ts

示例3: dataExport

async function dataExport() {
    await db.connect()

    const tmpFilename: string = `/tmp/owid_chartdata_${namespaces.join(",")}.sql`

    // This will also retrieve variables that are not in the specified namespace
    // but are used in a chart that has at least one variable from the specified
    // namespace.
    // This is necessary in order to reproduce the charts from the live grapher
    // accurately.
    const rows = await db.query(`
        SELECT DISTINCT chart_dimensions.variableId
        FROM chart_dimensions
        WHERE chart_dimensions.chartId IN (
            SELECT DISTINCT charts.id
            FROM charts
            JOIN chart_dimensions ON chart_dimensions.chartId = charts.id
            JOIN variables ON variables.id = chart_dimensions.variableId
            JOIN datasets ON datasets.id = variables.datasetId
            WHERE datasets.namespace IN (?)
        )
    `, [namespaces])

    const variableIds = rows.map((row: any) => row.variableId)

    console.log(`Exporting data for ${variableIds.length} variables to ${tmpFilename}`)

    await exec(`rm -f ${tmpFilename}`)

    let count = 0
    for (const chunk of _.chunk(variableIds, 100)) {
        await exec(`mysqldump --no-create-info ${DB_NAME} data_values --where="variableId IN (${chunk.join(",")})" >> ${tmpFilename}`)

        count += chunk.length
        console.log(count)
    }

    await db.end()
}
開發者ID:OurWorldInData,項目名稱:owid-grapher,代碼行數:39,代碼來源:exportChartDataNamespace.ts

示例4: it

 it('should reject when there is a non-zero exit code', () => {
     expect(exec(`echo "does not work"; exit 1`)).rejects.toBeInstanceOf(Error)
 })
開發者ID:OurWorldInData,項目名稱:owid-grapher,代碼行數:3,代碼來源:serverUtil.test.ts

示例5: execFormatted

async function execFormatted(cmd: string, args: string[]) {
    const formatCmd = util.format(cmd, ...args.map(s => quote([s])))
    console.log(formatCmd)
    await exec(formatCmd)
}
開發者ID:OurWorldInData,項目名稱:owid-grapher,代碼行數:5,代碼來源:gitDataExport.ts


注:本文中的utils/server/serverUtil.exec函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。