|
What Is Twining? |
Complete Examples #assume cn as the connection string for all samples #Ping (is it up?) # test a connection string#success[0] has reference to true/false, success[1] has message (success or error) success = database(cn).ping() #Copy/Export Operations # export data to a CSV filedatabase(cn).table("MyTable").copyto.csv("path") # export data to a delimited file database(cn).table("MyTable").copyto.delimited("\t", "c:\\foaf_no_trans.tsv") # export data to an XML file with fields as attributes database(cn).table("MyTable").copyto.xmlFieldsAsAttributes("path") # export data to an XML file with fields as attributes database(cn).table("MyTable").copyto.xmlFieldsAsElements("path") # copy data to another database cn2 = "my connection to new database" database(cn).table("MyTable").copyto.database(cn2) # Copy with transforms # copying with transforms is simple; use a dictionary,# set up field names and matching transform expressions # use the transform after specifying source table mytrans = {"Field1":"upper","Field2": lambda x: x.upper()} database(cn).table("MyTable").transform(mytrans).copyto.csv("path") database(cn).table("MyTable").transform(mytrans).copyto.xmlFieldsAsElements("path") #Importing Data # bring in data from a CSV filedatabase(cn).table("MyTable").importfrom.csv("path") # sometimes you need to map columns on the import # syntax is destination:source because you may want to have the same source # use multiple times colmap = {"DestinationField1":1, "DestinationField2":2, "DestinationField3":1} database(cn).table("MyTable").mapcolumns(colmap).importfrom.csv("C:\\foo.csv") #Backing up data # back up to a .BAK filedatabase(cn).backupto("C:\\temp\\loungin.bak") #Generate Scripts # an insert script with the records from given tabledatabase(cn).table("MyTable").copyto.script("C:\\temp\\my_insert.sql") |