sql

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FilterSuffix = map[string]string{
	"eq":     "==",
	"ne":     "!=",
	"lt":     "<",
	"lte":    "<=",
	"gt":     ">",
	"gte":    ">=",
	"in":     "IN",
	"not_in": "NOT IN",
}

Functions

func AlterTableAddFieldSQL added in v1.6.1

func AlterTableAddFieldSQL(engine, tableName string, f *models.FieldInfo) ([]string, error)

AlterTableAddFieldSQL returns DDL statements to add physical column(s) for one FieldInfo (locals expand to multiple columns). Engine must match DriverCredentials.Engine (e.g. postgresql, sqlite, libsql, mysql).

func ApplySQLiteConnectionPragmas added in v1.6.1

func ApplySQLiteConnectionPragmas(ctx context.Context, orm *bun.DB, engine, dsn string) error

ApplySQLiteConnectionPragmas sets FK enforcement and performance-related PRAGMAs for SQLite/libsql. For remote Turso/libsql URLs, WAL/mmap are skipped (not applicable or not supported the same way).

func BuildCombinedMetaQuery

func BuildCombinedMetaQuery(keys dataloader.Keys, param *QueryBuilderParam) ([]byte, error)

func BuildCombinedRelationQuery

func BuildCombinedRelationQuery(cfg *models.Config, relationType string, parentModel string, arg *models.CommonSystemParams) (string, []interface{}, *string, error)

func BuildPostgresDSN added in v1.6.0

func BuildPostgresDSN(c *models.DriverCredentials) (string, error)

BuildPostgresDSN builds a libpq URL for pgdriver from credentials (sslmode from SSLMode, default disable).

func CommonDocTransformation

func CommonDocTransformation(model *models.ModelType, local string, result map[string]interface{}, classification *FieldClassification) (*types.DefaultDocumentStructure, error)

func ConditionBuilder

func ConditionBuilder(variable string, args map[string]interface{}, modelType *models.ModelType, sqlArgs *[]interface{}) (map[string][]string, error)

func FilterBuilder

func FilterBuilder(variable string, where map[string]interface{}, modelType *models.ModelType, sqlArgs *[]interface{}) ([]string, error)

func LimitBuilder

func LimitBuilder(param *graphql.ResolveParams) (int, int)

func MediaDocTransformation

func MediaDocTransformation(docType string, result map[string]interface{}) (*models.FileDetails, error)

func PhysicalSQLColumnForSystemRelationField added in v1.6.1

func PhysicalSQLColumnForSystemRelationField(identifier string) string

PhysicalSQLColumnForSystemRelationField maps GraphQL/schema synthetic relation keys (system_<model>_id or system_<model>_as_<knownAs>_id) to physical FK column names created by AddRelationFields (<singular_model>_id). Non-matching identifiers are returned unchanged.

func QuoteMySQLIdent added in v1.6.0

func QuoteMySQLIdent(s string) string

QuoteMySQLIdent returns a MySQL backtick-quoted identifier for DDL.

func QuotePGIdent added in v1.6.0

func QuotePGIdent(s string) string

QuotePGIdent returns a PostgreSQL double-quoted identifier for DDL.

func RootConnectionResolverQueryBuilder

func RootConnectionResolverQueryBuilder(cfg *models.Config, param *models.CommonSystemParams) (string, error)

func RootResolverMediaQueryBuilder

func RootResolverMediaQueryBuilder(param *graphql.ResolveParams) (string, error)

func RootResolverQueryBuilder

func RootResolverQueryBuilder(cfg *models.Config, param *models.CommonSystemParams, returnCount bool) (string, []interface{}, error)

func RunAnalyzeAfterIndexDDL added in v1.6.1

func RunAnalyzeAfterIndexDDL(ctx context.Context, S *SQLDriver)

RunAnalyzeAfterIndexDDL refreshes planner statistics after CREATE INDEX on SQLite-like engines.

func RunSQLiteLikePostDDL added in v1.6.1

func RunSQLiteLikePostDDL(ctx context.Context, S *SQLDriver) error

RunSQLiteLikePostDDL runs ANALYZE on SQLite-like engines after DDL changes.

func SelectBuilder

func SelectBuilder(mv string, local string, modelType *models.ModelType, returnCount bool) []string

func StripArangoEnvelopeKeysForSQLInsert added in v1.6.1

func StripArangoEnvelopeKeysForSQLInsert(data map[string]interface{}, param *models.CommonSystemParams)

