postgres

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

func AlterTableAddFieldSQL

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 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 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

func PhysicalSQLColumnForSystemRelationField(identifier string, modelType *models.ModelType) string

PhysicalSQLColumnForSystemRelationField maps GraphQL/schema synthetic relation keys (system_<model>_id or system_<model>_as_<known>_id) to physical FK column names created by AddRelationFields. Pass modelType when available so legacy collapsed ids (e.g. system_foodcategory_id vs system_food_category_id) resolve to the same SQL column.

func PreflightSQLiteRelationParentTablesForAddRelation

func PreflightSQLiteRelationParentTablesForAddRelation(ctx context.Context, db bun.IDB, engine string, from, to *models.ConnectionType) error

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

func RunAnalyzeAfterIndexDDL(context.Context, *Driver)

func RunSQLiteLikePostDDL

func RunSQLiteLikePostDDL(context.Context, *Driver) error

func SelectBuilder

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

func StripArangoEnvelopeKeysForSQLInsert

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 Driver

type Driver struct {
	sqlcommon.Driver
}

Driver is the PostgreSQL project SQL driver.

func GetDriver

func GetDriver(cfg *models.Config, cred *models.DriverCredentials) (*Driver, error)

GetDriver opens a PostgreSQL project driver.

func (*Driver) AddATeamMemberToProject

func (d *Driver) AddATeamMemberToProject(ctx context.Context, req *models.TeamMemberAddRequest) error

func (*Driver) AddAuthAddOns

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

func (*Driver) AddDocumentToProject

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

func (*Driver) AddFieldToModel

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

func (*Driver) AddModel

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

func (*Driver) AddRelationFields

func (d *Driver) AddRelationFields(ctx context.Context, from *models.ConnectionType, to *models.ConnectionType) error

func (*Driver) AddRelationFields_AUTOGEN

func (s *Driver) 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 (*Driver) AddTeamMetaInfo

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

AddTeamMetaInfo adds metadata information for a team in the project.

func (*Driver) AggregateDocOfProject

func (s *Driver) 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 (*Driver) AggregateDocOfProjectBytes

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

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

func (*Driver) BuildFieldClassification

func (d *Driver) BuildFieldClassification(_fields []*models.FieldInfo) *FieldClassification

func (*Driver) CheckOneToOneRelationExists

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

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

func (*Driver) CheckProjectExists

func (d *Driver) CheckProjectExists(ctx context.Context, projectId string) (bool, error)

func (*Driver) CheckTableOrCollectionExists

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

func (*Driver) ConnectBuilder

func (d *Driver) ConnectBuilder(ctx context.Context, root *models.CommonSystemParams) error

func (*Driver) ConvertModel

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

ConvertModel converts a model in the project.

func (*Driver) CountDocOfProject

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

func (*Driver) CountDocOfProjectBytes

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

func (*Driver) CountMedias

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

func (*Driver) CountMultiDocumentOfProject

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

func (*Driver) CountProjectAuthUsersByRole

func (d *Driver) CountProjectAuthUsersByRole(ctx context.Context, tenantID string) (map[string]int, error)

func (*Driver) CreateIndex

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

CreateIndex creates an index for a model in the project.

func (*Driver) CreateMediaDocument

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

func (*Driver) CreateModelTable

func (d *Driver) 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 (*Driver) CreateProjectAuthUser

func (d *Driver) CreateProjectAuthUser(ctx context.Context, user *models.ProjectAuthUser) (*models.ProjectAuthUser, error)

func (*Driver) CreateProjectFile

func (d *Driver) CreateProjectFile(ctx context.Context, file *models.ProjectFile) (*models.ProjectFile, error)

func (*Driver) CreateRelation

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

CreateRelation creates a relation in the project.

func (*Driver) CreateTableOrCollection

func (d *Driver) 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 (*Driver) DeleteDocumentFromProject

func (d *Driver) DeleteDocumentFromProject(ctx context.Context, param *models.CommonSystemParams) error

func (*Driver) DeleteDocumentRelation

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

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

func (*Driver) DeleteDocumentsFromProject

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

DeleteDocumentsFromProject deletes multiple documents from the project.

func (*Driver) DeleteMediaFile

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

DeleteMediaFile deletes a media file from the project files table.

func (*Driver) DeleteProject

func (d *Driver) DeleteProject(ctx context.Context, projectId string) error

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

func (*Driver) DeleteProjectAuthUser

func (d *Driver) DeleteProjectAuthUser(ctx context.Context, userID string) error

func (*Driver) DeleteProjectBase

func (d *Driver) DeleteProjectBase(ctx context.Context, param *models.CommonSystemParams) error

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

func (*Driver) DeleteProjectFiles

func (d *Driver) DeleteProjectFiles(ctx context.Context, ids []string) error

func (*Driver) DeleteRelation

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

DeleteRelation deletes a relation in the project.

func (*Driver) DeleteRelationDocuments

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

func (*Driver) DeleteRelationDocuments_AUTOGEN

func (s *Driver) 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 (*Driver) DisconnectBuilder

func (d *Driver) DisconnectBuilder(ctx context.Context, param *models.CommonSystemParams) error

func (*Driver) DropField

func (d *Driver) DropField(ctx context.Context, param *models.CommonSystemParams) error

func (*Driver) DropIndex

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

DropIndex drops an index from a model in the project.

func (*Driver) DropModel

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

DropModel drops a model from the project.

func (*Driver) DuplicateModel

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

DuplicateModel duplicates a model in the project.

func (*Driver) EnsureFilesTable

func (d *Driver) EnsureFilesTable(ctx context.Context) error

func (*Driver) EnsureMetaFilesTables

func (d *Driver) EnsureMetaFilesTables(ctx context.Context) error

EnsureMetaFilesTables creates meta and files tables when missing (idempotent).

func (*Driver) EnsureMetaMediaTables

func (d *Driver) EnsureMetaMediaTables(ctx context.Context) error

EnsureMetaMediaTables is deprecated; use EnsureMetaFilesTables.

func (*Driver) EnsureModelUserFieldColumns

func (d *Driver) 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 (*Driver) EnsureRelationArtifactsFromSchema

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

EnsureRelationArtifactsFromSchema creates missing SQL artifacts for schema-declared relations (pivot tables, FK columns, constraints) via AddRelationFields. Idempotent where supported. Needed when projects were authored on Arango (edges only) or bootstrap only created model tables.

func (*Driver) EnsureSchemaOptimizationsV1

func (d *Driver) 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 (*Driver) EnsureUsersTable

func (d *Driver) EnsureUsersTable(ctx context.Context) error

func (*Driver) GetAllRelationDocumentsOfSingleDocument

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

func (*Driver) GetAllRelationDocumentsOfSingleDocument_AUTOGEN

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

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

func (*Driver) GetLoggedInProjectUser

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

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

func (*Driver) GetProjectAuthUser

func (d *Driver) GetProjectAuthUser(ctx context.Context, userID string) (*models.ProjectAuthUser, error)

func (*Driver) GetProjectAuthUserByUsername

func (d *Driver) GetProjectAuthUserByUsername(ctx context.Context, username string) (*models.ProjectAuthUser, error)

func (*Driver) GetProjectFile

func (d *Driver) GetProjectFile(ctx context.Context, fileID string) (*models.ProjectFile, error)

func (*Driver) GetProjectUser

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

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

func (*Driver) GetProjectUsers

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

GetProjectUsers retrieves metadata for multiple users in the project.

func (*Driver) GetRelationDocument

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

GetRelationDocument retrieves a relation document by ID.

func (*Driver) GetRelationIds

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

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

func (*Driver) GetSingleProjectDocument

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

func (*Driver) GetSingleProjectDocumentBytes

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

func (*Driver) GetSingleProjectDocumentRevisions

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

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

func (*Driver) GetSingleRawDocumentFromProject

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

func (*Driver) InitProjectBase

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

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

func (*Driver) IsRemoteSQLiteLikeTurso

func (d *Driver) IsRemoteSQLiteLikeTurso() bool

func (*Driver) ListMedias

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

func (*Driver) ListProjectAuthUsersByEmail

func (d *Driver) ListProjectAuthUsersByEmail(ctx context.Context, tenantID, email string) ([]*models.ProjectAuthUser, error)

func (*Driver) ListProjectAuthUsersByGoogleSub

func (d *Driver) ListProjectAuthUsersByGoogleSub(ctx context.Context, tenantID, googleSub string) ([]*models.ProjectAuthUser, error)

func (*Driver) ListProjectAuthUsersByPhone

func (d *Driver) ListProjectAuthUsersByPhone(ctx context.Context, tenantID, phone string) ([]*models.ProjectAuthUser, error)

func (*Driver) NewInsertableRelations

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

NewInsertableRelations retrieves new insertable relations in the project.

func (*Driver) QueryMultiDocumentOfProject

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

func (*Driver) QueryMultiDocumentOfProjectBytes

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

func (*Driver) RelationshipDataLoader

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

func (*Driver) RelationshipDataLoaderBytes

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

func (*Driver) RemoveATeamMemberFromProject

func (d *Driver) RemoveATeamMemberFromProject(ctx context.Context, projectId string, memberId string) error

func (*Driver) RemoveAuthAddOns

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

func (*Driver) RenameField

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

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

func (*Driver) RenameModel

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

RenameModel renames a model in the project.

func (*Driver) SQLDriverShell

func (d *Driver) SQLDriverShell() *sqlcommon.Driver

func (*Driver) SQLEngineName

func (d *Driver) SQLEngineName() string

func (*Driver) SearchProjectAuthUsers

func (d *Driver) SearchProjectAuthUsers(ctx context.Context, tenantID string, limit, offset int) ([]*models.ProjectAuthUser, int, error)

func (*Driver) SearchProjectFiles

func (d *Driver) SearchProjectFiles(ctx context.Context, param *models.CommonSystemParams) (*models.SearchResponse[models.ProjectFile], error)

func (*Driver) SumProjectFilesSize

func (d *Driver) SumProjectFilesSize(ctx context.Context) (int64, error)

func (*Driver) TransferProject

func (d *Driver) TransferProject(ctx context.Context, userId, from, to string) error

func (*Driver) UpdateDocumentOfProject

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

func (*Driver) UpdateProjectAuthUser

func (d *Driver) UpdateProjectAuthUser(ctx context.Context, user *models.ProjectAuthUser) error

type FieldClassification

type FieldClassification struct {
	MultilineFields []string
	PictureField    []string
	GalleryField    []string
	ListFields      []string
	RepeatedFields  map[string][]*models.FieldInfo
	ObjectField     []string
	BooleanFields   []string // this is needed because in turso and sqlite boolean is stored as integer
	DateFields      []string
}

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
}

Jump to

Keyboard shortcuts

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