Пример #1
0
        public void CreateTestTable()
        {
            var schema = schemaController.Deserialize(@"Name: typeMappingTest
Attributes:
- Name: term
  Type: text
- Name: omschrijving
  Type: text
- Name: versie
  Type: int
- Name: periode
  Type: periode
");
            var tSql   = schemaController.Service.CreateScript(schema);

            using (var connection = new SqlConnection(Global.ConnectionString))
            {
                connection.Open();
                var affectedRows = connection.Execute(@"IF NOT EXISTS (
SELECT  schema_name
FROM    information_schema.schemata
WHERE   schema_name = 'node' ) 

BEGIN
EXEC sp_executesql N'CREATE SCHEMA node'
END");
                affectedRows = connection.Execute($"drop table if exists node.{schema.Name}");
                connection.Execute(tSql);
            }
        }
Пример #2
0
        public void Node_Can_Deserialize_And_Create_SqlSchema()
        {
            var yaml = @"Version: 15.0.0.0
Name: person
Attributes:
- Name: FirstName
  Type: Text
- Name: LastName
  Type: Text
- Name: DateOfBirth
  Type: DateTime
Edges:
- Name: likes
  Constraints:
  - Name: person
  Attributes:
  - Name: rating
    Type: int
- Name: married
  Constraints:
  - Name: person
  Attributes: []
- Name: friend
  Constraints:
  - Name: person
  Attributes: []
";
            SchemaController controller = new SchemaController(new MsSqlGraphSchemaService());
            var r   = controller.Deserialize(yaml);
            var sql = controller.Service.CreateScript(r);

            Assert.True(sql == @"CREATE TABLE node.person (
ID INTEGER PRIMARY KEY,
FirstName  NTEXT,LastName  NTEXT,
) AS NODE;
CREATE TABLE edge.likes (
rating INTEGER,CONSTRAINT EC_LIKES CONNECTION (
node.person TO node.person
)
) AS EDGE;

CREATE TABLE edge.married (
CONSTRAINT EC_MARRIED CONNECTION (
node.person TO node.person
)
) AS EDGE;

CREATE TABLE edge.friend (
CONSTRAINT EC_FRIEND CONNECTION (
node.person TO node.person
)
) AS EDGE;

");
        }
Пример #3
0
        /*
         * {
         * "@context": "https://json-ld.org/contexts/person.jsonld",
         * "@id": "http://dbpedia.org/resource/John_Lennon",
         * "name": "John Lennon",
         * "born": "1940-10-09",
         * "spouse": "http://dbpedia.org/resource/Cynthia_Lennon"
         * }
         */
        public void CreateJsonLdFromSchema()
        {
            var schemaController = new SchemaController(null);
            var nameSpace        = "Vs.GraphData";
            var schema           = schemaController.Deserialize(@"Name: codeTest
Attributes:
- Name: term
  Type: text
- Name: omschrijving
  Type: text
- Name: versie
  Type: int
- Name: periode
  Type: periode
");
            //var code = schemaController.CreateJsonLd<INode>(schema, nameSpace);
        }
Пример #4
0
        public void Node_Create_Person()
        {
            NodeSchema n = new NodeSchema(name: "person");

            n.Attributes.Add(new Attribute(name: "FirstName", type: new AttributeText()));
            n.Attributes.Add(new Attribute(name: "LastName", type: new AttributeText()));
            n.Attributes.Add(new Attribute(name: "DateOfBirth", new AttributeDatum()));
            n.Edges.Add(new EdgeSchema(name: "likes"));
            n.Edges.Add(new EdgeSchema(name: "married"));
            n.Edges.Add(new EdgeSchema(name: "friend"));

            n.Edges[0].Constraints.Add(new Constraint(name: "person"));
            n.Edges[1].Constraints.Add(new Constraint(name: "person"));
            n.Edges[2].Constraints.Add(new Constraint(name: "person"));

            n.Edges[0].Attributes.Add(new Attribute(name: "rating", type: new AttributeEuro()));

            SchemaController controller = new SchemaController(new MsSqlGraphSchemaService());
            var yaml = controller.Serialize(n);
            var r    = controller.Deserialize(yaml);
            var sql  = controller.Service.CreateScript(r);

            Assert.True(sql == @"CREATE TABLE node.person (
ID INTEGER PRIMARY KEY,
FirstName  NTEXT,LastName  NTEXT,DateOfBirth DATETIME,
) AS NODE;
CREATE TABLE edge.likes (
rating DECIMAL,CONSTRAINT EC_LIKES CONNECTION (
node.person TO node.person
)
) AS EDGE;

CREATE TABLE edge.married (
CONSTRAINT EC_MARRIED CONNECTION (
node.person TO node.person
)
) AS EDGE;

CREATE TABLE edge.friend (
CONSTRAINT EC_FRIEND CONNECTION (
node.person TO node.person
)
) AS EDGE;

");
        }
Пример #5
0
        public void CreateCompilableCodeFromSchema()
        {
            var schemaController = new SchemaController(null);
            var nameSpace        = "Vs.GraphData";
            var schema           = schemaController.Deserialize(@"Name: codeTest
Attributes:
- Name: id
  Type: int
- Name: term
  Type: text
- Name: omschrijving
  Type: text
- Name: versie
  Type: int
- Name: periode
  Type: periode
");
            var code             = schemaController.CreateCode <INode>(schema, nameSpace);
            var assembly         = schemaController.Compile(code);

            Assert.NotNull(assembly);
        }
Пример #6
0
        public void CreateEntityFromYamlWithCustomType()
        {
            // create some entities through built-in data provider
            var yaml = @"Version: 15.0.0.0
Name: persoon
Attributes:
- Name: BSN
  Type: elfproef
- Name: periode
  Type: periode
Edges:
- Name: partner
  Constraints:
  - Name: persoon
  Attributes:
  - Name: periode
    Type: periode
- Name: kind
  Constraints:
  - Name: persoon
- Name: ouder
  Constraints:
  - Name: persoon
";

            SchemaController controller = new SchemaController(new MsSqlGraphSchemaService());
            var r = controller.Deserialize(yaml);
            var s = controller.Service.CreateScript(r);

            Assert.True(s == @"CREATE TABLE node.persoon (
ID INTEGER PRIMARY KEY,
BSN VARCHAR(10),periode_begin DATETIME,periode_eind  DATETIME,
) AS NODE;
CREATE TABLE edge.partner (
periode_begin DATETIME,periode_eind  DATETIME,CONSTRAINT EC_PARTNER CONNECTION (
node.persoon TO node.persoon
)
) AS EDGE;

CREATE TABLE edge.kind (
CONSTRAINT EC_KIND CONNECTION (
node.persoon TO node.persoon
)
) AS EDGE;

CREATE TABLE edge.ouder (
CONSTRAINT EC_OUDER CONNECTION (
node.persoon TO node.persoon
)
) AS EDGE;

");

            /*
             *
             * string connectionString = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=graph;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
             *
             * using (SqlConnection connection = new SqlConnection(connectionString))
             * {
             *  SqlCommand command = new SqlCommand(s, connection);
             *  //command.Parameters.AddWithValue("@tPatSName", "Your-Parm-Value");
             *  connection.Open();
             *  SqlDataReader reader = command.ExecuteReader();
             *  try
             *  {
             *      while (reader.Read())
             *      {
             *      }
             *  }
             *  finally
             *  {
             *      // Always call Close when done reading.
             *      reader.Close();
             *  }
             * }
             */
        }