apoc.model.jdbc
Procedure APOC Full
apoc.model.jdbc('key or url', {schema:'<schema>', write: <true/false>, filters: { tables:[], views: [], columns: []}) YIELD nodes, relationships - load schema from relational database
Signature
apoc.model.jdbc(jdbc :: STRING?, config = {} :: MAP?) :: (nodes :: LIST? OF NODE?, relationships :: LIST? OF RELATIONSHIP?)
Usage Examples
Starting from the following schema:
CREATE TABLE "country" (
"Code" CHAR(3) NOT NULL DEFAULT '',
"Name" CHAR(52) NOT NULL DEFAULT '',
"Continent" enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL DEFAULT 'Asia',
"Region" CHAR(26) NOT NULL DEFAULT '',
"SurfaceArea" FLOAT(10,2) NOT NULL DEFAULT '0.00',
"IndepYear" SMALLINT(6) DEFAULT NULL,
"Population" INT(11) NOT NULL DEFAULT '0',
"LifeExpectancy" FLOAT(3,1) DEFAULT NULL,
"GNP" FLOAT(10,2) DEFAULT NULL,
"GNPOld" FLOAT(10,2) DEFAULT NULL,
"LocalName" CHAR(45) NOT NULL DEFAULT '',
"GovernmentForm" CHAR(45) NOT NULL DEFAULT '',
"HeadOfState" CHAR(60) DEFAULT NULL,
"Capital" INT(11) DEFAULT NULL,
"Code2" CHAR(2) NOT NULL DEFAULT '',
PRIMARY KEY ("Code")
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE "city" (
"ID" INT(11) NOT NULL AUTO_INCREMENT,
"Name" CHAR(35) NOT NULL DEFAULT '',
"CountryCode" CHAR(3) NOT NULL DEFAULT '',
"District" CHAR(20) NOT NULL DEFAULT '',
"Population" INT(11) NOT NULL DEFAULT '0',
PRIMARY KEY ("ID"),
KEY "CountryCode" ("CountryCode"),
CONSTRAINT "city_ibfk_1" FOREIGN KEY ("CountryCode") REFERENCES "country" ("Code")
) ENGINE=InnoDB AUTO_INCREMENT=4080 DEFAULT CHARSET=latin1;
CREATE TABLE "countrylanguage" (
"CountryCode" CHAR(3) NOT NULL DEFAULT '',
"Language" CHAR(30) NOT NULL DEFAULT '',
"IsOfficial" enum('T','F') NOT NULL DEFAULT 'F',
"Percentage" FLOAT(4,1) NOT NULL DEFAULT '0.0',
PRIMARY KEY ("CountryCode","Language"),
KEY "CountryCode" ("CountryCode"),
CONSTRAINT "countryLanguage_ibfk_1" FOREIGN KEY ("CountryCode") REFERENCES "country" ("Code")
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
We can return a graph of the relational schema by running the following query:
CALL apoc.model.jdbc('jdbc:mysql://mysql:3306', {
schema: 'test',
credentials: {user: 'root', password: 'andrea'}
});
Figure 1. Graph Schema