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

feat: prisma-client-go support added #384

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions database/console/prisma/db_exec_command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package prisma

import (
"strings"

"github.com/goravel/framework/contracts/console"
"github.com/goravel/framework/contracts/console/command"
"github.com/steebchen/prisma-client-go/cli"
)

type DBExecCommand struct{}

func NewDBExecCommand() *DBExecCommand {
return &DBExecCommand{}

Check warning on line 14 in database/console/prisma/db_exec_command.go

View check run for this annotation

Codecov / codecov/patch

database/console/prisma/db_exec_command.go#L13-L14

Added lines #L13 - L14 were not covered by tests
}

// Signature The name and signature of the console command.
func (receiver *DBExecCommand) Signature() string {
return "prisma:db:exec"

Check warning on line 19 in database/console/prisma/db_exec_command.go

View check run for this annotation

Codecov / codecov/patch

database/console/prisma/db_exec_command.go#L18-L19

Added lines #L18 - L19 were not covered by tests
}

// Description The console command description.
func (receiver *DBExecCommand) Description() string {
return "🏋️ Manage your database schema and lifecycle during development."

Check warning on line 24 in database/console/prisma/db_exec_command.go

View check run for this annotation

Codecov / codecov/patch

database/console/prisma/db_exec_command.go#L23-L24

Added lines #L23 - L24 were not covered by tests
}

// Extend The console command extend.
func (receiver *DBExecCommand) Extend() command.Extend {
return command.Extend{
Category: "prisma",
}

Check warning on line 31 in database/console/prisma/db_exec_command.go

View check run for this annotation

Codecov / codecov/patch

database/console/prisma/db_exec_command.go#L28-L31

Added lines #L28 - L31 were not covered by tests
}

// Handle Execute the console command
func (r *DBExecCommand) Handle(ctx console.Context) error {
args := ctx.Argument(0)
cliCmds := append([]string{"db", "execute"}, strings.Split(args, " ")...)
return cli.Run(cliCmds, true)

}
29 changes: 29 additions & 0 deletions database/console/prisma/db_exec_command_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package prisma

import (
"testing"

consolemocks "github.com/goravel/framework/mocks/console"
"github.com/stretchr/testify/assert"
)

func TestDBExecCommand(t *testing.T) {
// make an instance of db exec command struct
dbec := &DBExecCommand{}
mockCtx := &consolemocks.Context{}

// no args
mockCtx.On("Argument", 0).Return("").Once()
assert.Error(t, dbec.Handle(mockCtx))

// no --file
mockCtx.On("Argument", 0).Return("--file").Once()
assert.Error(t, dbec.Handle(mockCtx))

// --stdin without sql in stdin
mockCtx.On("Argument", 0).Return("--stdin").Once()
assert.Error(t, dbec.Handle(mockCtx))

mockCtx.On("Argument", 0).Return("-h").Once()
assert.Nil(t, dbec.Handle(mockCtx))
}
39 changes: 39 additions & 0 deletions database/console/prisma/db_pull_command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package prisma

import (
"strings"

"github.com/goravel/framework/contracts/console"
"github.com/goravel/framework/contracts/console/command"
"github.com/steebchen/prisma-client-go/cli"
)

type DBPullCommand struct{}

func NewDBPullCommand() *DBPullCommand {
return &DBPullCommand{}

Check warning on line 14 in database/console/prisma/db_pull_command.go

View check run for this annotation

Codecov / codecov/patch

database/console/prisma/db_pull_command.go#L13-L14

Added lines #L13 - L14 were not covered by tests
}

// Signature The name and signature of the console command.
func (receiver *DBPullCommand) Signature() string {
return "prisma:db:pull"

Check warning on line 19 in database/console/prisma/db_pull_command.go

View check run for this annotation

Codecov / codecov/patch

database/console/prisma/db_pull_command.go#L18-L19

Added lines #L18 - L19 were not covered by tests
}

// Description The console command description.
func (receiver *DBPullCommand) Description() string {
return "Pull the state from the database to the Prisma schema using introspection"

Check warning on line 24 in database/console/prisma/db_pull_command.go

View check run for this annotation

Codecov / codecov/patch

database/console/prisma/db_pull_command.go#L23-L24

Added lines #L23 - L24 were not covered by tests
}

// Extend The console command extend.
func (receiver *DBPullCommand) Extend() command.Extend {
return command.Extend{
Category: "prisma",
}

Check warning on line 31 in database/console/prisma/db_pull_command.go

View check run for this annotation

Codecov / codecov/patch

database/console/prisma/db_pull_command.go#L28-L31

Added lines #L28 - L31 were not covered by tests
}

// Handle Execute the console command
func (r *DBPullCommand) Handle(ctx console.Context) error {
args := ctx.Argument(0)
cliCmd := append([]string{"db", "pull"}, strings.Split(args, " ")...)
return cli.Run(cliCmd, true)
}
28 changes: 28 additions & 0 deletions database/console/prisma/db_pull_command_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package prisma

import (
"testing"

consolemocks "github.com/goravel/framework/mocks/console"
"github.com/stretchr/testify/assert"
)

func TestDBPullCommand(t *testing.T) {
// make an instance of db pull command struct
dbpc := &DBPullCommand{}
mockCtx := &consolemocks.Context{}

// init prisma
handleInitPrisma(mockCtx, t)
defer removePrisma()

// fill schema.prisma with data
fillPrismaSchema()

// runs into error because it needs data in database
// otherwise there's no error
// used assert.Error to pass test
mockCtx.On("Argument", 0).Return("").Once()
assert.Error(t, dbpc.Handle(mockCtx))

}
40 changes: 40 additions & 0 deletions database/console/prisma/db_push_command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package prisma

import (
"strings"

"github.com/goravel/framework/contracts/console"
"github.com/goravel/framework/contracts/console/command"
"github.com/steebchen/prisma-client-go/cli"
)

type DBPushCommand struct{}

func NewDBPushCommand() *DBPullCommand {
return &DBPullCommand{}
}

// Signature The name and signature of the console command.
func (receiver *DBPushCommand) Signature() string {
return "prisma:db:pull"

Check warning on line 19 in database/console/prisma/db_push_command.go

View check run for this annotation

Codecov / codecov/patch

database/console/prisma/db_push_command.go#L18-L19

Added lines #L18 - L19 were not covered by tests
}

// Description The console command description.
func (receiver *DBPushCommand) Description() string {
return "🙌 Push the state from your Prisma schema to your database (no migrations change)"

Check warning on line 24 in database/console/prisma/db_push_command.go

View check run for this annotation

Codecov / codecov/patch

database/console/prisma/db_push_command.go#L23-L24

Added lines #L23 - L24 were not covered by tests
}

// Extend The console command extend.
func (receiver *DBPushCommand) Extend() command.Extend {
return command.Extend{
Category: "prisma",
}

Check warning on line 31 in database/console/prisma/db_push_command.go

View check run for this annotation

Codecov / codecov/patch

database/console/prisma/db_push_command.go#L28-L31

Added lines #L28 - L31 were not covered by tests
}

// Handle Execute the console command
func (r *DBPushCommand) Handle(ctx console.Context) error {
args := ctx.Argument(0)
cliCmd := append([]string{"db", "push"}, strings.Split(args, " ")...)
return cli.Run(cliCmd, true)

Check warning on line 39 in database/console/prisma/db_push_command.go

View check run for this annotation

Codecov / codecov/patch

database/console/prisma/db_push_command.go#L35-L39

Added lines #L35 - L39 were not covered by tests
}
26 changes: 26 additions & 0 deletions database/console/prisma/db_push_command_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package prisma

import (
"testing"

consolemocks "github.com/goravel/framework/mocks/console"
"github.com/stretchr/testify/assert"
)

func TestDBPushCommand(t *testing.T) {
// make an instance of db pull command struct
dbpc := NewDBPushCommand()
mockCtx := &consolemocks.Context{}

// init prisma project
handleInitPrisma(mockCtx, t)
defer removePrisma()

// fill schema.prisma with data
fillPrismaSchema()

// requires at least one existing table at database to execute push
mockCtx.On("Argument", 0).Return("").Once()
assert.Error(t, dbpc.Handle(mockCtx))

}
40 changes: 40 additions & 0 deletions database/console/prisma/db_seed_command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package prisma

import (
"strings"

"github.com/goravel/framework/contracts/console"
"github.com/goravel/framework/contracts/console/command"
"github.com/steebchen/prisma-client-go/cli"
)

type DBSeedCommand struct{}

func NewDBSeedCommand() *DBSeedCommand {
return &DBSeedCommand{}
}

// Signature The name and signature of the console command.
func (receiver *DBSeedCommand) Signature() string {
return "prisma:db:seed"

Check warning on line 19 in database/console/prisma/db_seed_command.go

View check run for this annotation

Codecov / codecov/patch

database/console/prisma/db_seed_command.go#L18-L19

Added lines #L18 - L19 were not covered by tests
}

// Description The console command description.
func (receiver *DBSeedCommand) Description() string {
return "🙌 Seed your database"

Check warning on line 24 in database/console/prisma/db_seed_command.go

View check run for this annotation

Codecov / codecov/patch

database/console/prisma/db_seed_command.go#L23-L24

Added lines #L23 - L24 were not covered by tests
}

// Extend The console command extend.
func (receiver *DBSeedCommand) Extend() command.Extend {
return command.Extend{
Category: "prisma",
}

Check warning on line 31 in database/console/prisma/db_seed_command.go

View check run for this annotation

Codecov / codecov/patch

database/console/prisma/db_seed_command.go#L28-L31

Added lines #L28 - L31 were not covered by tests
}

// Handle Execute the console command
func (r *DBSeedCommand) Handle(ctx console.Context) error {
args := ctx.Argument(0)
cliCmd := append([]string{"db", "push"}, strings.Split(args, " ")...)
return cli.Run(cliCmd, true)

}
25 changes: 25 additions & 0 deletions database/console/prisma/db_seed_command_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package prisma

import (
"testing"

consolemocks "github.com/goravel/framework/mocks/console"
"github.com/stretchr/testify/assert"
)

func TestDBSeedCommand(t *testing.T) {
dbsc := NewDBSeedCommand()
mockCtx := &consolemocks.Context{}

// init prisma before any test
handleInitPrisma(mockCtx, t)

// fill schema.prisma with data
fillPrismaSchema()
defer removePrisma()

// test on user model
mockCtx.On("Argument", 0).Return("")
assert.Nil(t, dbsc.Handle(mockCtx))

}
40 changes: 40 additions & 0 deletions database/console/prisma/debug_command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package prisma

import (
"strings"

"github.com/goravel/framework/contracts/console"
"github.com/goravel/framework/contracts/console/command"
"github.com/steebchen/prisma-client-go/cli"
)

type DebugCommand struct{}

func NewDebugCommand() *DebugCommand {
return &DebugCommand{}
}

// Signature The name and signature of the console command.
func (receiver *DebugCommand) Signature() string {
return "prisma:debug"

Check warning on line 19 in database/console/prisma/debug_command.go

View check run for this annotation

Codecov / codecov/patch

database/console/prisma/debug_command.go#L18-L19

Added lines #L18 - L19 were not covered by tests
}

// Description The console command description.
func (receiver *DebugCommand) Description() string {
return "Print information helpful for debugging and bug reports"

Check warning on line 24 in database/console/prisma/debug_command.go

View check run for this annotation

Codecov / codecov/patch

database/console/prisma/debug_command.go#L23-L24

Added lines #L23 - L24 were not covered by tests
}

// Extend The console command extend.
func (receiver *DebugCommand) Extend() command.Extend {
return command.Extend{
Category: "prisma",
}

Check warning on line 31 in database/console/prisma/debug_command.go

View check run for this annotation

Codecov / codecov/patch

database/console/prisma/debug_command.go#L28-L31

Added lines #L28 - L31 were not covered by tests
}

// Handle Execute the console command
func (r *DebugCommand) Handle(ctx console.Context) error {
args := ctx.Argument(0)
cliCmds := []string{"debug"}
cliCmds = append(cliCmds, strings.Split(args, " ")...)
return cli.Run(cliCmds, true)
}
20 changes: 20 additions & 0 deletions database/console/prisma/debug_command_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package prisma

import (
"testing"

consolemocks "github.com/goravel/framework/mocks/console"
"github.com/stretchr/testify/assert"
)

func TestDebugCommand(t *testing.T) {
debugCmd := NewDebugCommand()
mockCtx := &consolemocks.Context{}

// init prisma
handleInitPrisma(mockCtx, t)
defer removePrisma()

// check debug info
assert.Nil(t, debugCmd.Handle(mockCtx))
}
40 changes: 40 additions & 0 deletions database/console/prisma/format_command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package prisma

import (
"strings"

"github.com/goravel/framework/contracts/console"
"github.com/goravel/framework/contracts/console/command"
"github.com/steebchen/prisma-client-go/cli"
)

type FormatCommand struct{}

func NewFormatCommand() *FormatCommand {
return &FormatCommand{}
}

// Signature The name and signature of the console command.
func (receiver *FormatCommand) Signature() string {
return "prisma:format"

Check warning on line 19 in database/console/prisma/format_command.go

View check run for this annotation

Codecov / codecov/patch

database/console/prisma/format_command.go#L18-L19

Added lines #L18 - L19 were not covered by tests
}

// Description The console command description.
func (receiver *FormatCommand) Description() string {
return "Format a Prisma schema"

Check warning on line 24 in database/console/prisma/format_command.go

View check run for this annotation

Codecov / codecov/patch

database/console/prisma/format_command.go#L23-L24

Added lines #L23 - L24 were not covered by tests
}

// Extend The console command extend.
func (receiver *FormatCommand) Extend() command.Extend {
return command.Extend{
Category: "prisma",
}

Check warning on line 31 in database/console/prisma/format_command.go

View check run for this annotation

Codecov / codecov/patch

database/console/prisma/format_command.go#L28-L31

Added lines #L28 - L31 were not covered by tests
}

// Handle Execute the console command
func (r *FormatCommand) Handle(ctx console.Context) error {
args := ctx.Argument(0)
cliCmds := []string{"debug"}
cliCmds = append(cliCmds, strings.Split(args, " ")...)
return cli.Run(cliCmds, true)
}
Loading
Loading