|
|
|
@ -23,6 +23,34 @@ export function alasql_async_queries(alasql_object, queries) { |
|
|
|
|
return p; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function convert_sqljs_result_to_rows(result_object) { |
|
|
|
|
if(result_object.length == 0) { |
|
|
|
|
return []; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var headers = result_object[0].columns; |
|
|
|
|
var data = result_object[0].values; |
|
|
|
|
var data_out = []; |
|
|
|
|
data.forEach(row => { |
|
|
|
|
var row_out = {}; |
|
|
|
|
for(let i=0; i<row.length; i++) { |
|
|
|
|
row_out[headers[i]] = row[i]; |
|
|
|
|
} |
|
|
|
|
data_out.push(row_out); |
|
|
|
|
}); |
|
|
|
|
return data_out; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export async function sqljs_async_queries(sqljs_object, queries) { |
|
|
|
|
for (let i = 0; i < (queries.length - 1); i++) { |
|
|
|
|
var r = sqljs_object.exec(queries[i]); |
|
|
|
|
console.log("Ran: ", queries[i], ". Output: ", r); |
|
|
|
|
} |
|
|
|
|
var ret = sqljs_object.exec(queries[queries.length - 1]); |
|
|
|
|
console.log("Ran: ", queries[queries.length - 1], ". Output: ", ret); |
|
|
|
|
return convert_sqljs_result_to_rows(ret); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export class DB { |
|
|
|
|
state = { |
|
|
|
|
db_type: false, |
|
|
|
@ -43,8 +71,9 @@ export class DB { |
|
|
|
|
if (this.state.db_type === DBTypeEnum.ALASQL_SQLITE || |
|
|
|
|
this.state.db_type === DBTypeEnum.ALASQL_INDEXEDDB || |
|
|
|
|
this.state.db_type === DBTypeEnum.ALASQL_NATIVE) { |
|
|
|
|
var self = this; |
|
|
|
|
return alasql_async_queries(self.state.db_object, s); |
|
|
|
|
return alasql_async_queries(this.state.db_object, s); |
|
|
|
|
} else if (this.state.db_type === DBTypeEnum.SQLJS_SQLITE) { |
|
|
|
|
return sqljs_async_queries(this.state.db_object, s); |
|
|
|
|
} |
|
|
|
|
throw new Error("Unsupported database type for async operations: " + this.state.db_type); |
|
|
|
|
} |
|
|
|
@ -250,8 +279,10 @@ export class ProvideDB extends React.Component { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
componentDidMount() { |
|
|
|
|
var output_db_name = (this.props.db_source_type === this.props.db_target_type) ? |
|
|
|
|
this.props.db_source_name : this.props.db_target_name; |
|
|
|
|
if (this.props.db_source_type === DBTypeEnum.ALASQL_SQLITE && this.props.db_source === DBSourceEnum.ATTACHFILE) { |
|
|
|
|
fetch_db_from_sqlite(this.props.db_file, this.props.db_source_name) |
|
|
|
|
fetch_db_from_sqlite(this.props.db_file, output_db_name) |
|
|
|
|
.then(db => { |
|
|
|
|
if (this.props.db_target_type !== this.props.db_source_type) { |
|
|
|
|
db.migrate_async(this.props.db_target_type, this.props.db_target_name) |
|
|
|
@ -260,7 +291,7 @@ export class ProvideDB extends React.Component { |
|
|
|
|
}) |
|
|
|
|
.catch(error => this.setState({ loading: false, done: false, error })); |
|
|
|
|
} else if (this.props.db_source_type === DBTypeEnum.ALASQL_INDEXEDDB && this.props.db_source === DBSourceEnum.CREATE) { |
|
|
|
|
create_indexed_db(this.props.db_source_name) |
|
|
|
|
create_indexed_db(output_db_name) |
|
|
|
|
.then(db => { |
|
|
|
|
if (this.props.db_target_type !== this.props.db_source_type) { |
|
|
|
|
db.migrate_async(this.props.db_target_type, this.props.db_target_name) |
|
|
|
@ -268,7 +299,7 @@ export class ProvideDB extends React.Component { |
|
|
|
|
} else { this.setState({ loading: false, done: true, db: db }) }; |
|
|
|
|
}); |
|
|
|
|
} else if (this.props.db_source_type === DBTypeEnum.ALASQL_NATIVE && this.props.db_source === DBSourceEnum.CREATE) { |
|
|
|
|
create_native_db(this.props.db_source_name) |
|
|
|
|
create_native_db(output_db_name) |
|
|
|
|
.then(db => { |
|
|
|
|
if (this.props.db_target_type !== this.props.db_source_type) { |
|
|
|
|
db.migrate_async(this.props.db_target_type, this.props.db_target_name) |
|
|
|
@ -276,7 +307,7 @@ export class ProvideDB extends React.Component { |
|
|
|
|
} else { this.setState({ loading: false, done: true, db: db }) }; |
|
|
|
|
}); |
|
|
|
|
} else if (this.props.db_source_type === DBTypeEnum.SQLJS_SQLITE && this.props.db_source === DBSourceEnum.ATTACHFILE) { |
|
|
|
|
fetch_sqljs_db_from_sqlite(this.props.db_file, this.props.db_source_name) |
|
|
|
|
fetch_sqljs_db_from_sqlite(this.props.db_file, output_db_name) |
|
|
|
|
.then(db => { |
|
|
|
|
if (this.props.db_target_type !== this.props.db_source_type) { |
|
|
|
|
db.migrate_async(this.props.db_target_type, this.props.db_target_name) |
|
|
|
|