简体   繁体   English

如何在HugSQL结果中将返回的映射转换为json csv

[英]How do I convert the returned maps to json csv in HugSQL results

I am trying to use HugSQL to select some records from my DB and I get back the records I have few problems when I try this code: 我正在尝试使用HugSQL从我的数据库中选择一些记录,当我尝试这段代码时,我找回了几个问题:

f/attempt-all [_ (println  "Getting DB records")
                    db-records (oracle-db/get-records my-db)
;hangs here when there are large(100,000k+) records

and

-- :name get-records
select /*+ index(src_ski_sysevents_au SRC_SKI_SYSEVENTS_AU_IDX_A)*/ * from src_ski_sysevents_au where week_id='201903' AND ROWNUM <'10000'

Actual results: db-records has a list of maps(map for each record returned) like this: 实际结果:db-records有一个映射列表(返回的每个记录的映射),如下所示:

({:remarks nil, :timeprocessing 1994-01-01 00:00:00.000, :devicetype 3M, :staffcode 0M, 
           :timedeletion 1994-01-01 00:00:00.000, :occurred 1M, :syseventdesig Ticket jam, :time 2019-01-14 10:47:37.350, :syseventno 27M, 
  :devicedesig P4 LH Exit Wilga ST - 49, :devicenoprocessing 0M, :component nil, :lotabbr P3P4, :deviceabbr P4 LEX WIL, 
  :week_id 201903M, :lotdesig P3, P4 Levels, :dss_update_time #inst "2019-01-14T15:48:46.000000000-00:00", :loaded_new_yn N, 
  :operatorfirstname nil, :quantity 1M, :systemeventregno 7365M, :pdi_batch_id 697410M, :lotno 1M, :deviceno 49M, :deleted_yn N, 
  :centre_no 0012000, :lot_no 0012001, :operatorsurname unattended, :operatornoprocessing 0M}
  ...
)

I want to know how to convert this list of maps to a Json string file or CSV file to push it to my endpoint. 我想知道如何将这个映射列表转换为Json字符串文件或CSV文件,以将其推送到我的端点。 While handling non-string values like 在处理非字符串值时

:timeprocessing 1994-01-01 00:00:00.000 :timeprocessing 1994-01-01 00:00:00.000

I see errors for these as soon as I put this test string in to test in a (comment (def testmap {input_test_Data})) with invalid number format and I also found that 一旦我将这个测试字符串放入测试(comment (def testmap {input_test_Data}))并且数字格式无效,我就会看到这些错误,我也发现了

:dss_update_time in my DB is "15/JAN/19" :我的DB中的dss_update_time是“15 / JAN / 19”

but in the HugSQL results I get something like this 但是在HugSQL结果中,我得到了类似的东西

:dss_update_time #inst "2019-01-14T15:48:46.000000000-00:00" :dss_update_time #inst“2019-01-14T15:48:46.0​​00000000-00:00”

Basically how would I ensure I get back all the data Would really appreciate some help on the second part of my problem at least. 基本上我将如何确保我收回所有数据至少在我的问题的第二部分非常感谢一些帮助。 Thank you 谢谢

Please use the function prn instead of println to print out a sample data row. 请使用函数prn而不是println打印出样本数据行。 Then you will see that the date values are actually strings ( prn will not strip away the double-quote chars like println does). 然后你会看到日期值实际上是字符串( prn不会剥离像println那样的双引号字符)。

At that point, you can just use normal EDN->JSON conversion. 此时,您可以使用正常的EDN-> JSON转换。 There is a simple function in the Tupelo library : 图珀洛图书馆一个简单的功能

(t/edn->json  {:a 1  :b 2})
;=> {"a":1,"b":2}

which just uses the Cheshire lib under the covers and automatically does keyword<->string conversion. 它只使用了封面下的Cheshire lib并自动进行关键字< - >字符串转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM