queries

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: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Connection = graphql.Field{
	Type: types.ConnectionType,
	Args: graphql.FieldConfigArgument{
		"connectionId": &graphql.ArgumentConfig{
			Type: graphql.ID,
		},
	},
	Resolve: func(p graphql.ResolveParams) (interface{}, error) {
		connection, err := types.GetConnectionFromDB(p.Context, p.Args["connectionId"].(string))
		if err != nil {
			return connection, err
		}
		if _, err := client.NewClient(connection.DSN); err != nil {
			return connection, err
		}

		connection.Connected = true
		return connection, err
	},
}
View Source
var Connections = graphql.Field{
	Type: graphql.NewList(types.ConnectionType),
	Resolve: func(p graphql.ResolveParams) (interface{}, error) {
		var bunConnections []models.Connection

		if err := db.DB.NewSelect().
			Model(&bunConnections).
			Scan(p.Context); err != nil {
			return nil, err
		}
		var connections []*types.Connection

		for _, bc := range bunConnections {
			connections = append(connections, types.ConvertBunModelToConnection(&bc))
		}

		return connections, nil
	},
}
View Source
var RedisKeys = graphql.Field{
	Type: graphql.NewObject(graphql.ObjectConfig{
		Name: "RedisScanResult",
		Fields: graphql.Fields{
			"cursor": &graphql.Field{
				Type: graphql.Int,
			},
			"keys": &graphql.Field{
				Type: graphql.NewList(types.RedisRecordType),
			},
		},
	}),
	Args: graphql.FieldConfigArgument{
		"cursor": &graphql.ArgumentConfig{
			Type:         graphql.Int,
			DefaultValue: 0,
		},
		"pattern": &graphql.ArgumentConfig{
			Type:         graphql.String,
			DefaultValue: "",
		},
		"count": &graphql.ArgumentConfig{
			Type:         graphql.Int,
			DefaultValue: 0,
		},
	},
	Resolve: func(p graphql.ResolveParams) (interface{}, error) {
		connection := p.Context.Value(constants.CurrentConnectionContextKey).(*types.Connection)
		client := connection.Client.(*client.ClientRedis)
		var records []types.RedisRecord

		keys, cursor, err := client.Client.
			Scan(p.Context, uint64(p.Args["cursor"].(int)), "*"+p.Args["pattern"].(string)+"*", int64(p.Args["count"].(int))).
			Result()

		if err != nil {
			return nil, err
		}

		records = x.Map(keys, func(k string) types.RedisRecord {
			return types.RedisRecord{
				Key: k,
			}
		})

		return RedisScanResult{
			Cursor: cursor,
			Keys:   records,
		}, nil
	},
}
View Source
var RedisValue = graphql.Field{
	Type: graphql.NewNonNull(types.RedisRecordType),
	Args: graphql.FieldConfigArgument{
		"key": &graphql.ArgumentConfig{
			Type: graphql.NewNonNull(graphql.String),
		},
	},
	Resolve: func(p graphql.ResolveParams) (interface{}, error) {
		connection := p.Context.Value(constants.CurrentConnectionContextKey).(*types.Connection)
		client := connection.Client.(*client.ClientRedis)
		k := p.Args["key"].(string)
		t, err := client.Client.Type(p.Context, k).Result()
		if err != nil {
			return nil, err
		}
		v, e, err := client.GetWithExpiration(p.Context, k)
		if err != nil {
			return nil, err
		}

		return types.RedisRecord{
			Key:      k,
			Type:     t,
			Value:    v,
			ExpireAt: e,
		}, nil
	},
}
View Source
var SQLTable = graphql.Field{
	Type: types.SQLTableType,
	Args: graphql.FieldConfigArgument{
		"schema": &graphql.ArgumentConfig{
			Type: graphql.NewNonNull(graphql.String),
		},
		"name": &graphql.ArgumentConfig{
			Type: graphql.NewNonNull(graphql.String),
		},
	},
	Resolve: func(p graphql.ResolveParams) (interface{}, error) {
		schema := p.Args["schema"].(string)
		name := p.Args["name"].(string)

		return client.TableSQL{
			Schema: schema,
			Name:   name,
		}, nil
	},
}
View Source
var SQLTables = graphql.Field{
	Type: graphql.NewList(types.SQLTableType),
	Resolve: func(p graphql.ResolveParams) (interface{}, error) {
		connection := p.Context.Value(constants.CurrentConnectionContextKey).(*types.Connection)

		return connection.Client.Tables(p.Context)
	},
}

Functions

This section is empty.

Types

type RedisScanResult

type RedisScanResult struct {
	Cursor uint64              `json:"cursor"`
	Keys   []types.RedisRecord `json:"keys"`
}

Jump to

Keyboard shortcuts

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