Explorer

definy.store-write-contents

description
Store the contents in the CAS (the hashes are checked beforehand) and return the hashes. An existing hash is not overwritten (SQL)
type
Fn(items: List<@definy.content-item>, then: Fn(stored: List<String>) -> @definy.service-io) -> @definy.service-io
expression
fn(items$0, then$1) =>
  let stored$2 = @core.list-map(
      T: @definy.content-item,
      U: String,
      f: fn(item$3) =>
        $3.content_hash,
      xs: $0
    );
  match @core.equal(left: @core.list-length(value: $0), right: 0) {
    true =>
      $1(stored: $2),
    false =>
      #sql<@definy.service-io>({
        statements: @core.list-map(
          T: @definy.content-item,
          U: @definy.sql-statement,
          f: fn(item$4) =>
            {
              sql: "INSERT OR IGNORE INTO cas_contents (content_hash, content_bytes) VALUES (?, ?)",
              params: [#text<@definy.sql-value>($4.content_hash), #text<@definy.sql-value>($4.content_bytes)]
            },
          xs: $0
        ),
        then: fn(results$5) =>
          $1(stored: $2)
      })
  }
visibility
public
definy.store-write-contents (project definy, branch main, snapshot l0VFjJZP174d8CbZWFoujAGTYjgsQu4uTq5uWCZaXgo)
id: FoeOFQ5ssp5ur7wU4a2Kb76Wgaq-rui3hUaqvMZY66o
content hash: OIBtxcL3fZRQ213BOHtS12DcDSLi09q7zuc9Rva_9JE