Dyna
Dyna is an AWS DynamoDB ORM for Common Lisp.
Install / Use
/learn @rudolph-miller/DynaREADME
Dyna
Dyna is an AWS DynamoDB ORM for Common Lisp.
Usage
(defvar *dyna* (make-dyna :credentials (cons (asdf::getenv "AWS_ACCESS_KEY")
(asdf::getenv "AWS_SECRET_KEY"))
:region "ap-northeast-1"))
(defclass thread ()
((forum-name :key-type :hash
:attr-name "ForumName"
:initarg :forum-name
:accessor thread-forum-name)
(subject :key-type :range
:attr-name "Subject"
:initarg :subject
:accessor thread-subject))
(:dyna *dyna*)
(:table-name "Thread")
(:metaclass <dyna-table-class>))
(migrate-dyna-teble 'thread)
;; => T
(save-dyna (make-instance 'thread :forum-name "Amazon DynamoDB"
:subject "Really useful"))
;; => T
(find-dyna 'thread "Amazon DynamoDB" "Really useful")
;; => #<THREAD :forum-name "Amazon DynamoDB" :subject "Really useful">
;;; The operations below is the samples of Low Level API.
(fetch (dyna-credentials *dyna*) "local" "ListTables" "{}")
;; => #(...)
(put-item *dyna* :table-name "aliens"
:item (("Name" . "LispAlien") ("Feature" . "They talk Lisp.")))
;; => T
(get-item *dyna* :table-name "aliens" :key (("Name" . "LispAlien"))))
;; => (("Name" . "LispAlien") ("Feature" . "They talk Lisp."))
Installasion
(ql:quickload :dyna)
API
dyna
(make-dyna :credentials (cons "access-key" "secret-key")
:region "ap-northeast-1")
dynaobject is a object for setting up.make-dynacreatesdynaobject.:credentialsis a dotted pair of AccessKey and SecretKey.:regionis a region of your DynamoDB.- If you want to access you local DynamoDB Local,
you can setup:region "local"and(setf *local-port* 8000).
<dyna-table-class>
(defclass thread ()
((forum-name :key-type :hash
:attr-name "ForumName"
:attr-type :S
:initarg :forum-name
:accessor thread-forum-name)
(subject :key-type :range
:attr-name "Subject"
:attr-type :S
:initarg :subject
:accessor thread-subject)
(owner :attr-name "Owner"
:attr-type :S
:initarg :owner
:accessor thread-owner)
(last-post-date-time :attr-name "LastPostDateTime"
:attr-type :S
:initarg :last-post-date-time
:accessor thread-last-post-date-time))
(:dyna *dyna*)
(:table-name "Thread")
(:throughput (:read 1 :wirte 1)
(:lsi lat-post-date-time)
(:gsi (:hash owner :read 5 :write 5))
(:metaclass <dyna-table-class>))
;; Simpler Style
(defclass thread ()
((forum-name :key-type :hash
:attr-type :S
:initarg :forum-name
:accessor thread-forum-name)
(subject :key-type :range
:attr-type :S
:initarg :subject
:accessor thread-subject))
(:dyna *dyna*)
(:metaclass <dyna-table-class>))
- You can create class haveing <dyna-table-class> as
:metaclass. :dynacan takedynaobject.:table-namecan take table name of DynamoDB's table. (Optional):throughputis the ProvisionedThroughput of the table. (Optional)- You can create table without
:throughput,
then the first value of ProvisionedThroughput will be*default-throughput*,
and you can adjust ProvisionedThroughput with AWS Console. :lsiis columns of LocalSecondaryIndexes.:gsiis columns of GlobalSecondaryIndexes.- You can create
:gsiwithout:readnor:write,
then the first value of ProvisionedThroughput in GlobalSecondaryIndexes will be
*default-throughput*, and you can adjust ProvisionedThroughput with AWS Console. :key-typein slot should be:hashor:rangeand is the same as DynamoDB's table.:attr-namein slot is AttributeName of Item in DynamoDB's table. (Optional):attr-typein slot is AttributeType of Item in DynamoDB's table. (Optional)- You must attach
:attr-typewith Attributes used in Indexes.
create-dyna-table
(create-dyna-table 'thread)
;; => T
- can return T if the table is successfully created.
update-dyna-table
(defclass thread ()
((forum-name :key-type :hash
:attr-name "ForumName"
:attr-type :S
:initarg :forum-name
:accessor thread-forum-name)
(subject :key-type :range
:attr-name "Subject"
:attr-type :S
:initarg :subject
:accessor thread-subject))
(:dyna *dyna*)
(:table-name "Thread")
(:throughput (:read 10 :wirte 10)
(:metaclass <dyna-table-class>))
(update-dyna-table 'thread)
;; => T
(update-dyna-table 'thread)
;; => NIL
- can return T if the table is successfully updated.
- can return NIL if the table has no changs.
migrate-dyna-table
(migrate-dyna-table 'thread)
=> T
- can create the table if the table doesn't exist.
- can update the table if the table definitions are chagned.
- can return NIL if the table has no changes.
find-dyna
(find-dyna 'thread "Amazon DynamoDB" "Really useful")
;; => #<THREAD :forum-name "Amazon DynamoDB" :subject "Really useful">
- can return a object if matching Item exists.
select-dyna
(select-dyna 'thread)
;; => (#<THREAD > <#THREAD >)
(selet-dyna 'thread (where (:= :forum-name "Amazon DynamoDB")))
;; => (#<THREAD >)
(selet-dyna 'thread (where (:or (:= :forum-name "Amazon S3")
(:= :forum-name "Amazon DynamoDB"))))
;; => (#<THREAD > #<THREAD >)
(selet-dyna 'thread (where (:in :forum-name '("Amazon S3" "Amazon DynamoDB"))))
;; => (#<THREAD > #<THREAD >)
(selet-dyna 'thread (where (:in :forum-name '("Amazon S3" "Amazon DynamoDB")))
:limit 1)
;; => (#<THREAD >)
(selet-dyna 'thread (where (:in :forum-name '("Amazon S3" "Amazon DynamoDB")))
(limit 1))
;; => (#<THREAD >)
(select-dyna 'thread :segments 4)
;; => (#<THREAD > <#THREAD >)
- returns the list of objects.
- can handle Extended Where Clause of SxQL.
- can handle
LastEvaluatedKeyin the response. :limitcan restrict the number of results.- can handle Limit Clause of SxQL.
:segmentscan makescanrequest divided.
save-dyna
(save-dyna (make-instance 'thread :forum-name "Amazon DynamoDB"
:subject "Really useful"))
;; =>
- can return T if the object is successfully saved.
Low Level API
Most Low Level API return multiple values, the formaer is formatted result, and the latter is raw result.
fetch
(fetch (cons "access-key" "secret-key") "ap-northeast-1" "ListTables" "{}")
;; => #(...)
- returns raw octets of reponse.
batch-get-item
(batch-get-item dyna :request-items '(("Forum" . (("Keys" . ((("Id" . 1))
(("Id" . 2))))
("ProjectionExpression" . "Id, Title, Author")))
("Thread" . (("Keys" . ((("ForumName" . "Amazon DynamoDB")
("Subject" . "Concurrent reads"))))
("AttributesToGet" . "ForumName, Subject"))))
:return-consumed-capacity "TOTAL")))
;; => (("Forum" (("Id" . 1) ("Title" . "Enjoy Lisp") ("Author" . "Rudolph-Miller"))
;; (("Id" . 2) ("Title" . "Sophisticated Programming Language") ("Author" . "Lisp-Alien")))
;; ("Thread" (("ForumName" . "Amazon DynamoDB") ("Subject" . "Concurrent reads"))))
- returns the list of alists.
- Support
:request-items:return-consumed-capacity
batch-write-item
(batch-write-item dyna :request-items '(("Forum" . ((("PutRequest" . (("Item" . (("Name" . "Amazon DynamoDB")
("Category" . "Amazon Web Services"))))))
(("PutRequest" . (("Item" . (("Name" . "Amazon RDS")
("Category" . "Amazon Web Services"))))))))
("Thread" . ((("PutRequest" . (("Item" . (("ForumName" . "Amazon DynamoDB")
("Subject" . "Concurrent reads")))))))))
:return-consumed-capacity "TOTAL")
;; => T
- returns t if the operation succeeded.
- Support
:request-items:return-consumed-capacity:return-item-collection-metrics
create-table
(create-table dyna :table-name "Thread"
:key-schema '((("AttributeName" . "ForumName") ("KeyType" . "HASH"))
(("AttributeName" . "Subject") ("KeyType" . "RANGE")))
:attribute-definitions '((("AttributeName" . "ForumName") ("AttributeType" . "S"))
(("AttributeName" . "Subject") ("AttributeType" . "S"))
(("AttributeName" . "LastPostDateTime") ("AttributeType" . "S")))
:local-secondary-indexes '((("IndexName" . "LastPostIndex")
("KeySchema" . ((("AttributeName" . "ForumName")
("KeyType" . "HASH"))
(("AttributeName" . "
Related Skills
node-connect
345.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
104.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
345.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
345.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
