Skip to content

Instantly share code, notes, and snippets.

@tracker1
Created September 14, 2012 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tracker1/3725475 to your computer and use it in GitHub Desktop.
Save tracker1/3725475 to your computer and use it in GitHub Desktop.
Module exports in coffeescript
# Without the anonymous function wrapper, it seemed to only export the first value.
(->
exports.getTopOfQueue = """
SELECT TOP 10
[Id],[CreatedOn],[LastAttemptOn],[Application],[Class],[From],[To],[Subject],[BodyUrl],[BodyHtml],[JsonDetails]
FROM [EmailQueue]
WHERE [LastAttemptOn] < DATEADD(m, -15, SYSUTCDATETIME())
ORDER BY [Id]
"""
exports.unsentEmailQueueItem="""
UPDATE [EmailQueue]
SET [LastAttemptedOn] = SYSUTCDATETIME()
,[JsonDetails] = @details
WHERE [Id] = @id
"""
exports.sentEmailQueueItem="""
BEGIN TRANS
INSERT INTO [EmailSent] ([CreatedOn],[LastAttemptOn],[Application],[Class],[From],[To],[Subject],[BodyUrl],[BodyHtml],[JsonDetails])
SELECT eq.[CreatedOn]
,eq.[LastAttemptOn]
,eq.[Application]
,eq.[Class]
,eq.[From]
,eq.[To]
,eq.[Subject]
,eq.[BodyUrl]
,@bodyHtml
,@details
FROM [EmailQueue] eq
WHERE eq.[Id] = @id;
DELETE FROM [EmailQueue] WHERE [Id] = @id;
COMMIT TRANS
"""
)() #end anonymous self-executing function
@tracker1
Copy link
Author

console.dir(require("./sqltext")) outputs { getTopOfQueue: '...' } not the rest.

@tracker1
Copy link
Author

If I wrap the entire thing in an anonymous self executing function, it seems to work... (<- ... )()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment