/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
	"os"

	"dyproxy/providers/db"

	"github.com/spf13/cobra"
)

// initCmd represents the init command
var initCmd = &cobra.Command{
	Use:   "init",
	Short: "init db",
	RunE: func(cmd *cobra.Command, args []string) error {
		db, err := db.Connect("")
		if err != nil {
			return err
		}
		defer db.Close()

		initSql, _ := os.ReadFile("init.sql")
		_, err = db.Exec(string(initSql))
		if err != nil {
			return err
		}

		return nil
	},
}

func init() {
	rootCmd.AddCommand(initCmd)
}
