如何使用SQL Replication将数组中的多个列从Raven DB复制到关系数据库?

时间:2013-03-26 16:32:25

标签: replication ravendb

我正在努力使用Raven的SQL复制工具将我们的Raven DB文档复制到SQL中,到目前为止只遇到了几个障碍。我现在已经开始研究我们最复杂的文档之一,并努力寻找在包含多个列的文档中复制数组的最佳方法。

这就是我试图复制的文档的外观:

{
  "CreatedAt": "2013-03-26T15:58:05.5130458",
  "IsMostRecent": true,
  "ClientId": "clients/417",
  "StatusType": "Live",
  "Start": "2013-03-31T00:00:00.0000000",
  "End": null,
  "EndCharge": null,
  "AssessmentDate": null,
  "Correspondence": null,
  "Service": {
  "$type": "xxxx.xxxx.xxxx.xxxx.Personalisation, xxxx.Care.Core",
  "IsDirectBilling": false,
   "Visits": [
      {
         "DayOfWeek": "Monday",
         "Start": "09:00:00",
         "End": "10:15:00",
         "AdditionalResources": true,
         "SocialWork": {
             "Duration": 30,
             "BillableTo": "SocialWork",
             "VisitTasks": [
                "GoingToBed",
                "DressingAssistance",
                "WashingBathingAssistance",
                "AssistWithPersonalGrooming"
          ]
        },
         "PrivateWork": {
             "Duration": 45,
             "BillableTo": "Private",
          "VisitTasks": [
            "SupportWithRehab",
            "FoodPreperation",
            "ShoppingErrandRunning",
            "NonSpecialisedLaundry",
            "CheckVisit",
            "MealsAtHomeService",
            "Escorting"
          ]
        }
  },
  {
    "DayOfWeek": "Wednesday",
    "Start": "09:00:00",
    "End": "10:15:00",
    "AdditionalResources": true,
    "SocialWork": {
      "Duration": 30,
      "BillableTo": "SocialWork",
      "VisitTasks": [
        "GoingToBed",
        "DressingAssistance",
        "WashingBathingAssistance",
        "AssistWithPersonalGrooming"
      ]
    },
    "PrivateWork": {
      "Duration": 45,
      "BillableTo": "Private",
      "VisitTasks": [
        "SupportWithRehab",
        "FoodPreperation",
        "ShoppingErrandRunning",
        "NonSpecialisedLaundry",
        "CheckVisit",
        "MealsAtHomeService",
        "Escorting"
      ]
    }
  },
  {
    "DayOfWeek": "Friday",
    "Start": "09:00:00",
    "End": "10:15:00",
    "AdditionalResources": true,
    "SocialWork": {
      "Duration": 30,
      "BillableTo": "SocialWork",
      "VisitTasks": [
        "GoingToBed",
        "DressingAssistance",
        "WashingBathingAssistance",
        "AssistWithPersonalGrooming"
      ]
    },
    "PrivateWork": {
      "Duration": 45,
      "BillableTo": "Private",
      "VisitTasks": [
        "SupportWithRehab",
        "FoodPreperation",
        "ShoppingErrandRunning",
        "NonSpecialisedLaundry",
        "CheckVisit",
        "MealsAtHomeService",
        "Escorting"
      ]
    }
  }
],
"_visits": [
  {
    "DayOfWeek": "Monday",
    "Start": "09:00:00",
    "End": "10:15:00",
    "AdditionalResources": true,
    "SocialWork": {
      "Duration": 30,
      "BillableTo": "SocialWork",
      "VisitTasks": [
        "GoingToBed",
        "DressingAssistance",
        "WashingBathingAssistance",
        "AssistWithPersonalGrooming"
      ]
    },
    "PrivateWork": {
      "Duration": 45,
      "BillableTo": "Private",
      "VisitTasks": [
        "SupportWithRehab",
        "FoodPreperation",
        "ShoppingErrandRunning",
        "NonSpecialisedLaundry",
        "CheckVisit",
        "MealsAtHomeService",
        "Escorting"
      ]
    }
   },
 }
}

到目前为止,这是我的复制脚本,目前正在复制一些列但不是全部:

replicateToServiceStatusDetails({
        ClientId: this.ClientId,
        StatusType: this.StatusType,
        Start: this.Start,
        End: this.End,
        EndChargeDate: this.EndChargeDate,
        AssessmentDate: this.AssessmentDate
});

for (var i=0; i<this.Service.length; i++) 
{
    replicateToService( 
    {
           IsDirectBilling: this.IsDirectBilling
    });
}

for (var i=0; i<this.Service.Visits.length; i++) 
{
    replicateToVisits( 
    {
            DayOfWeek: this.Service.Visits.DayOfWeek,
    Start: this.Service.Visits.Start,
    End: this.Service.Visits.End,
    AdditionalResources: this.Service.Visits.AdditionalResources
});
}

for (var i=0; i<this.Service.Visits.SocialWork.length; i++) 
{
    replicateToSocialWork( 
    {
            Duration: this.Service.Visits.SocialWork.Duration,
    BillableTo: this.Service.Visits.SocialWork.BillableTo
    });
}

for (var i=0; i<this.Service.Visits.PrivateWork.length; i++) 
{
    replicateToPrivateWork( 
    {
            Duration: this.Service.Visits.PrivateWork.Duration,
    BillableTo: this.Service.Visits.PrivateWork.BillableTo
    });
}

寻找有关如何复制所有列的一些想法。

1 个答案:

答案 0 :(得分:2)

如果要迭代数组,则只需要for。这可能是你想要这样做的:

replicateToServiceStatusDetails({
        ClientId: this.ClientId,
        StatusType: this.StatusType,
        Start: this.Start,
        End: this.End,
        EndChargeDate: this.EndChargeDate,
        AssessmentDate: this.AssessmentDate
});

replicateToService( 
{
       IsDirectBilling: this.IsDirectBilling
});

for (var i=0; i<this.Service.Visits.length; i++) 
{
    var visit = this.Service.Visits[i];
    replicateToVisits( 
    {
            DayOfWeek: visit.DayOfWeek,
            Start: visit.Start,
            End: visit.End,
            AdditionalResources: visit.AdditionalResources
    });

    replicateToSocialWork( 
    {
            Duration: visit.SocialWork.Duration,
        BillableTo: visit.SocialWork.BillableTo
    });

    replicateToPrivateWork( 
    {
         Duration: visit.PrivateWork.Duration,
        BillableTo: visit.PrivateWork.BillableTo
    });
}