Search code examples
gocassandragocql

How do you execute a cql file using gocql?


If you were to interface directly with Cassandra using cqlsh you could do the following:

$ cqlsh
cqlsh:test> SOURCE '/home/me/reset_db.cql'

I've tried to do this using gocql several times but I always get an error. For example, running this:

filePath := "/home/me/reset_db.cql"
SOURCE_FILE := "SOURCE (?)"
resetErr := session.Query(SOURCE_FILE, filePath).Exec()

Produces the following error:

line 1:0 no viable alternative at input 'SOURCE' ([SOURCE]...)

So what am I doing wrong here?


Solution

  • SOURCE is a shortcut in cqlsh, not valid CQL command in general.

    You'll need to read the file contents into strings and execute them.