Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined: sql.NewPrimaryKeySchema #703

Closed
Rock-Lee-520 opened this issue Jan 1, 2022 · 0 comments
Closed

undefined: sql.NewPrimaryKeySchema #703

Rock-Lee-520 opened this issue Jan 1, 2022 · 0 comments

Comments

@Rock-Lee-520
Copy link

Rock-Lee-520 commented Jan 1, 2022

./mysql.go:47:38: undefined: sql.NewPrimaryKeySchema

I use the exmple to run a mysql-server , but it notice that undefined: sql.NewPrimaryKeySchema, what shoud i do ?

whole code :
`package main
import (
"time"
sqle "github.com/dolthub/go-mysql-server"
"github.com/dolthub/go-mysql-server/auth"
"github.com/dolthub/go-mysql-server/memory"
"github.com/dolthub/go-mysql-server/server"
"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/go-mysql-server/sql/information_schema"
)
// Example of how to implement a MySQL server based on a Engine:
//
// // > mysql --host=127.0.0.1 --port=3306 -u root mydb -e "SELECT * FROM mytable" // +----------+-------------------+-------------------------------+---------------------+ // | name | email | phone_numbers | created_at | // +----------+-------------------+-------------------------------+---------------------+ // | John Doe | john@doe.com | ["555-555-555"] | 2018-04-18 09:41:13 | // | John Doe | johnalt@doe.com | [] | 2018-04-18 09:41:13 | // | Jane Doe | jane@doe.com | [] | 2018-04-18 09:41:13 | // | Evil Bob | evilbob@gmail.com | ["555-666-555","666-666-666"] | 2018-04-18 09:41:13 | // +----------+-------------------+-------------------------------+---------------------+ //
func main() {
engine := sqle.NewDefault(
sql.NewDatabaseProvider(
createTestDatabase(),
information_schema.NewInformationSchemaDatabase(),
))
config := server.Config{
Protocol: "tcp",
Address: "localhost:3306",
Auth: auth.NewNativeSingle("root", "", auth.AllPermissions),
}
s, err := server.NewDefaultServer(config, engine)
if err != nil {
panic(err)
}
s.Start()
}
func createTestDatabase() *memory.Database {
const (
dbName = "mydb"
tableName = "mytable"
)
db := memory.NewDatabase(dbName)
table := memory.NewTable(tableName, sql.NewPrimaryKeySchema(sql.Schema{
{Name: "name", Type: sql.Text, Nullable: false, Source: tableName},
{Name: "email", Type: sql.Text, Nullable: false, Source: tableName},
{Name: "phone_numbers", Type: sql.JSON, Nullable: false, Source: tableName},
{Name: "created_at", Type: sql.Timestamp, Nullable: false, Source: tableName},
}))

db.AddTable(tableName, table)
ctx := sql.NewEmptyContext()
table.Insert(ctx, sql.NewRow("John Doe", "john@doe.com", []string{"555-555-555"}, time.Now()))
table.Insert(ctx, sql.NewRow("John Doe", "johnalt@doe.com", []string{}, time.Now()))
table.Insert(ctx, sql.NewRow("Jane Doe", "jane@doe.com", []string{}, time.Now()))
table.Insert(ctx, sql.NewRow("Evil Bob", "evilbob@gmail.com", []string{"555-666-555", "666-666-666"}, time.Now()))
return db

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant