@awspilot/dynamodb

Issue Star Fork

SQL

Notes:

SQL keywords must be enclosed ex. SET `set` = true

Keys in json that are keywords must be enclosed too:
	SET myobject = {
			'number'  : 1,
			"keyword2": "value",
			'keyword3': 'value',
		}


Keys in json must be enclosed in the same way as in JavaScript
	SET `object` = {
			splitme   : 'value',
			"split-me": 'value',
		}


CREATE [ PROVISIONED | PAY_PER_REQUEST ] TABLE tbl_name ( partition_key DATA_TYPE, [ sort_key DATA_TYPE, ] [ gsi_partition_key DATA_TYPE [ , gsi_sort_key DATA_TYPE ] ,] [ lsi_sort_key DATA_TYPE, ] PRIMARY KEY ( partition_key [, sort_key ] ) [ THROUGHPUT number number ] , [ , INDEX indexname GSI ( gsi_partition_key [, gsi_sort_key ] ) [ PROJECTION ALL | KEYS_ONLY | INCLUDE ( attr1, attr2 [, attr3 ] ) ] [ THROUGHPUT NUMBER NUMBER ] ] [ , INDEX indexname LSI ( partition_key , lsi_sort_key ) [ PROJECTION ALL | KEYS_ONLY | INCLUDE ( attr1, attr2 [, attr3 ] ) ] ] [ , more index defintions ] )
Values for partition_key and sort_key can be of type String or Number

INSERT INTO tbl_name SET partition_key = <VALUE>, sort_key =<VALUE> [, other_key = <VALUE>, ... ] /* NOTES: - values for non key attributes can be: string: "foo", 'bar' number: 3.14, -1 boolean: true or false null list: ["string", 1, true, null, [ 1,2,3], {} ] map: { 'number': 1, "string": "text", 'bool': true, arr: [] } stringset: new Set(['a','b','c']) numberset: new Set([ 1 , 2 , 3 ]) expression (currently only JavaScript Date supported): new Date( string_or_number_parameter ).getTime() */


INSERT INTO tbl_name VALUES ( <JSON> ) [ , ( <JSON> ) ]


UPDATE tbl_name SET key1 OP <VALUE> [, key2 OP <VALUE>, ... ] WHERE partition_key = <VALUE> AND sort_key = <VALUE> /* NOTES: - UPDATE statement will update exacly one Item indicated by WHERE - VALUE for partition_key and sort_key can be string or number - Delete an item attribute by setting its value to undefined ( not "undefined" ) - OP can be "=" or "+=" - Increment an item's value by using attribute += value, attribute = attribute + value is not supported yet */


REPLACE statement inserts or replace the Item, the equivalent of .insert_or_replace()

REPLACE INTO tbl_name SET partition_key = <VALUE>, sort_key =<VALUE> [, other_key = <VALUE> ]


DELETE FROM tbl_name WHERE partition_key = <VALUE> AND sort_key = <VALUE>


RANGE_COMPARISON can be:
	 = <VALUE>
	 < <VALUE>
	<= <VALUE>
	 > <VALUE>
	>= <VALUE>
	BETWEEN <VALUE> AND <VALUE>
	LIKE '<STRING>%'

SELECT * | attribute [, attribute ] FROM tbl_name [ USE INDEX idx_name ] WHERE partition_key = <VALUE> AND sort_key <RANGE_COMPARISON> [ DESC ] [ LIMIT <NUMBER> ] [ CONSISTENT_READ ]