Skip to content

Instantly share code, notes, and snippets.

@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:
@tywalch
tywalch / nodejs_discussion.js
Last active December 4, 2020 14:06
POC Service
/**
* 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:
@tywalch
tywalch / koanexample.js
Last active August 25, 2020 17:03
Koan example in ElectroDB
// Modeling the example posed by Ashwin Bhat in ElectroDB
// https://medium.com/developing-koan/modeling-graph-relationships-in-dynamodb-c06141612a70
const {Entity, Service} = require("electrodb");
const Roles = {
"lead": "500",
"contributor": "400",
"team": "300",
}
/**********************************************
* Zuul IoT Delegation Manager - ZUULJS.COM
* Example Code
*
* Tyler W. Walch
* TINKERTAMPER.COM [2017]
***********************************************/
/* CONFIGURE SHARED VARIABLES.
* Shared light status variable allows for all functions to react