Documentation
¶
Overview ¶
Package simpledbsql provides an AWS SimpleDB driver for the database/sql package.
See the package example for an overview of how to use the driver.
SQL ¶
Refer to https://github.com/jjeffery/simpledbsql for a description of the SQL dialect supported by this driver. The following examples can be used as a guide.
select id, a, b, c from my_table where a > ? and b = ? order by a insert into my_table(id, a, b, c) values(?, ?, ?, 'c value') update my_table set a = ?, b = ?, c = 'processed' where id = ? delete from my_table where id = ? create table my_table drop table my_table
For consistent-read select statements, prefix the `select` with the word `consistent`
consistent select id, a, b, c from my_table where a = ?
Example ¶
package main import ( "context" "database/sql" "fmt" "log" "time" _ "github.com/jjeffery/simpledbsql" ) func main() { db, err := sql.Open("simpledb", "") exitIfError(err) ctx := context.Background() // create a table _, err = db.ExecContext(ctx, "create table temp_test_table") exitIfError(err) waitForConsistency() // insert some rows for i := 0; i < 10; i++ { id := fmt.Sprintf("ID%03d", i) name := fmt.Sprintf("name-%d", i) number := i * i _, err = db.ExecContext(ctx, "insert into temp_test_table(id, name, number) values(?, ?, ?)", id, name, number, ) exitIfError(err) } waitForConsistency() // update a row _, err = db.ExecContext(ctx, "update temp_test_table set number = ? where id = ?", 100, "ID007", ) exitIfError(err) // delete a row _, err = db.ExecContext(ctx, "delete from temp_test_table where id = 'ID008'") exitIfError(err) // select rows rows, err := db.QueryContext(ctx, "consistent select id, name, number from temp_test_table where name is not null order by name desc", ) exitIfError(err) for rows.Next() { var ( id string name string number int ) err = rows.Scan(&id, &name, &number) exitIfError(err) fmt.Printf("%s,%s,%d\n", id, name, number) } _, err = db.ExecContext(ctx, "drop table temp_test_table") exitIfError(err) } func exitIfError(err error) { if err != nil { log.Fatal(err) } } // waitForConsistency waits a short time for the SimpleDB domain // to be consistent across all copies. func waitForConsistency() { time.Sleep(500 * time.Millisecond) }
Output: ID009,name-9,81 ID007,name-7,100 ID006,name-6,36 ID005,name-5,25 ID004,name-4,16 ID003,name-3,9 ID002,name-2,4 ID001,name-1,1 ID000,name-0,0
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Connector ¶
type Connector struct { // SimpleDB is the AWS SDK handle used for all SimpleDB operations. SimpleDB simpledbiface.SimpleDBAPI // Schema is used to derive the SimpleDB domain name from the // table name in the SQL. If Schema is not blank, then it is // prefixed in front of any table name with a period. So if // Schema is "dev" and table name is "tbl" then the corresponding // SimpleDB domain would be "dev.tbl". Schema string // Synonyms is a map of table names to their corresponding SimpleDB // domain names. Useful in an environment where the SimpleDB domains // are created by CloudFormation and have randomly generated names. // Create an entry in Synonym and use a constant table name in the SQL. // // If a table name has an entry in Synonyms, Schema is ignored. Synonyms map[string]string }
Connector implements the driver.Connector interface, and is useful for passing to the sql.OpenDB function.
Directories
¶
Path | Synopsis |
---|---|
internal
|
|
lex
Package lex implements a simple lexical scanner for SQL statements.
|
Package lex implements a simple lexical scanner for SQL statements. |
parse
Package parse parses SQL statements for the SimpleDB driver.
|
Package parse parses SQL statements for the SimpleDB driver. |
Click to show internal directories.
Click to hide internal directories.