MCPcopy Create free account
hub / github.com/GoogleChrome/webstatus.dev / createWithTransaction

Method createWithTransaction

lib/gcpspanner/client.go:599–633  ·  view source on GitHub ↗
(
	_ context.Context,
	txn *spanner.ReadWriteTransaction,
	req CreateRequest,
	opts ...CreateOption)

Source from the content-addressed store, hash-verified

597}
598
599func (c *entityCreator[M, CreateRequest, SpannerStruct]) createWithTransaction(
600 _ context.Context,
601 txn *spanner.ReadWriteTransaction,
602 req CreateRequest,
603 opts ...CreateOption) (*string, error) {
604 options := &createOptions{
605 id: "",
606 }
607 for _, opt := range opts {
608 opt(options)
609 }
610
611 var entityID string
612 if options.id != "" {
613 entityID = options.id
614 } else {
615 entityID = uuid.NewString()
616 }
617
618 var mapper M
619 entity, err := mapper.NewEntity(entityID, req)
620 if err != nil {
621 return nil, err
622 }
623 m, err := spanner.InsertStruct(mapper.Table(), entity)
624 if err != nil {
625 return nil, errors.Join(ErrInternalMutationFailure, err)
626 }
627 err = txn.BufferWrite([]*spanner.Mutation{m})
628 if err != nil {
629 return nil, errors.Join(ErrInternalMutationFailure, err)
630 }
631
632 return &entityID, nil
633}
634
635// syncableEntityMapper is composed for the entitySynchronizer. It needs
636// methods to read all entities, handle keys, merge, and delete by struct.

Calls 2

NewEntityMethod · 0.65
TableMethod · 0.65

Tested by

no test coverage detected