Skip to content

Instantly share code, notes, and snippets.

@booo
Created November 7, 2012 20:21
Show Gist options
  • Select an option

  • Save booo/4034152 to your computer and use it in GitHub Desktop.

Select an option

Save booo/4034152 to your computer and use it in GitHub Desktop.
class Batch
constructor: (@keyspace) ->
@statements = [] #list of statements aka insert delete update
toCQL: ->
"BEGIN BATCH
#{(stmt.toCQL() for stmt in @statements).join "\n"}
APPLY BATCH"
class Table
constructor: (@name, @columns, @primaryKeys, @options) ->
create: ->
"CREATE TABLE #{@name} (#{ ("#{name} #{type}" for [name, type] in @columns).join ", " } PRIMARY KEY(#{@primaryKeys.join ", "}))"
drop: ->
"DROP TABLE #{@name}"
truncate: ->
"TRUNCATE TABLE #{@name}"
select: (columns) ->
new SelectStatement @
insert: ->
update: @insert
delete: ->
class SelectStatement
constructor: (@table, @columns) ->
toCQL: ->
bar = new Table "bar", [["user_id", "varchar"],["tweet_id", "varchar"]], ["user_id"]
b = new Batch("foo")
console.log b.toCQL()
console.log bar.create()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment