types

package
v1.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConnectionType = graphql.NewObject(graphql.ObjectConfig{
	Name: "Connection",
	Fields: graphql.Fields{
		"id": &graphql.Field{
			Type: graphql.ID,
		},
		"name": &graphql.Field{
			Type: graphql.String,
		},
		"dsn": &graphql.Field{
			Type: graphql.NewNonNull(graphql.String),
		},
		"connected": &graphql.Field{
			Type: graphql.NewNonNull(graphql.Boolean),
		},
	},
})
View Source
var RedisRecordType = graphql.NewObject(graphql.ObjectConfig{
	Name: "RedisRecord",
	Fields: graphql.Fields{
		"key": &graphql.Field{
			Type: graphql.ID,
		},
		"type": &graphql.Field{
			Type: RedisRecordTypeEnum,
		},
		"value": &graphql.Field{
			Type: scalars.JsonType,
		},
		"expireAt": &graphql.Field{
			Type: graphql.Float,
		},
	},
})
View Source
var RedisRecordTypeEnum = graphql.NewEnum(graphql.EnumConfig{
	Name: "RedisRecordType",
	Values: graphql.EnumValueConfigMap{
		"STRING": &graphql.EnumValueConfig{
			Value: "string",
		},
		"HASH": &graphql.EnumValueConfig{
			Value: "hash",
		},
		"LIST": &graphql.EnumValueConfig{
			Value: "list",
		},
		"SET": &graphql.EnumValueConfig{
			Value: "set",
		},
		"ZSET": &graphql.EnumValueConfig{
			Value: "zset",
		},
	},
})
View Source
var SQLColumnType = graphql.NewObject(graphql.ObjectConfig{
	Name: "SQLColumn",
	Fields: graphql.Fields{
		"name": &graphql.Field{
			Type: graphql.String,
		},
		"dataType": &graphql.Field{
			Type: graphql.String,
		},
	},
})
View Source
var SQLRecordsType = graphql.NewObject(graphql.ObjectConfig{
	Name: "SQLRecords",
	Fields: graphql.Fields{
		"rows": &graphql.Field{
			Type: scalars.JsonType,
		},
		"rowCount": &graphql.Field{
			Type: graphql.Int,
		},
	},
})
View Source
var SQLTableType = graphql.NewObject(graphql.ObjectConfig{
	Name: "SQLTable",
	Fields: graphql.Fields{
		"schema": &graphql.Field{
			Type: graphql.String,
		},
		"name": &graphql.Field{
			Type: graphql.String,
		},
		"columns": &graphql.Field{
			Type: graphql.NewList(SQLColumnType),
			Resolve: func(p graphql.ResolveParams) (interface{}, error) {
				src := p.Source.(client.TableSQL)
				connection := p.Context.Value(constants.CurrentConnectionContextKey).(*Connection)

				return connection.Client.Columns(p.Context, src.Schema, src.Name)
			},
		},
		"records": &graphql.Field{
			Type: SQLRecordsType,
			Args: graphql.FieldConfigArgument{
				"limit": &graphql.ArgumentConfig{
					Type: graphql.NewNonNull(graphql.Int),
				},
				"offset": &graphql.ArgumentConfig{
					Type: graphql.NewNonNull(graphql.Int),
				},
				"where": &graphql.ArgumentConfig{
					Type:         graphql.String,
					DefaultValue: "",
				},
			},
			Resolve: func(p graphql.ResolveParams) (interface{}, error) {
				src := p.Source.(client.TableSQL)
				connection := p.Context.Value(constants.CurrentConnectionContextKey).(*Connection)
				db, _ := connection.Client.GetDB()

				builder := db.NewSelect().Table(src.Schema + "." + src.Name)
				where := p.Args["where"].(string)

				if where != "" {
					builder = builder.Where(where)
				}

				var r []map[string]any
				count, err := builder.
					Limit(p.Args["limit"].(int)).
					Offset(p.Args["offset"].(int)).
					ScanAndCount(p.Context, &r)

				if err != nil {
					return nil, err
				}

				x.ParseSQL(r)

				return SQLRecords{
					Rows:     r,
					RowCount: count,
				}, nil
			},
		},
	},
})

Functions

This section is empty.

Types

type Connection

type Connection struct {
	ID        int64         `json:"id"`
	Name      *string       `json:"name"`
	DSN       string        `json:"dsn"`
	Connected bool          `json:"connected"`
	Client    client.Client `json:"-"`
}

func ConvertBunModelToConnection

func ConvertBunModelToConnection(v *models.Connection) *Connection

func GetConnectionFromDB

func GetConnectionFromDB(ctx context.Context, id string) (*Connection, error)

type RedisRecord

type RedisRecord struct {
	Key      string `json:"key"`
	Type     string `json:"type"`
	Value    any    `json:"value"`
	ExpireAt *int64 `json:"expireAt"`
}

type SQLRecords added in v1.1.0

type SQLRecords struct {
	Rows     []map[string]any `json:"rows"`
	RowCount int              `json:"rowCount"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL