The database copy feature provides a way to duplicate tables from a source database to a target database. It allows conversion from major database types like informix, oracle, db2, postgres, mysql and sqlserver.

1 Using table copy

  1. Obtain a database copy instance from cureent database pointing to another database.
    For example, asuming we have a connection to an informix database (junit_studio), we want to perform a copy from it to a database named junit_studio_oracle that belongs to a server named oracle.
    Copy
    // Ax.db points to junit_studio
    var dbcopy = Ax.db.dbcopy(Ax.db.of("oracle", "junit_studio_oracle"));
  2. Now, assume we want to copy table account. We can setup a configurator with options like in the example.
    Copy
    var event = dbcopy.copy("account", f => {
        // DROP: drop table in destination and create again before copy
        // DELETE: Delete rows in destination
        // TRUNCATE: Execute a truncate command
        // MERGE: (default)
        f.setCopyType("DROP");
        // set a batch size
        f.setBatchSize(1000);
    });   
    // TableCopyEvent
    console.log(event);
    console.log(event.getSourceDatabase());
    console.log(event.getSourceTableName());
    console.log(event.getSourceEncoding());
    console.log(event.getTargetDatabase());
    console.log(event.getTargetTableName());
    console.log(event.getTargetEncoding());
    console.log(event.getRowsDeleted());
    console.log(event.getRowsInserted());

2 Copy a database

To copy a database you can simply use the tables iterator.

Copy
var dbcopy = Ax.db.dbcopy(Ax.db.of("oracle", "junit_studio_oracle"));
    for (var table of Ax.db.getMetaData().getTables()) {
    	var event = dbcopy.copy(table, f => {
    		f.setCopyType("DROP");
    		f.setBatchSize(1000);
    	});
    	console.log(event.getRowsInserted() + " rows copied into " + event.getTargetTableName()); 
    }