``` export async function createOHLCVs(market, per...
# orm-help
i
Copy code
export async function createOHLCVs(market, period, ohlcvs) {
  // console.log('createOHLCVs', market, period, ohlcvs.length)

  const apolloClient = getApolloClient()

  await Promise.all(
    ohlcvs.map((oHLCV) => {
      const [timestamp, open, high, low, close, volume] = oHLCV

      const variables = {
        close,
        high,
        low,
        marketBase: market.base,
        marketQuote: market.quote,
        open,
        period,
        timestamp: new Date(timestamp).toISOString(),
        volume,
      }

      return apolloClient.mutate({
        mutation: createOHLCV,
        variables,
      })
    }),
  )
}
This code makes me cry 😞
d
Please use threads 🙂
i
I'm doing N (365 for me) insert's in parallel After deleting all 365 because I can't upsert them because my data does not contain an ID.
How do I upsert many documents?
h
Create something unique from it, there is no other way around it
i
Copy code
type OHLCV @model {
    timestamp: DateTime!
    marketBase: String!
    marketQuote: String!
    period: String!
    open: Float!
    high: Float!
    low: Float!
    close: Float!
    volume: Float
}
Copy code
mutation upsertOHLCV(
  $timestamp: DateTime!
  $marketBase: String!
  $marketQuote: String!
  $period: String!
  $open: Float!
  $high: Float!
  $low: Float!
  $close: Float!
  $volume: Float

) {
  upsertOHLCV(
    where: {
    	timestamp: $timestamp
  	},
    create: {
      timestamp: $timestamp
      marketBase: $marketBase
      marketQuote: $marketQuote
      period: $period
      open: $open
      high: $high
      low: $low
      close: $close
      volume: $volume
    },
    update: {
      timestamp: $timestamp
      marketBase: $marketBase
      marketQuote: $marketQuote
      period: $period
      open: $open
      high: $high
      low: $low
      close: $close
      volume: $volume
    }
  ) {
    timestamp
  }
}
Copy code
Cannot query field 'upsertOHLCV' on type 'Mutation'. Did you mean 'createOHLCV', 'upsertUser', 'upsertChart', 'upsertMarket' or 'updateManyOHLCVs'? (line 2, column 3):\n  upsertOHLCV(where: {timestamp: $timestamp}, create: {timestamp: $timestamp, marketBase: $marketBase, marketQuote: $marketQuote, period: $period, open: $open, high: $high, low: $low, close: $close, volume: $volume}, update: {timestamp: $timestamp, marketBase: $marketBase, marketQuote: $marketQuote, period: $period, open: $open, high: $high, low: $low, close: $close, volume: $volume}) {\n  ^",
Huh? I don't haven an upsert?
It does show in the docs
h
You need index for upsert
i
on the right in the GraphQL Playground
Okay so how do I make my timestamp my primary key
I have time based data, all the data values will basically never change anyway. I just need them in my DB
h
@unique
i
@huv1k Somehow my table still has an ID column now
And the index should be on three columns, not just timestamp
I have timestamp, marketBase and marketQuote forming the uniqueness
scuse me, and period