schemagen cli
This commit is contained in:
committed by
Michal Jan Matczuk
parent
979397bc5e
commit
1bfe101568
76
README.md
76
README.md
@@ -103,6 +103,82 @@ t.Log(people)
|
||||
// stdout: [{Michał Matczuk [michal@scylladb.com]}]
|
||||
```
|
||||
|
||||
## Generating table metadata with schemagen
|
||||
|
||||
Installation
|
||||
|
||||
```bash
|
||||
go get -u "github.com/scylladb/gocqlx/v2/cmd/schemagen"
|
||||
```
|
||||
|
||||
Usage:
|
||||
```bash
|
||||
$GOBIN/schemagen [flags]
|
||||
|
||||
Flags:
|
||||
-cluster string
|
||||
a comma-separated list of host:port tuples (default "127.0.0.1")
|
||||
-keyspace string
|
||||
keyspace to inspect (required)
|
||||
-output string
|
||||
the name of the folder to output to (default "models")
|
||||
-pkgname string
|
||||
the name you wish to assign to your generated package (default "models")
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
Running the following command for `examples` keyspace:
|
||||
```bash
|
||||
$GOBIN/schemagen -cluster="127.0.0.1:9042" -keyspace="examples" -output="models" -pkgname="models"
|
||||
```
|
||||
|
||||
Generates `models/models.go` as follows:
|
||||
```go
|
||||
// Code generated by "gocqlx/cmd/schemagen"; DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import "github.com/scylladb/gocqlx/v2/table"
|
||||
|
||||
var PlaylistsMetadata = table.Metadata{
|
||||
Name: "playlists",
|
||||
Columns: []string{
|
||||
"album",
|
||||
"artist",
|
||||
"id",
|
||||
"song_id",
|
||||
"title",
|
||||
},
|
||||
PartKey: []string{
|
||||
"id",
|
||||
},
|
||||
SortKey: []string{
|
||||
"title",
|
||||
"album",
|
||||
"artist",
|
||||
},
|
||||
}
|
||||
var PlaylistsTable = table.New(PlaylistsMetadata)
|
||||
|
||||
var SongsMetadata = table.Metadata{
|
||||
Name: "songs",
|
||||
Columns: []string{
|
||||
"album",
|
||||
"artist",
|
||||
"data",
|
||||
"id",
|
||||
"tags",
|
||||
"title",
|
||||
},
|
||||
PartKey: []string{
|
||||
"id",
|
||||
},
|
||||
SortKey: []string{},
|
||||
}
|
||||
var SongsTable = table.New(SongsMetadata)
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
You can find lots of examples in [example_test.go](https://github.com/scylladb/gocqlx/blob/master/example_test.go).
|
||||
|
||||
Reference in New Issue
Block a user