提出读取json并将其插入mysql db的最佳方法。

JSON示例:

{
    "PaymentOrder": [
        {
            "$": {
                "Id": "83C44C4A-7EFD-491E-913E-007A3598618F",
                "Name": "",
                "OrderNumber": "AH9NZPUI",
                "OrderType": "Recurring",
                "Amount": "1.000000",
                "CouponDiscountAmount": ".000000",
                "ChargeAmount": ".000000",
                "CurrencyCode": "USD",
                "OwnerId": "D9F48450-AB86-4ABE-B9AD-66FE3B7AEFB1",
                "OrderStatus": "Pending",
                "PaymentProcessor": "Global Collect",
                "PaymentMethodType": "Visa",
                "SoftDescriptorText": "CNext_AH9NZPUI",
                "UserPaymentInfoId": "FDD9C487-6F66-4919-B945-766699C9EF1D",
                "IsAuthorization": "1",
                "CreateTime": "2012-07-18T10:21:47.7610377",
                "UpdateTime": "2012-07-18T10:21:47.7610377",
                "IsEnabled": "1",
                "IsDeleted": "0"
            }
        },
        {
            "$": {
                "Id": "03B1600F-F92A-47BA-8B53-00B70A942E43",
                "Name": "",
                "OrderNumber": "3427BBC3",
                "OrderType": "Recurring",
                "Amount": ".000000",
                "CouponDiscountAmount": ".000000",
                "ChargeAmount": ".000000",
                "CurrencyCode": "USD",
                "OwnerId": "9A1186E4-BAC6-43D0-8C6F-B02ECD6544B5",
                "OrderStatus": "Success",
                "PaymentProcessor": "Global Collect",
                "PaymentMethodType": "Visa",
                "SoftDescriptorText": "ComputeNext Inc Order Number - 3427BBC3",
                "UserPaymentInfoId": "142C6B38-A470-40A9-B7A7-1C8CDD6FBD2C",
                "BillingHistoryId": "6BE8DF8E-4C97-492B-9407-38EBA2B942F2",
                "InvoiceDate": "2013-03-26T14:02:07.8570464",
                "IsAuthorization": "0",
                "CreateTime": "2013-03-26T18:08:19.5383118",
                "UpdateTime": "2013-03-26T18:08:19.5695118",
                "IsEnabled": "1",
                "IsDeleted": "0"
            }
        },
        {
            "$": {
                "Id": "8FC1D8EA-C388-4F31-91C7-00CB54C337A4",
                "Name": "",
                "OrderNumber": "YTM8TOKQ",
                "OrderType": "Recurring",
                "Amount": "1.000000",
                "CouponDiscountAmount": ".000000",
                "ChargeAmount": ".000000",
                "CurrencyCode": "USD",
                "OwnerId": "3702AB47-1095-4211-B844-82C47D0D9F6C",
                "OrderStatus": "Failure",
                "PaymentProcessor": "Global Collect",
                "PaymentMethodType": "Visa",
                "SoftDescriptorText": "CNext_YTM8TOKQ",
                "UserPaymentInfoId": "19193F72-14D1-4A72-9676-2493002711ED",
                "TransactionDuration": "0:0:40:809",
                "LastTransactionNumber": "HC0F4CBYMT14QP3",
                "IsAuthorization": "1",
                "CreateTime": "2012-07-26T21:15:25.8004068",
                "UpdateTime": "2012-07-26T21:16:06.6100785",
                "IsEnabled": "1",
                "IsDeleted": "0"
            }
        }
    ]
}


JSON中存在的属性等效于mysql中的列。

最佳答案

您可以使用自己选择的语言进行编码(您只需要JSON读取工具和MySQL客户端,但是这些天来这些语言已经可以使用所有语言了),或者可以使用ETL工具。

使用ETL的优势

通常可以通过重新配置工具来解决对源格式或目标格式(例如突然需要从CSV文件或XML文件读取这些数据)或内容(添加,消失或重命名字段)的更改。

使用ETL的缺点

这是您还需要管理的另一个(相当沉重的)基础架构,有人会争辩说,使用ETL工具执行此类任务就像用大锤杀死苍蝇。

但是,根据您对灵活性的要求,ETL可能是最好/最简单的解决方案。

关于mysql - 以编程方式使用node.js读取JSON和将MySQL插入mysql的最佳方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19027750/

10-12 14:16
查看更多