Skip to content

Instantly share code, notes, and snippets.

@tywalch
tywalch / matrix.md
Last active April 6, 2025 17:44
Key/Index Mutation Scenario Matrix

Key/Index Mutation Scenario Matrix

Every permutation and its outcome at the key and index level. I have removed the following invalid scenarios:

  • There are no "update" operations on the main table index (it's immutable)
  • Only secondary indexes can have a "condition" function
  • The condition function will never be called when the "PK Composites Provided" and "SK Composites Provided" are both none

Create (put, create, upsert)

| Row | Impacted Index Type | PK Composites Provided | SK Composites Provided | Condition Present | Condition Returns | Throws | PK Action | SK Action | Index Outcome |

import { Entity, ElectroError } from 'electrodb';
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
const table = 'electro';
const client = new DynamoDBClient({
region: "us-east-1",
endpoint: 'http://localhost:8000',
credentials: {
accessKeyId: 'fake',
@tywalch
tywalch / gist:fa43890fa0c7beb84804811b7f95bf46
Created October 19, 2024 18:25
electrodb-issue-435.ts
import { Entity, Service } from 'electrodb';
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
const client = new DynamoDBClient({
region: "us-east-1",
endpoint: 'http://localhost:8000',
});
const table = 'electro';
@tywalch
tywalch / transactions.ts
Created December 29, 2023 22:39
ElectroDB Transactions across tables
process.env.AWS_NODEJS_CONNECTION_REUSE_ENABLED = "1";
import { Entity, ElectroEventListener, Service, createWriteTransaction, createGetTransaction } from 'electrodb';
import { DocumentClient } from "aws-sdk/clients/dynamodb";
const table = "electro";
const configuration = {
endpoint: "http://localhost:8000",
region: "us-east-1",
};
@tywalch
tywalch / package.json
Created May 12, 2023 20:10
ElectroDB Issue#239
{
"name": "electro-test-2023-04-08",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "ts-node src/index.ts"
},
"keywords": [],
import { DynamoDBClient as V3, ListTablesCommand, DeleteTableCommand, CreateTableCommand } from '@aws-sdk/client-dynamodb';
import { Entity, QueryResponse, EntityItem } from 'electrodb';
import { v4 as uuid } from 'uuid';
const client = new V3({
endpoint: 'http://localhost:8000',
region: 'us-east-1',
});
const table = "pagination_test";
import { Kinesis } from 'aws-sdk';
import { Command } from 'commander';
import { decodeMessage } from '@jupiterone/platform-sdk-message-codec';
const kinesis = new Kinesis({
apiVersion: '2013-12-02',
region: 'us-east-1'
});
const noop = () => {};
@tywalch
tywalch / user.ts
Created February 24, 2023 19:18
ElectroDB + Zod
import { z } from 'zod';
import { Entity, CustomAttributeType } from 'electrodb';
import { v4 as uuid } from 'uuid';
import { DocumentClient } from "aws-sdk/clients/dynamodb";
const client = new DocumentClient();
const table = 'my_table';
const zUserDetail = z.object({
firstName: z.string().min(1).max(18),
@tywalch
tywalch / index.js
Created October 28, 2021 03:43
Updating GSIs with strings like it's possible with numbers
const DynamoDB = require("aws-sdk/clients/dynamodb");
const client = new DynamoDB.DocumentClient({
region: "us-east-1",
endpoint: "http://localhost:8000"
});
/**
* withNumbers demonstrates the update of a "composite" gsi sortkey without knowledge of the current
* composite value at the time of update. This works runs without error and operates as expected.
*/
@tywalch
tywalch / poc.js
Created August 9, 2021 17:53
PoC Challenge
/**
* The aim of this exercise is ultimately to inspire communication and be starting place to drive discussion
* on methodology, general approach, and universal best practices. To frame how best to think about this code is
* that it represents a happy path POC, and your task is to use your personal experience to identify and discuss
* improvements, recommendations and potental changes that you'd recommend to get this service production ready.
*
* Please examine this document, familize yourself, come up with any questions you have and ultimately lets meet
* and discuss your thoughts. You don't need to write any code in the meantime.
*
* Note: