Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
mgz0227 committed Nov 20, 2024
1 parent eff62f9 commit 6caf4aa
Show file tree
Hide file tree
Showing 44 changed files with 5,760 additions and 0 deletions.
Binary file removed entry/cronetlib/cronet_api.jar
Binary file not shown.
Binary file removed entry/cronetlib/cronet_impl_common_java.jar
Binary file not shown.
Binary file removed entry/cronetlib/cronet_impl_native_java.jar
Binary file not shown.
Binary file removed entry/cronetlib/cronet_impl_platform_java.jar
Binary file not shown.
Binary file removed entry/cronetlib/cronet_shared_java.jar
Binary file not shown.
2,380 changes: 2,380 additions & 0 deletions entry/src/main/ets/database/AppDatabase/index.ets

Large diffs are not rendered by default.

69 changes: 69 additions & 0 deletions entry/src/main/ets/database/AppDatabaseUtil.ets
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { FieldsType } from './types/AppDatabaseType'
import { ColumnInfo, ColumnValue, ColumnType } from './types/ColumnInfo'
import AppDatabase from './AppDatabase'
import DbUtil from '../common/utils/DbUtil'

class AppDatabaseUtil {
getCreateSql(tableName: string) {
const entities = AppDatabase.database.entities
const tableInfo = entities.find(item => item.tableName === tableName)
return tableInfo?.createSql.replace('${TABLE_NAME}', tableName)
}

getFields(tableName: string): FieldsType[] | undefined {
const entities = AppDatabase.database.entities
const tableInfo = entities.find(item => item.tableName === tableName)
return tableInfo?.fields
}

// 检测表中的字段是否缺失,若是缺失则新增
async existsTable(tableName: string) {
try {
const rowNames = await DbUtil.queryRowNames(tableName);
const fields = this.getFields(tableName)
if (!fields?.length) return
for (let index = 0; index < fields.length; index++) {
const element = fields[index];
if (!rowNames.includes(element.columnName)) {
console.info(`TagInfo 数据表【${tableName}】缺失字段,开始新增字段:`, element.columnName)
let executeSql = `ALTER TABLE '${tableName}' ADD COLUMN '${element.columnName}' ${element.affinity}`
if (element.defaultValue) {
executeSql += ` DEFAULT '${element.defaultValue}'`
}
await DbUtil.executeSql(executeSql)
console.info('TagInfo', `数据表【${tableName}】新增字段【${element.columnName}】成功`)
}
}
} catch (e) {
console.info('TagInfo Error:', JSON.stringify(e))
}
}

getColumn(tableName: string) {
const entities = AppDatabase.database.entities
const tableInfo = entities.find(item => item.tableName === tableName)
return this.fieldsToColumnInfo(tableInfo?.fields || [])
}

getAssignColumn(tableName: string, assignColumn: string[]) {
const columns = this.getColumn(tableName)
return columns.filter(item => assignColumn.includes(item.columnName))
}

fieldsToColumnInfo(fields: FieldsType[]): ColumnInfo[] {
return fields.map(item => {
const columnInfo: ColumnInfo = {
name: item.fieldPath,
// 数据库列名
columnName: item.columnName,
// 列类型
type: item.boolean ? ColumnType.BOOLEAN : ColumnValue[item.affinity],
defaultValue: item.defaultValue
}
return columnInfo
})
}
}

const appDatabaseUtil = new AppDatabaseUtil();
export default appDatabaseUtil as AppDatabaseUtil;
Loading

0 comments on commit 6caf4aa

Please sign in to comment.