StripArangoEnvelopeKeysForSQLInsert removes *DefaultDocumentStructure merge keys that SQL model DDL does not provision (PK is `id`; _key/_id are Arango compat; `type` mirrors the table when no field named type). Shared-DB SaaS only adds a physical tenant_id column (see prosql.ApplyModelPhysicalDDL); tenant_model is document metadata for drivers that store it in JSON/ext, not a SQL column.

Types

type FieldClassification

type FieldClassification struct {
	MultilineFields []string
	DoubleFields    []string
	PictureField    []string
	GalleryField    []string
	ListFields      []string
	RepeatedFields  map[string][]*models.FieldInfo
}

type Meta2

type Meta2 struct {
	ID    string `gorm:"primaryKey;column:id;not null"`
	DocID string `gorm:"column:doc_id;not null"`

	CreatedAt time.Time `gorm:"column:created_at;not null;default:current_date"`
	UpdatedAt time.Time `gorm:"column:updated_at;not null;default:current_date"`

	CreatedBy string `gorm:"column:created_by;not null"`

	UpdatedBy string `gorm:"column:updated_by;not null"`
	Status    string `gorm:"column:status;not null"`
}

type QueryBuilderParam

type QueryBuilderParam struct {
	CollectionName string
	RelationName   string
	Args           map[string]interface{}
	ParentModel    string
	ModelType      *models.ModelType
}

type SQLDriver

type SQLDriver struct {
	Conf             *models.Config
	ORM              *bun.DB
	DriverCredential *models.DriverCredentials
}

func GetSQLDriver

func GetSQLDriver(cfg *models.Config, driverCredentials *models.DriverCredentials) (*SQLDriver, error)

func (*SQLDriver) AddATeamMemberToProject

func (S *SQLDriver) AddATeamMemberToProject(ctx context.Context, req *models.TeamMemberAddRequest) error

func (*SQLDriver) AddAuthAddOns

func (S *SQLDriver) AddAuthAddOns(ctx context.Context, project *models.Project, auth map[string]interface{}) error

func (*SQLDriver) AddDocumentToProject

func (S *SQLDriver) AddDocumentToProject(ctx context.Context, param *models.CommonSystemParams, doc *types.DefaultDocumentStructure) (interface{}, error)

func (*SQLDriver) AddFieldToModel

func (S *SQLDriver) AddFieldToModel(ctx context.Context, param *models.CommonSystemParams, isUpdate bool, parent_field string) (*models.ModelType, error)

func (*SQLDriver) AddModel

func (S *SQLDriver) AddModel(ctx context.Context, project *models.Project, model *models.ModelType) (*models.ProjectSchema, error)

func (*SQLDriver) AddRelationFields

func (S *SQLDriver) AddRelationFields(ctx context.Context, from *models.ConnectionType, to *models.ConnectionType) error

func (*SQLDriver) AddRelationFields_AUTOGEN

func (s *SQLDriver) AddRelationFields_AUTOGEN(ctx context.Context, from *models.ConnectionType, to *models.ConnectionType) error

AddRelationFields creates a relation field (has one or has many) between models.

func (*SQLDriver) AddTeamMetaInfo

func (s *SQLDriver) AddTeamMetaInfo(ctx context.Context, docs []*models.SystemUser) ([]*models.SystemUser, error)

AddTeamMetaInfo adds metadata information for a team in the project.

func (*SQLDriver) AggregateDocOfProject

func (s *SQLDriver) AggregateDocOfProject(ctx context.Context, param *models.CommonSystemParams) (interface{}, error)

AggregateDocOfProject aggregates the documents in the project. Uses the same SQL shape as CountDocOfProject (RootResolverQueryBuilder with returnCount=true) so filters, tenant QueryFilterHook, and role-based predicates match list/count behavior.

func (*SQLDriver) AggregateDocOfProjectBytes

func (s *SQLDriver) AggregateDocOfProjectBytes(ctx context.Context, param *models.CommonSystemParams) ([]byte, error)

AggregateDocOfProjectBytes aggregates the documents in the project and returns it as bytes.

func (*SQLDriver) BuildFieldClassification

func (S *SQLDriver) BuildFieldClassification(_fields []*models.FieldInfo) *FieldClassification

func (*SQLDriver) CheckOneToOneRelationExists

func (s *SQLDriver) CheckOneToOneRelationExists(ctx context.Context, param *models.ConnectDisconnectParam) (bool, error)

CheckOneToOneRelationExists checks if a one-to-one relation exists in the project.

func (*SQLDriver) CheckProjectExists

func (S *SQLDriver) CheckProjectExists(ctx context.Context, projectId string) (bool, error)

func (*SQLDriver) CheckTableOrCollectionExists added in v1.6.0

func (a *SQLDriver) CheckTableOrCollectionExists(ctx context.Context, param *models.CommonSystemParams) (bool, error)

func (*SQLDriver) Close added in v1.6.0

func (p *SQLDriver) Close() error

Close implements database.Closeable so ConnectionManager can release *sql.DB on eviction.

func (*SQLDriver) ConnectBuilder

func (S *SQLDriver) ConnectBuilder(ctx context.Context, root *models.CommonSystemParams) error

func (*SQLDriver) ConvertModel

func (s *SQLDriver) ConvertModel(ctx context.Context, project *models.Project, modelName string) error

ConvertModel converts a model in the project.

func (*SQLDriver) CountDocOfProject

func (S *SQLDriver) CountDocOfProject(ctx context.Context, param *models.CommonSystemParams) (interface{}, error)

func (*SQLDriver) CountDocOfProjectBytes

func (S *SQLDriver) CountDocOfProjectBytes(ctx context.Context, param *models.CommonSystemParams) ([]byte, error)

func (*SQLDriver) CountMedias

func (S *SQLDriver) CountMedias(ctx context.Context, projectId string, param *graphql.ResolveParams) (int, error)

func (*SQLDriver) CountMultiDocumentOfProject

func (f *SQLDriver) CountMultiDocumentOfProject(ctx context.Context, param *models.CommonSystemParams, previewMode bool) (int, error)

func (*SQLDriver) CreateIndex

func (s *SQLDriver) CreateIndex(ctx context.Context, param *models.CommonSystemParams, fieldName string, parent_field string) error

CreateIndex creates an index for a model in the project.

func (*SQLDriver) CreateMediaDocument

func (S *SQLDriver) CreateMediaDocument(ctx context.Context, projectId string, media *models.FileDetails) (*models.FileDetails, error)

func (*SQLDriver) CreateModelTable added in v1.6.0

func (S *SQLDriver) CreateModelTable(ctx context.Context, model *models.ModelType, ifNotExists bool) error

CreateModelTable creates a model table with only an id primary key column. Use ifNotExists to guard against duplicate table errors during provisioning.

func (*SQLDriver) CreateRelation

func (s *SQLDriver) CreateRelation(ctx context.Context, projectId string, relation *models.EdgeRelation) error

CreateRelation creates a relation in the project.

func (*SQLDriver) CreateTableOrCollection added in v1.6.0

func (S *SQLDriver) CreateTableOrCollection(ctx context.Context, param *models.CommonSystemParams, indexes []string) error

CreateTableOrCollection creates the physical table for param.Model only. Project bootstrap (database + meta + media) is handled by InitProjectBase.

func (*SQLDriver) DeleteDocumentFromProject

func (S *SQLDriver) DeleteDocumentFromProject(ctx context.Context, param *models.CommonSystemParams) error

func (*SQLDriver) DeleteDocumentRelation

func (s *SQLDriver) DeleteDocumentRelation(ctx context.Context, param *models.CommonSystemParams) error

DeleteDocumentRelation deletes all relations or data in pivot tables from the project.

func (*SQLDriver) DeleteDocumentsFromProject

func (s *SQLDriver) DeleteDocumentsFromProject(ctx context.Context, param *models.CommonSystemParams) error

DeleteDocumentsFromProject deletes multiple documents from the project.

func (*SQLDriver) DeleteMediaFile

func (s *SQLDriver) DeleteMediaFile(ctx context.Context, param models.CommonSystemParams) error

DeleteMediaFile deletes a media file from the project.

func (*SQLDriver) DeleteProject

func (S *SQLDriver) DeleteProject(ctx context.Context, projectId string) error

DeleteProject removes project storage: dedicated database for PostgreSQL / MySQL, or core tables for SQLite.

func (*SQLDriver) DeleteProjectBase added in v1.6.0

func (S *SQLDriver) DeleteProjectBase(ctx context.Context, param *models.CommonSystemParams) error

DeleteProjectBase drops meta and media in the current database (SQLite file-backed layout).

func (*SQLDriver) DeleteRelation

func (s *SQLDriver) DeleteRelation(ctx context.Context, param *models.ConnectDisconnectParam, id string) error

DeleteRelation deletes a relation in the project.

func (*SQLDriver) DeleteRelationDocuments

func (S *SQLDriver) DeleteRelationDocuments(ctx context.Context, projectId string, from *models.ConnectionType, to *models.ConnectionType) error

func (*SQLDriver) DeleteRelationDocuments_AUTOGEN

func (s *SQLDriver) DeleteRelationDocuments_AUTOGEN(ctx context.Context, projectId string, from *models.ConnectionType, to *models.ConnectionType) error

DeleteRelationDocuments drops pivot tables, relation keys, or collection tables and all documents within them.

func (*SQLDriver) DisconnectBuilder

func (S *SQLDriver) DisconnectBuilder(ctx context.Context, param *models.CommonSystemParams) error

func (*SQLDriver) DropField

func (S *SQLDriver) DropField(ctx context.Context, param *models.CommonSystemParams) error

func (*SQLDriver) DropIndex

func (s *SQLDriver) DropIndex(ctx context.Context, param *models.CommonSystemParams, indexName string) error

DropIndex drops an index from a model in the project.

func (*SQLDriver) DropModel

func (s *SQLDriver) DropModel(ctx context.Context, project *models.Project, modelName string) error

DropModel drops a model from the project.

func (*SQLDriver) DuplicateModel

func (s *SQLDriver) DuplicateModel(ctx context.Context, project *models.Project, modelName, newName string) (*models.ProjectSchema, error)

DuplicateModel duplicates a model in the project.

func (*SQLDriver) EnsureMetaMediaTables added in v1.6.0

func (S *SQLDriver) EnsureMetaMediaTables(ctx context.Context) error

EnsureMetaMediaTables creates meta and media tables when missing (idempotent).

func (*SQLDriver) EnsureModelUserFieldColumns added in v1.6.1

func (S *SQLDriver) EnsureModelUserFieldColumns(ctx context.Context, model *models.ModelType) error

EnsureModelUserFieldColumns runs ALTER TABLE ADD for each top-level model.Fields entry so physical tables match schema (e.g. SaaS tenant catalogue name/logo after CreateModelTable created id-only table). Idempotent: duplicate column errors are ignored.

func (*SQLDriver) EnsureRelationArtifactsFromSchema added in v1.6.1

func (S *SQLDriver) EnsureRelationArtifactsFromSchema(ctx context.Context, modelsList []*models.ModelType) error

EnsureRelationArtifactsFromSchema creates missing SQL artifacts for schema-declared relations (has_many↔has_many pivot tables via AddRelationFields). Idempotent: pivot CREATE uses IF NOT EXISTS. Needed when projects were authored on Arango (edges only) or bootstrap only created model tables.

func (*SQLDriver) EnsureSchemaOptimizationsV1 added in v1.6.1

func (S *SQLDriver) EnsureSchemaOptimizationsV1(ctx context.Context) error

EnsureSchemaOptimizationsV1 applies idempotent secondary indexes and document_revisions bootstrap for project databases created before meta/media secondary indexes existed. Uses _apito_db_meta sentinel so work runs at most once per database.

func (*SQLDriver) GetAllRelationDocumentsOfSingleDocument

func (S *SQLDriver) GetAllRelationDocumentsOfSingleDocument(ctx context.Context, from string, arg *models.CommonSystemParams) (interface{}, error)

func (*SQLDriver) GetAllRelationDocumentsOfSingleDocument_AUTOGEN

func (s *SQLDriver) GetAllRelationDocumentsOfSingleDocument_AUTOGEN(ctx context.Context, from string, arg *models.CommonSystemParams) (interface{}, error)

GetAllRelationDocumentsOfSingleDocument retrieves all relation data of a single document by ID.

func (*SQLDriver) GetLoggedInProjectUser

func (s *SQLDriver) GetLoggedInProjectUser(ctx context.Context, param *models.CommonSystemParams) (*types.DefaultDocumentStructure, error)

GetLoggedInProjectUser retrieves the logged-in user profile for the project.

func (*SQLDriver) GetProjectUser

func (s *SQLDriver) GetProjectUser(ctx context.Context, phone, email, projectId string) (*types.DefaultDocumentStructure, error)

GetProjectUser retrieves a user profile by phone, email, and project ID.

func (*SQLDriver) GetProjectUsers

func (s *SQLDriver) GetProjectUsers(ctx context.Context, projectId string, keys []string) (map[string]*types.DefaultDocumentStructure, error)

GetProjectUsers retrieves metadata for multiple users in the project.

func (*SQLDriver) GetRelationDocument

func (s *SQLDriver) GetRelationDocument(ctx context.Context, param *models.ConnectDisconnectParam) (*models.EdgeRelation, error)

GetRelationDocument retrieves a relation document by ID.

func (*SQLDriver) GetRelationIds

func (s *SQLDriver) GetRelationIds(ctx context.Context, param *models.ConnectDisconnectParam) ([]string, error)

GetRelationIds retrieves the IDs of every document related to a document.

func (*SQLDriver) GetSingleProjectDocument

func (S *SQLDriver) GetSingleProjectDocument(ctx context.Context, param *models.CommonSystemParams) (*types.DefaultDocumentStructure, error)

func (*SQLDriver) GetSingleProjectDocumentBytes

func (S *SQLDriver) GetSingleProjectDocumentBytes(ctx context.Context, param *models.CommonSystemParams) ([]byte, error)

func (*SQLDriver) GetSingleProjectDocumentRevisions

func (s *SQLDriver) GetSingleProjectDocumentRevisions(ctx context.Context, param *models.CommonSystemParams) ([]*models.DocumentRevisionHistory, error)

GetSingleProjectDocumentRevisions retrieves the revision history of a single project document by ID.

func (*SQLDriver) GetSingleRawDocumentFromProject

func (S *SQLDriver) GetSingleRawDocumentFromProject(ctx context.Context, param *models.CommonSystemParams) (interface{}, error)

func (*SQLDriver) InitProjectBase added in v1.6.0

func (S *SQLDriver) InitProjectBase(ctx context.Context, param *models.CommonSystemParams, indexes []string) error

InitProjectBase creates the per-project database (PostgreSQL / MySQL) when needed, reconnects, and ensures meta + media tables. For SQLite it only ensures meta + media in the current file.

func (*SQLDriver) ListMedias

func (S *SQLDriver) ListMedias(ctx context.Context, projectId string, param *graphql.ResolveParams) ([]*models.FileDetails, error)

func (*SQLDriver) NewInsertableRelations

func (s *SQLDriver) NewInsertableRelations(ctx context.Context, param *models.ConnectDisconnectParam) ([]string, error)

NewInsertableRelations retrieves new insertable relations in the project.

func (*SQLDriver) Ping added in v1.1.4

func (p *SQLDriver) Ping() error

func (*SQLDriver) QueryMultiDocumentOfProject

func (S *SQLDriver) QueryMultiDocumentOfProject(ctx context.Context, param *models.CommonSystemParams) ([]*types.DefaultDocumentStructure, error)

func (*SQLDriver) QueryMultiDocumentOfProjectBytes

func (S *SQLDriver) QueryMultiDocumentOfProjectBytes(ctx context.Context, param *models.CommonSystemParams) ([]byte, error)

func (*SQLDriver) RelationshipDataLoader

func (S *SQLDriver) RelationshipDataLoader(ctx context.Context, param *models.CommonSystemParams, connection map[string]interface{}) (interface{}, error)

func (*SQLDriver) RelationshipDataLoaderBytes

func (S *SQLDriver) RelationshipDataLoaderBytes(ctx context.Context, param *models.CommonSystemParams, connection map[string]interface{}) ([]byte, error)

func (*SQLDriver) RemoveATeamMemberFromProject

func (S *SQLDriver) RemoveATeamMemberFromProject(ctx context.Context, projectId string, memberId string) error

func (*SQLDriver) RemoveAuthAddOns

func (a *SQLDriver) RemoveAuthAddOns(ctx context.Context, project *models.Project, option map[string]interface{}) error

func (*SQLDriver) RenameField

func (s *SQLDriver) RenameField(ctx context.Context, oldFieldName string, repeatedFieldGroup string, param *models.CommonSystemParams) error

RenameField renames a field in a model along with its data key.

func (*SQLDriver) RenameModel

func (s *SQLDriver) RenameModel(ctx context.Context, project *models.Project, modelName, newName string) error

RenameModel renames a model in the project.

func (*SQLDriver) TransferProject

func (S *SQLDriver) TransferProject(ctx context.Context, userId, from, to string) error

func (*SQLDriver) UpdateDocumentOfProject

func (S *SQLDriver) UpdateDocumentOfProject(ctx context.Context, param *models.CommonSystemParams, doc *types.DefaultDocumentStructure, replace bool) error

Jump to

Keyboard shortcuts

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