├── 执行流程 ├── CommandExecutor.drawio └── 流程.png ├── src ├── core │ ├── NCDC.Plugin │ │ ├── IRouteRule.cs │ │ ├── DefaultRules │ │ │ ├── ShardingRuleParams │ │ │ │ ├── TableRuleParam.cs │ │ │ │ └── BaseRuleParam.cs │ │ │ └── TableRules │ │ │ │ └── ModLongTableRule.cs │ │ ├── TableRouteRules │ │ │ ├── ITableRuleConfigure.cs │ │ │ └── ITableRouteRule.cs │ │ ├── DataSourceRouteRules │ │ │ ├── IDataSourceRuleConfigure.cs │ │ │ └── IDataSourceRouteRule.cs │ │ ├── NCDC.Plugin.csproj │ │ ├── TableRouteUnit.cs │ │ └── DataSourceRouteResult.cs │ ├── NCDC.Basic │ │ ├── Metadatas │ │ │ ├── ILogicTable.cs │ │ │ └── IProxyDatabase.cs │ │ └── NCDC.Basic.csproj │ ├── parser │ │ └── NCDC.CommandParser │ │ │ ├── Abstractions │ │ │ ├── Visitor │ │ │ │ ├── ISqlVisitor.cs │ │ │ │ ├── Commands │ │ │ │ │ ├── ISqlTypeVisitor.cs │ │ │ │ │ ├── IDALVisitor.cs │ │ │ │ │ ├── IDCLVisitor.cs │ │ │ │ │ ├── IDDLVisitor.cs │ │ │ │ │ ├── IDMLVisitor.cs │ │ │ │ │ ├── IRLVisitor.cs │ │ │ │ │ └── ITCLVisitor.cs │ │ │ │ └── Operations │ │ │ │ │ ├── ISqlFromVisitor.cs │ │ │ │ │ ├── ISqlOperationVisitor.cs │ │ │ │ │ └── ISqlCommandVisitor.cs │ │ │ ├── ISqlCommandParser.cs │ │ │ ├── IASTNode.cs │ │ │ ├── SqlLexer │ │ │ │ └── ISqlLexer.cs │ │ │ └── SqlParser │ │ │ │ └── ISqlParser.cs │ │ │ ├── Dialect │ │ │ ├── Handler │ │ │ │ └── ISqlCommandHandler.cs │ │ │ └── Command │ │ │ │ └── MySql │ │ │ │ ├── IMySqlCommand.cs │ │ │ │ ├── DAL │ │ │ │ ├── MySqlSetCommand.cs │ │ │ │ ├── MySqlShowDatabasesCommand.cs │ │ │ │ └── MySqlUseCommand.cs │ │ │ │ ├── TCL │ │ │ │ ├── MySqlCommitCommand.cs │ │ │ │ ├── MySqlUnlockCommand.cs │ │ │ │ ├── MySqlRollbackCommand.cs │ │ │ │ ├── MySqlSetTransactionCommand.cs │ │ │ │ ├── MySqlBeginTransactionCommand.cs │ │ │ │ ├── MySqlXACommand.cs │ │ │ │ ├── MySqlSavepointCommand.cs │ │ │ │ ├── MySqlSetAutoCommitCommand.cs │ │ │ │ └── MySqlLockCommand.cs │ │ │ │ ├── DDL │ │ │ │ ├── MySqlPrepareCommand.cs │ │ │ │ ├── MySqlTruncateCommand.cs │ │ │ │ ├── MySqlRenameTableCommand.cs │ │ │ │ ├── MySqlAlterDatabaseCommand.cs │ │ │ │ ├── MySqlDropTableCommand.cs │ │ │ │ ├── MySqlDropDatabaseCommand.cs │ │ │ │ ├── MySqlCreateDatabaseCommand.cs │ │ │ │ ├── MySqlAlterTableCommand.cs │ │ │ │ ├── MySqlDropIndexCommand.cs │ │ │ │ ├── MySqlCreateIndexCommand.cs │ │ │ │ └── MySqlCreateTableCommand.cs │ │ │ │ ├── DML │ │ │ │ ├── MySqlDoCommand.cs │ │ │ │ ├── MySqlInsertCommand.cs │ │ │ │ ├── MySqlTableCommand.cs │ │ │ │ ├── MySqlDeleteCommand.cs │ │ │ │ └── MySqlSelectCommand.cs │ │ │ │ └── Segment │ │ │ │ └── TableIndexSegment.cs │ │ │ ├── Common │ │ │ ├── Constant │ │ │ │ ├── OperationScopeEnum.cs │ │ │ │ ├── JoinTypeEnum.cs │ │ │ │ ├── ParameterMarkerTypeEnum.cs │ │ │ │ ├── TransactionAccessTypeEnum.cs │ │ │ │ ├── SubQueryTypeEnum.cs │ │ │ │ ├── CombineTypeEnum.cs │ │ │ │ ├── TransactionIsolationLevelEnum.cs │ │ │ │ └── OrderDirectionEnum.cs │ │ │ ├── Segment │ │ │ │ ├── Generic │ │ │ │ │ ├── ACLTypeEnum.cs │ │ │ │ │ ├── GrantLevelTypeEnum.cs │ │ │ │ │ ├── IParameterMarkerSegment.cs │ │ │ │ │ ├── IRemoveAvailable.cs │ │ │ │ │ ├── Table │ │ │ │ │ │ ├── ITableSegment.cs │ │ │ │ │ │ └── DeleteMultiTableSegment.cs │ │ │ │ │ ├── IOwnerAvailable.cs │ │ │ │ │ ├── WindowSegment.cs │ │ │ │ │ ├── IAliasAvailable.cs │ │ │ │ │ ├── CommentSegment.cs │ │ │ │ │ ├── DataTypeLengthSegment.cs │ │ │ │ │ ├── GrantLevelSegment.cs │ │ │ │ │ ├── NameSegment.cs │ │ │ │ │ ├── InsertMultiTableElementSegment.cs │ │ │ │ │ ├── WithSegment.cs │ │ │ │ │ └── DataTypeSegment.cs │ │ │ │ ├── DML │ │ │ │ │ ├── Item │ │ │ │ │ │ └── IProjectionSegment.cs │ │ │ │ │ ├── Expr │ │ │ │ │ │ ├── IExpressionSegment.cs │ │ │ │ │ │ ├── Simple │ │ │ │ │ │ │ └── ISimpleExpressionSegment.cs │ │ │ │ │ │ ├── Complex │ │ │ │ │ │ │ └── IComplexExpressionSegment.cs │ │ │ │ │ │ ├── ExistsSubQueryExpression.cs │ │ │ │ │ │ ├── ListExpression.cs │ │ │ │ │ │ └── NotExpression.cs │ │ │ │ │ ├── Pagination │ │ │ │ │ │ ├── INumberLiteralPaginationValueSegment.cs │ │ │ │ │ │ ├── IPaginationValueSegment.cs │ │ │ │ │ │ └── IParameterMarkerPaginationValueSegment.cs │ │ │ │ │ ├── Predicate │ │ │ │ │ │ ├── Value │ │ │ │ │ │ │ ├── IPredicateRightValue.cs │ │ │ │ │ │ │ └── PredicateRightBracketValue.cs │ │ │ │ │ │ ├── HavingSegment.cs │ │ │ │ │ │ ├── OrPredicateSegment.cs │ │ │ │ │ │ └── AndPredicateSegment.cs │ │ │ │ │ └── Prepare │ │ │ │ │ │ └── PrepareCommandQuerySegment.cs │ │ │ │ ├── DAL │ │ │ │ │ ├── VariableAssignSegment.cs │ │ │ │ │ ├── VariableSegment.cs │ │ │ │ │ ├── FromTableSegment.cs │ │ │ │ │ └── ShowLikeSegment.cs │ │ │ │ ├── DDL │ │ │ │ │ ├── IAlterDefinitionSegment.cs │ │ │ │ │ ├── ICreateDefinitionSegment.cs │ │ │ │ │ ├── Constraint │ │ │ │ │ │ ├── ConstraintSegment.cs │ │ │ │ │ │ └── Alter │ │ │ │ │ │ │ └── ValidateConstraintDefinitionSegment.cs │ │ │ │ │ ├── Table │ │ │ │ │ │ └── RenameTableDefinitionSegment.cs │ │ │ │ │ ├── Charset │ │ │ │ │ │ └── CharsetNameSegment.cs │ │ │ │ │ ├── Types │ │ │ │ │ │ └── TypeSegment.cs │ │ │ │ │ ├── Column │ │ │ │ │ │ └── Position │ │ │ │ │ │ │ ├── ColumnAfterPositionSegment.cs │ │ │ │ │ │ │ └── ColumnFirstPositionSegment.cs │ │ │ │ │ └── Index │ │ │ │ │ │ └── DropIndexDefinitionSegment.cs │ │ │ │ ├── TCL │ │ │ │ │ ├── AutoCommitSegment.cs │ │ │ │ │ └── ImplicitTransactionsSegment.cs │ │ │ │ └── ISqlSegment.cs │ │ │ ├── Command │ │ │ │ ├── TCL │ │ │ │ │ ├── LockCommand.cs │ │ │ │ │ ├── UnlockCommand.cs │ │ │ │ │ ├── XACommand.cs │ │ │ │ │ ├── CommitCommand.cs │ │ │ │ │ ├── ITCLCommand.cs │ │ │ │ │ ├── BeginTransactionCommand.cs │ │ │ │ │ ├── RollbackCommand.cs │ │ │ │ │ ├── SetAutoCommitCommand.cs │ │ │ │ │ ├── SavepointCommand.cs │ │ │ │ │ └── SetTransactionCommand.cs │ │ │ │ ├── DAL │ │ │ │ │ ├── FlushStatement.cs │ │ │ │ │ ├── LoadStatement.cs │ │ │ │ │ ├── VacuumStatement.cs │ │ │ │ │ ├── IDALCommand.cs │ │ │ │ │ ├── ExplainStatement.cs │ │ │ │ │ ├── ShowStatement.cs │ │ │ │ │ ├── UseCommand.cs │ │ │ │ │ ├── SetCommand.cs │ │ │ │ │ ├── AnalyzeTableStatement.cs │ │ │ │ │ └── ResetParameterStatement.cs │ │ │ │ ├── DML │ │ │ │ │ ├── TableCommand.cs │ │ │ │ │ ├── CheckpointCommand.cs │ │ │ │ │ ├── EmptyCommand.cs │ │ │ │ │ ├── DoCommand.cs │ │ │ │ │ ├── CallCommand.cs │ │ │ │ │ └── IDMLCommand.cs │ │ │ │ ├── DCL │ │ │ │ │ ├── CreateGroupCommand.cs │ │ │ │ │ ├── ReassignOwnedCommand.cs │ │ │ │ │ ├── AlterRoleCommand.cs │ │ │ │ │ ├── DropRoleCommand.cs │ │ │ │ │ ├── SetRoleCommand.cs │ │ │ │ │ ├── CreateRoleCommand.cs │ │ │ │ │ ├── IDCLCommand.cs │ │ │ │ │ ├── GrantCommand.cs │ │ │ │ │ └── RevokeCommand.cs │ │ │ │ ├── DDL │ │ │ │ │ ├── AlterDatabaseCommand.cs │ │ │ │ │ ├── DropTablespaceCommand.cs │ │ │ │ │ ├── CreateTablespaceCommand.cs │ │ │ │ │ ├── IDDLCommand.cs │ │ │ │ │ ├── PrepareCommand.cs │ │ │ │ │ ├── AlterIndexCommand.cs │ │ │ │ │ ├── RenameTableCommand.cs │ │ │ │ │ ├── TruncateCommand.cs │ │ │ │ │ ├── DropTableCommand.cs │ │ │ │ │ ├── DropIndexCommand.cs │ │ │ │ │ ├── DropDatabaseCommand.cs │ │ │ │ │ └── CreateDatabaseCommand.cs │ │ │ │ ├── Available │ │ │ │ │ └── IFromDatabaseAvailable.cs │ │ │ │ ├── RL │ │ │ │ │ └── IRLCommand.cs │ │ │ │ ├── SqlCommandTypeEnum.cs │ │ │ │ └── ISqlCommand.cs │ │ │ └── Value │ │ │ │ ├── IValueASTNode.cs │ │ │ │ ├── Literal │ │ │ │ ├── ILiteralValue.cs │ │ │ │ └── Impl │ │ │ │ │ ├── OtherLiteralValue.cs │ │ │ │ │ └── StringLiteralValue.cs │ │ │ │ └── KeyWord │ │ │ │ └── KeywordValue.cs │ │ │ ├── Exceptions │ │ │ ├── SqlParsingBaseException.cs │ │ │ ├── SqlParsingException.cs │ │ │ └── SqlASTVisitorException.cs │ │ │ ├── Core │ │ │ └── Cahce │ │ │ │ └── ParseCacheOption.cs │ │ │ ├── NCDCCommandParserExtension.cs │ │ │ ├── NCDC.CommandParser.csproj │ │ │ └── SqlParseEngines │ │ │ └── Hook │ │ │ └── IParsingHook.cs │ └── NCDC │ │ ├── Enums │ │ ├── DatabaseTypeEnum.cs │ │ ├── TransactionTypeEnum.cs │ │ └── ConnectionModeEnum.cs │ │ ├── Host │ │ └── IServiceHost.cs │ │ ├── DataSource │ │ ├── IDataSourceMetaData.cs │ │ └── IDataSource.cs │ │ ├── DataStructure │ │ └── RangeStructure │ │ │ └── BoundType.cs │ │ ├── Base │ │ ├── DoOnlyOnce.cs │ │ ├── SemaphoreReleaseOnlyOnce.cs │ │ └── OneByOneChecker.cs │ │ ├── Exceptions │ │ ├── ShardingConfigException.cs │ │ ├── ShardingNotSupportedException.cs │ │ └── ShardingInvalidOperationException.cs │ │ └── Helpers │ │ └── UtcTimeHelper.cs ├── proxy │ ├── NCDC.ProxyClient │ │ ├── Authentication │ │ │ ├── IAuthContext.cs │ │ │ ├── IAuthenticator.cs │ │ │ └── AuthenticationResult.cs │ │ ├── Exceptions │ │ │ ├── ClientException.cs │ │ │ └── NotSupportedCommandException.cs │ │ ├── Command │ │ │ ├── Abstractions │ │ │ │ ├── IMessageExecutorFactory.cs │ │ │ │ ├── IMessageExecutor.cs │ │ │ │ └── IMessageCommandProcessor.cs │ │ │ └── MessageExecutorFactory.cs │ │ ├── NCDC.ProxyClient.csproj │ │ ├── Abstractions │ │ │ ├── IClientQueryDataReader.cs │ │ │ └── IClientCommand.cs │ │ ├── ConnectionIdGenerator.cs │ │ ├── DotNetty │ │ │ └── ChannelAttrInitializer.cs │ │ ├── DIExtension.cs │ │ └── IDatabaseProtocolClientEngine.cs │ ├── NCDC.ProxyServer │ │ ├── Commons │ │ │ ├── ResultTypeEnum.cs │ │ │ └── DbStorageTypeEnum.cs │ │ ├── Abstractions │ │ │ ├── ICommand.cs │ │ │ ├── IDbProviderFactory.cs │ │ │ ├── IServerResult.cs │ │ │ ├── IServerDataReaderFactory.cs │ │ │ ├── ICommandListener.cs │ │ │ ├── IServerDataReader.cs │ │ │ ├── IServerHandlerFactory.cs │ │ │ └── IServerHandler.cs │ │ ├── StreamMerges │ │ │ ├── IExecuteResult.cs │ │ │ ├── IExecutor.cs │ │ │ ├── Results │ │ │ │ ├── AffectedRowsExecuteResult.cs │ │ │ │ └── QueryExecuteResult.cs │ │ │ └── IShardingMerger.cs │ │ ├── Bootstrappers │ │ │ ├── IAppInitializer.cs │ │ │ └── IAppBootstrapper.cs │ │ ├── ServiceProviders │ │ │ └── IShardingScope.cs │ │ ├── Runtimes │ │ │ ├── Builder │ │ │ │ ├── IAppRuntimeBuilder.cs │ │ │ │ ├── ActualTableNode.cs │ │ │ │ └── DataSourceNode.cs │ │ │ └── Initializer │ │ │ │ └── ITableMetadataInitializer.cs │ │ ├── Connection │ │ │ ├── Abstractions │ │ │ │ ├── IConnectionInvokeReply.cs │ │ │ │ ├── IServerDbDataReader.cs │ │ │ │ ├── IServerDbTransaction.cs │ │ │ │ ├── IServerDbCommand.cs │ │ │ │ ├── IServerDbConnection.cs │ │ │ │ └── IQueryContext.cs │ │ │ ├── IConnectionSessionFactory.cs │ │ │ ├── DefaultConnectionInvokeReply.cs │ │ │ └── CreateServerDbConnectionStrategyEnum.cs │ │ ├── ServerHandlers │ │ │ ├── TransactionOperationTypeEnum.cs │ │ │ ├── ServerTransactions │ │ │ │ ├── TransactionHolder.cs │ │ │ │ └── ITransactionManager.cs │ │ │ ├── Results │ │ │ │ ├── AffectRowUnitResult.cs │ │ │ │ └── QueryServerResult.cs │ │ │ └── SkipServerHandler.cs │ │ ├── Options │ │ │ ├── DatabaseOption.cs │ │ │ ├── DataSourceOption.cs │ │ │ └── UserOption.cs │ │ ├── AppServices │ │ │ ├── Abstractions │ │ │ │ ├── IAppUserLoader.cs │ │ │ │ ├── IUserDatabaseMappingLoader.cs │ │ │ │ ├── IAppRuntimeLoader.cs │ │ │ │ ├── IAppConfiguration.cs │ │ │ │ └── IAppRuntimeManager.cs │ │ │ └── AppConfiguration.cs │ │ ├── Executors │ │ │ ├── IShardingExecutionContextFactory.cs │ │ │ ├── SqlExecutorGroup.cs │ │ │ ├── DataSourceSqlExecutorUnit.cs │ │ │ └── CommandExecuteUnit.cs │ │ ├── Binaries │ │ │ ├── BinaryRow.cs │ │ │ └── BinaryCell.cs │ │ ├── Databases │ │ │ └── IDataSource.cs │ │ └── Helpers │ │ │ └── AutoCommitHelper.cs │ ├── NCDC.ProxyClientMySql │ │ ├── Authentication │ │ │ └── Authenticator │ │ │ │ └── IMySqlAuthenticator.cs │ │ ├── Common │ │ │ ├── MySqlConnectionPhaseEnum.cs │ │ │ └── ServerStatusFlagCalculator.cs │ │ ├── NCDC.ProxyClientMySql.csproj │ │ └── ClientConnections │ │ │ ├── Commands │ │ │ └── MySqlQuitClientCommand.cs │ │ │ └── DataReaders │ │ │ └── Quit │ │ │ └── MySqlQuitClientDataReader.cs │ └── NCDC.ProxyStarter │ │ └── appsettings.json ├── sharding │ ├── NCDC.ShardingRoute │ │ ├── Abstractions │ │ │ ├── IRoute.cs │ │ │ ├── IRouteContextFactory.cs │ │ │ └── ITableRouteManager.cs │ │ ├── TableRoutes │ │ │ ├── Abstractions │ │ │ │ ├── ITableRouteRuleEngine.cs │ │ │ │ └── ITableRoute.cs │ │ │ └── TableRouteContext.cs │ │ ├── DataSourceRoutes │ │ │ ├── Abstractions │ │ │ │ ├── IDataSourceRouteRuleEngine.cs │ │ │ │ └── IDataSourceRoute.cs │ │ │ └── DataSourceRouteRuleContext.cs │ │ ├── RouteMapper.cs │ │ ├── NCDC.ShardingRoute.csproj │ │ └── Extensions │ │ │ └── TableMetadataExtension.cs │ ├── NCDC.ShardingRewrite │ │ ├── Abstractions │ │ │ ├── IParameterBuilder.cs │ │ │ ├── ISqlRewriterContextFactory.cs │ │ │ └── IParameterRewriterBuilder.cs │ │ ├── Sql │ │ │ ├── ISqlBuilder.cs │ │ │ ├── Token │ │ │ │ ├── SimpleObject │ │ │ │ │ ├── IAttachable.cs │ │ │ │ │ ├── IRouteUnitAware.cs │ │ │ │ │ ├── ISubstitutable.cs │ │ │ │ │ └── Generic │ │ │ │ │ │ └── RemoveToken.cs │ │ │ │ └── Generator │ │ │ │ │ ├── Builder │ │ │ │ │ └── ISqlTokenGeneratorBuilder.cs │ │ │ │ │ └── ISqlTokenGenerator.cs │ │ │ └── Impl │ │ │ │ └── DefaultSqlBuilder.cs │ │ ├── Token │ │ │ ├── Generator │ │ │ │ └── IIgnoreForSingleRoute.cs │ │ │ └── SimpleObject │ │ │ │ ├── DistinctProjectionPrefixToken.cs │ │ │ │ └── ParameterMarkerGeneratedKeyAssignmentToken.cs │ │ ├── NCDC.ShardingRewrite.csproj │ │ ├── SqlRewriteResult.cs │ │ └── NCDCShardingRewriteExtension.cs │ ├── NCDC.ShardingMerge │ │ ├── Abstractions │ │ │ ├── IDataReaderMergerFactory.cs │ │ │ └── IDataReaderMerger.cs │ │ ├── NCDC.ShardingMerge.csproj │ │ └── DataReaderMergers │ │ │ └── DQL │ │ │ └── GroupBy │ │ │ └── Aggregation │ │ │ └── IAggregationUnit.cs │ └── NCDC.ShardingParser │ │ ├── Abstractions │ │ └── ISqlCommandContextFactory.cs │ │ ├── Command │ │ ├── IIndexAvailable.cs │ │ ├── IWhereAvailable.cs │ │ └── ITableAvailable.cs │ │ ├── NCDC.ShardingParser.csproj │ │ ├── Segment │ │ ├── Select │ │ │ ├── Projection │ │ │ │ └── IProjection.cs │ │ │ └── SubQuery │ │ │ │ └── SubQueryTableContext.cs │ │ └── Insert │ │ │ └── Values │ │ │ └── Expression │ │ │ ├── IDerivedSimpleExpressionSegment.cs │ │ │ └── DerivedLiteralExpressionSegment.cs │ │ └── NCDCShardingParserExtension.cs ├── orm │ └── NCDC.EntityFrameworkCore │ │ ├── Entities │ │ ├── Base │ │ │ ├── IEntity.cs │ │ │ ├── IVersion.cs │ │ │ ├── ILogicDelete.cs │ │ │ ├── ICreateTime.cs │ │ │ ├── IUpdateTime.cs │ │ │ └── BaseEntity.cs │ │ ├── DatabaseUserEntity.cs │ │ ├── ActualTableEntity.cs │ │ └── AppAuthUserEntity.cs │ │ ├── QueryableExtension.cs │ │ └── Maps │ │ ├── DatabaseUserMap.cs │ │ ├── LogicDatabaseMap.cs │ │ ├── AppAuthUserMap.cs │ │ └── ActualDatabaseMap.cs ├── protocol │ └── NCDC.Protocol │ │ ├── MySql │ │ ├── Packet │ │ │ ├── Prepare │ │ │ │ ├── MySqlCommandPreparePacket.cs │ │ │ │ └── MySqlCommandPrepareOkPacket.cs │ │ │ ├── IMysqlPacket.cs │ │ │ ├── Command │ │ │ │ ├── MySqlServerNotSupportCommandPacket.cs │ │ │ │ ├── MySqlCommandPacketTypeLoader.cs │ │ │ │ └── MySqlServerComSetOptionPacket.cs │ │ │ └── Handshake │ │ │ │ └── MySqlAuthSwitchResponsePacket.cs │ │ └── Constant │ │ │ ├── MySqlConstants.cs │ │ │ └── MySqlAuthenticationMethod.cs │ │ ├── Packets │ │ ├── IPacketPayload.cs │ │ └── IPacket.cs │ │ ├── Errors │ │ └── ISqlErrorCode.cs │ │ └── Helper │ │ ├── BytesHelper.cs │ │ └── Sha1Helper.cs ├── bootstrapper │ └── NCDC.WebBootstrapper │ │ ├── rule │ │ └── test │ │ │ └── ShardingRoutePluginTest.dll │ │ ├── Configs │ │ └── JwtConfig.json │ │ ├── Controllers │ │ ├── LogicDatabase │ │ │ └── Page │ │ │ │ └── LogicDatabasePageRequest.cs │ │ ├── AuthUser │ │ │ ├── Page │ │ │ │ └── AuthUserPageRequest.cs │ │ │ ├── UserDatabasesSave │ │ │ │ └── UserDatabasesSaveRequest.cs │ │ │ ├── UserDatabases │ │ │ │ ├── UserDatabasesRequest.cs │ │ │ │ └── UserDatabasesResponse.cs │ │ │ └── All │ │ │ │ └── AuthUserAllResponse.cs │ │ ├── User │ │ │ ├── Info │ │ │ │ └── UserInfoResponse.cs │ │ │ └── UserController.cs │ │ ├── ActualDatabase │ │ │ ├── All │ │ │ │ ├── ActualDatabaseAllResponse.cs │ │ │ │ └── ActualDatabaseAllRequest.cs │ │ │ └── Page │ │ │ │ └── ActualDatabasePageRequest.cs │ │ ├── Passport │ │ │ └── Login │ │ │ │ └── LoginRequest.cs │ │ ├── PageRequest.cs │ │ └── LogicTable │ │ │ ├── Page │ │ │ └── LogicTablePageRequest.cs │ │ │ └── ActualTablePage │ │ │ └── ActualTablePageRequest.cs │ │ ├── Jwt │ │ └── JwtIssuerOptions.cs │ │ ├── WeatherForecast.cs │ │ ├── appsettings.Development.json │ │ ├── appsettings.json │ │ ├── Properties │ │ └── launchSettings.json │ │ ├── AppResult.cs │ │ └── Exceptions │ │ └── AppException.cs └── antlr4 │ └── NCDC.MySqlParser │ ├── Visitor │ └── Impl │ │ ├── MySqlRLVisitor.cs │ │ └── MySqlDCLVisitor.cs │ └── NCDCMySqlParserExtension.cs ├── test ├── NCDC.ShardingTest │ ├── Seed │ │ ├── Entities │ │ │ ├── LogMonthLong.cs │ │ │ ├── LogYearLong.cs │ │ │ ├── LogWeekTimeLong.cs │ │ │ ├── LogNoSharding.cs │ │ │ ├── LogWeekDateTime.cs │ │ │ ├── LogYearDateTime.cs │ │ │ ├── MultiShardingOrder.cs │ │ │ ├── LogDay.cs │ │ │ ├── LogDayLong.cs │ │ │ ├── Order.cs │ │ │ ├── SysUserModInt.cs │ │ │ └── SysUserMod.cs │ │ ├── Maps │ │ │ ├── OrderMap.cs │ │ │ ├── LogDayMap.cs │ │ │ └── LogWeekDateTimeMap.cs │ │ └── Shardings │ │ │ └── PaginationConfigs │ │ │ └── LogDayPaginationConfiguration.cs │ └── Seed2 │ │ └── TypeSeedDbContext.cs ├── ShardingRoutePluginTest │ └── ShardingRoutePluginTest.csproj └── ShardingConnector.HiSqlTest │ └── ShardingConnector.HiSqlTest.csproj └── README.md /执行流程/CommandExecutor.drawio: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /执行流程/流程.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xuejmnet/NCDC/HEAD/执行流程/流程.png -------------------------------------------------------------------------------- /src/core/NCDC.Plugin/IRouteRule.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.Plugin; 2 | 3 | public interface IRouteRule 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /src/core/NCDC.Basic/Metadatas/ILogicTable.cs: -------------------------------------------------------------------------------- 1 | // namespace NCDC.Basic.Metadatas; 2 | // 3 | // public interface ILogicTable 4 | // { 5 | // 6 | // } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyClient/Authentication/IAuthContext.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ProxyClient.Authentication; 2 | 3 | public interface IAuthContext 4 | { 5 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingRoute/Abstractions/IRoute.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ShardingRoute.Abstractions; 2 | 3 | public interface IRoute 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyClient/Authentication/IAuthenticator.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ProxyClient.Authentication; 2 | 3 | public interface IAuthenticator 4 | { 5 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Commons/ResultTypeEnum.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ProxyServer.Commons; 2 | 3 | public enum ResultTypeEnum 4 | { 5 | QUERY,UPDATE 6 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyClient/Exceptions/ClientException.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ProxyClient.Exceptions; 2 | 3 | public class ClientException:Exception 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Abstractions/ICommand.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ProxyServer.Abstractions; 2 | 3 | public interface ICommand 4 | { 5 | ValueTask ExecuteAsync(); 6 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/StreamMerges/IExecuteResult.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ProxyServer.StreamMerges; 2 | 3 | public interface IExecuteResult:IDisposable 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Commons/DbStorageTypeEnum.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ProxyServer.Commons; 2 | 3 | public enum DbStorageTypeEnum 4 | { 5 | MySql=1, 6 | SqlServer=2 7 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Abstractions/Visitor/ISqlVisitor.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Abstractions.Visitor; 2 | 3 | public interface ISqlVisitor 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Dialect/Handler/ISqlCommandHandler.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Dialect.Handler; 2 | 3 | public interface ISqlCommandHandler 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /src/orm/NCDC.EntityFrameworkCore/Entities/Base/IEntity.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.EntityFrameworkCore.Entities.Base; 2 | 3 | public interface IEntity 4 | { 5 | string Id { get; set; } 6 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Bootstrappers/IAppInitializer.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ProxyServer.Bootstrappers; 2 | 3 | public interface IAppInitializer 4 | { 5 | Task InitializeAsync(); 6 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Constant/OperationScopeEnum.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Constant; 2 | 3 | public enum OperationScopeEnum 4 | { 5 | GLOBAL,SESSION 6 | } -------------------------------------------------------------------------------- /src/orm/NCDC.EntityFrameworkCore/Entities/Base/IVersion.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.EntityFrameworkCore.Entities.Base; 2 | 3 | public interface IVersion 4 | { 5 | string Version { get; set; } 6 | } -------------------------------------------------------------------------------- /src/orm/NCDC.EntityFrameworkCore/Entities/Base/ILogicDelete.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.EntityFrameworkCore.Entities.Base; 2 | 3 | public interface ILogicDelete 4 | { 5 | bool IsDelete { get; set; } 6 | } -------------------------------------------------------------------------------- /src/protocol/NCDC.Protocol/MySql/Packet/Prepare/MySqlCommandPreparePacket.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.Protocol.MySql.Packet.Prepare; 2 | 3 | public sealed class MySqlCommandPreparePacket 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /src/bootstrapper/NCDC.WebBootstrapper/rule/test/ShardingRoutePluginTest.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xuejmnet/NCDC/HEAD/src/bootstrapper/NCDC.WebBootstrapper/rule/test/ShardingRoutePluginTest.dll -------------------------------------------------------------------------------- /src/orm/NCDC.EntityFrameworkCore/Entities/Base/ICreateTime.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.EntityFrameworkCore.Entities.Base; 2 | 3 | public interface ICreateTime 4 | { 5 | DateTime CreateTime { get; set; } 6 | } -------------------------------------------------------------------------------- /src/orm/NCDC.EntityFrameworkCore/Entities/Base/IUpdateTime.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.EntityFrameworkCore.Entities.Base; 2 | 3 | public interface IUpdateTime 4 | { 5 | DateTime UpdateTime { get; set; } 6 | } -------------------------------------------------------------------------------- /src/protocol/NCDC.Protocol/MySql/Packet/Prepare/MySqlCommandPrepareOkPacket.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.Protocol.MySql.Packet.Prepare; 2 | 3 | public sealed class MySqlCommandPrepareOkPacket 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Constant/JoinTypeEnum.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Constant; 2 | 3 | public enum JoinTypeEnum 4 | { 5 | INNER, FULL, CROSS, LEFT, RIGHT, COMMA 6 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Constant/ParameterMarkerTypeEnum.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Constant; 2 | 3 | public enum ParameterMarkerTypeEnum 4 | { 5 | QUESTION,DOLLAR,AT 6 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/Generic/ACLTypeEnum.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Segment.Generic; 2 | 3 | public enum ACLTypeEnum 4 | { 5 | TABLE, FUNCTION, PROCEDURE 6 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/TCL/LockCommand.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Command.TCL; 2 | 3 | public abstract class LockCommand: AbstractSqlCommand, ITCLCommand 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Constant/TransactionAccessTypeEnum.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Constant; 2 | 3 | public enum TransactionAccessTypeEnum 4 | { 5 | READ_ONLY,READ_WRITE 6 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/Generic/GrantLevelTypeEnum.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Segment.Generic; 2 | 3 | public enum GrantLevelTypeEnum 4 | { 5 | GLOBAL, DB, TABLE 6 | } -------------------------------------------------------------------------------- /src/core/NCDC/Enums/DatabaseTypeEnum.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.Enums; 2 | 3 | public enum DatabaseTypeEnum 4 | { 5 | SqlServer=1, 6 | MySql=2, 7 | PostgreSql=3, 8 | Oracle=4, 9 | MariaDB=5, 10 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Abstractions/Visitor/Commands/ISqlTypeVisitor.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Abstractions.Visitor.Commands; 2 | 3 | public interface ISqlTypeVisitor:ISqlVisitor 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DAL/FlushStatement.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Command.DAL; 2 | 3 | public abstract class FlushStatement:AbstractSqlCommand,IDALCommand 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DAL/LoadStatement.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Command.DAL; 2 | 3 | public abstract class LoadStatement:AbstractSqlCommand,IDALCommand 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DML/TableCommand.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Command.DML; 2 | 3 | public abstract class TableCommand: AbstractSqlCommand, IDMLCommand 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/TCL/UnlockCommand.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Command.TCL; 2 | 3 | public abstract class UnlockCommand: AbstractSqlCommand, ITCLCommand 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /src/bootstrapper/NCDC.WebBootstrapper/Configs/JwtConfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "JwtIssuerOptions": { 3 | "Issuer": "NCDC", 4 | "Audience": "http://localhost:5000/", 5 | "SecretKey": "NcdcjWTTOKENjWTTOKEN!@#" 6 | } 7 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DAL/VacuumStatement.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Command.DAL; 2 | 3 | public abstract class VacuumStatement:AbstractSqlCommand,IDALCommand 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DML/CheckpointCommand.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Command.DML; 2 | 3 | public abstract class CheckpointCommand:AbstractSqlCommand,IDMLCommand 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/Generic/IParameterMarkerSegment.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Segment.Generic; 2 | 3 | public interface IParameterMarkerSegment:ISqlSegment 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /src/protocol/NCDC.Protocol/Packets/IPacketPayload.cs: -------------------------------------------------------------------------------- 1 | using DotNetty.Buffers; 2 | 3 | namespace NCDC.Protocol.Packets; 4 | 5 | public interface IPacketPayload:IDisposable 6 | { 7 | IByteBuffer GetByteBuffer(); 8 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyClient/Command/Abstractions/IMessageExecutorFactory.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ProxyClient.Command.Abstractions; 2 | 3 | public interface IMessageExecutorFactory 4 | { 5 | IMessageExecutor Create(); 6 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/ServiceProviders/IShardingScope.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ProxyServer.ServiceProviders; 2 | 3 | public interface IShardingScope : IDisposable 4 | { 5 | IShardingProvider ServiceProvider { get; } 6 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DCL/CreateGroupCommand.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Command.DCL; 2 | 3 | public abstract class CreateGroupCommand:AbstractSqlCommand,IDCLCommand 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /src/protocol/NCDC.Protocol/Errors/ISqlErrorCode.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.Protocol.Errors; 2 | 3 | public interface ISqlErrorCode 4 | { 5 | int GetErrorCode(); 6 | string GetSqlState(); 7 | string GetErrorMessage(); 8 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Runtimes/Builder/IAppRuntimeBuilder.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ProxyServer.Runtimes.Builder; 2 | 3 | public interface IAppRuntimeBuilder 4 | { 5 | Task BuildAsync(string database); 6 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Abstractions/Visitor/Operations/ISqlFromVisitor.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Abstractions.Visitor.Operations; 2 | 3 | public interface ISqlFromVisitor:ISqlOperationVisitor 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Abstractions/Visitor/Operations/ISqlOperationVisitor.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Abstractions.Visitor.Operations; 2 | 3 | public interface ISqlOperationVisitor:ISqlVisitor 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DCL/ReassignOwnedCommand.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Command.DCL; 2 | 3 | public abstract class ReassignOwnedCommand:AbstractSqlCommand,IDCLCommand 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DDL/AlterDatabaseCommand.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Command.DDL; 2 | 3 | public abstract class AlterDatabaseCommand:AbstractSqlCommand,IDDLCommand 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DDL/DropTablespaceCommand.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Command.DDL; 2 | 3 | public abstract class DropTablespaceCommand:AbstractSqlCommand,IDDLCommand 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Abstractions/IDbProviderFactory.cs: -------------------------------------------------------------------------------- 1 | using System.Data.Common; 2 | 3 | namespace NCDC.ProxyServer.Abstractions; 4 | 5 | public interface IDbProviderFactory 6 | { 7 | DbProviderFactory Create(); 8 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Abstractions/IServerResult.cs: -------------------------------------------------------------------------------- 1 | using NCDC.ProxyServer.Commons; 2 | 3 | namespace NCDC.ProxyServer.Abstractions; 4 | 5 | public interface IServerResult 6 | { 7 | ResultTypeEnum ResultType { get; } 8 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Abstractions/Visitor/Operations/ISqlCommandVisitor.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Abstractions.Visitor.Operations; 2 | 3 | public interface ISqlCommandVisitor:ISqlOperationVisitor 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DAL/IDALCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Abstractions; 2 | 3 | namespace NCDC.CommandParser.Common.Command.DAL; 4 | 5 | public interface IDALCommand:ISqlCommand 6 | { 7 | 8 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DDL/CreateTablespaceCommand.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Command.DDL; 2 | 3 | public abstract class CreateTablespaceCommand:AbstractSqlCommand,IDDLCommand 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /src/core/NCDC/Host/IServiceHost.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.Host; 2 | 3 | public interface IServiceHost 4 | { 5 | Task StartAsync(CancellationToken cancellationToken=default); 6 | Task StopAsync(CancellationToken cancellationToken=default); 7 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Dialect/Command/MySql/IMySqlCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command; 2 | 3 | namespace NCDC.CommandParser.Dialect.Command.MySql; 4 | 5 | public interface IMySqlCommand:ISqlCommand 6 | { 7 | 8 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Connection/Abstractions/IConnectionInvokeReply.cs: -------------------------------------------------------------------------------- 1 | // namespace NCDC.ProxyServer.Connection.Abstractions; 2 | // 3 | // public interface IConnectionInvokeReply 4 | // { 5 | // ValueTask Process(T target); 6 | // } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingRewrite/Abstractions/IParameterBuilder.cs: -------------------------------------------------------------------------------- 1 | using NCDC.ShardingAdoNet; 2 | 3 | namespace NCDC.ShardingRewrite.Abstractions; 4 | 5 | public interface IParameterBuilder 6 | { 7 | ParameterContext GetParameterContext(); 8 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingRoute/TableRoutes/Abstractions/ITableRouteRuleEngine.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ShardingRoute.TableRoutes.Abstractions; 2 | 3 | public interface ITableRouteRuleEngine 4 | { 5 | ShardingRouteResult Route(TableRouteContext context); 6 | } -------------------------------------------------------------------------------- /test/NCDC.ShardingTest/Seed/Entities/LogMonthLong.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ShardingTest.Seed.Entities; 2 | 3 | public class LogMonthLong 4 | { 5 | public string Id { get; set; } 6 | public string Body { get; set; } 7 | public long LogTime { get; set; } 8 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingRoute/Abstractions/IRouteContextFactory.cs: -------------------------------------------------------------------------------- 1 | using NCDC.ShardingParser; 2 | 3 | namespace NCDC.ShardingRoute.Abstractions; 4 | 5 | public interface IRouteContextFactory 6 | { 7 | RouteContext Create(SqlParserResult sqlParserResult); 8 | } -------------------------------------------------------------------------------- /test/NCDC.ShardingTest/Seed/Entities/LogYearLong.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ShardingTest.Seed.Entities; 2 | 3 | public class LogYearLong 4 | { 5 | public string Id { get; set; } 6 | public string LogBody { get; set; } 7 | public long LogTime { get; set; } 8 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Abstractions/ISqlCommandParser.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command; 2 | 3 | namespace NCDC.CommandParser.Abstractions; 4 | 5 | public interface ISqlCommandParser 6 | { 7 | ISqlCommand Parse(string sql, bool useCache); 8 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Dialect/Command/MySql/DAL/MySqlSetCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command.DAL; 2 | 3 | namespace NCDC.CommandParser.Dialect.Command.MySql.DAL; 4 | 5 | public class MySqlSetCommand:SetCommand,IMySqlCommand 6 | { 7 | 8 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Exceptions/SqlParsingBaseException.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Exceptions; 2 | 3 | public class SqlParsingBaseException:Exception 4 | { 5 | public SqlParsingBaseException(string? message) : base(message) 6 | { 7 | } 8 | } -------------------------------------------------------------------------------- /test/NCDC.ShardingTest/Seed/Entities/LogWeekTimeLong.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ShardingTest.Seed.Entities; 2 | 3 | public class LogWeekTimeLong 4 | { 5 | public string Id { get; set; } 6 | public string Body { get; set; } 7 | public long LogTime { get; set; } 8 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Constant/SubQueryTypeEnum.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Constant; 2 | 3 | public enum SubQueryTypeEnum 4 | { 5 | PROJECTION_SUB_QUERY, TABLE_SUB_QUERY, PREDICATE_SUB_QUERY, INSERT_SELECT_SUB_QUERY, EXISTS_SUB_QUERY 6 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyClient/Command/Abstractions/IMessageExecutor.cs: -------------------------------------------------------------------------------- 1 | using NCDC.ProxyServer.Abstractions; 2 | 3 | namespace NCDC.ProxyClient.Command.Abstractions; 4 | 5 | public interface IMessageExecutor:IDisposable 6 | { 7 | bool TryAddMessage(ICommand command); 8 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/ServerHandlers/TransactionOperationTypeEnum.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ProxyServer.ServerHandlers; 2 | 3 | public enum TransactionOperationTypeEnum 4 | { 5 | BEGIN,COMMIT,ROLLBACK,SAVEPOINT, ROLLBACK_TO_SAVEPOINT, RELEASE_SAVEPOINT, SET_AUTOCOMMIT 6 | } -------------------------------------------------------------------------------- /test/NCDC.ShardingTest/Seed/Entities/LogNoSharding.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ShardingTest.Seed.Entities; 2 | 3 | public class LogNoSharding 4 | { 5 | public string Id { get; set; } 6 | public string Body { get; set; } 7 | public DateTime CreationTime { get; set; } 8 | } -------------------------------------------------------------------------------- /test/NCDC.ShardingTest/Seed/Entities/LogWeekDateTime.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace NCDC.ShardingTest.Seed.Entities; 3 | 4 | public class LogWeekDateTime 5 | { 6 | public string Id { get; set; } 7 | public string Body { get; set; } 8 | public DateTime LogTime { get; set; } 9 | } -------------------------------------------------------------------------------- /src/bootstrapper/NCDC.WebBootstrapper/Controllers/LogicDatabase/Page/LogicDatabasePageRequest.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.WebBootstrapper.Controllers.LogicDatabase.Page; 2 | 3 | public class LogicDatabasePageRequest:PageRequest 4 | { 5 | public string? DatabaseName { get; set; } 6 | } -------------------------------------------------------------------------------- /src/protocol/NCDC.Protocol/MySql/Packet/IMysqlPacket.cs: -------------------------------------------------------------------------------- 1 | using NCDC.Protocol.MySql.Payload; 2 | using NCDC.Protocol.Packets; 3 | 4 | namespace NCDC.Protocol.MySql.Packet; 5 | 6 | public interface IMysqlPacket:IPacket 7 | { 8 | int SequenceId { get; } 9 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Options/DatabaseOption.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ProxyServer.Options; 2 | 3 | public class DatabaseOption 4 | { 5 | public string DatabaseName { get; set; } 6 | public List DataSources { get; set; } = new List(); 7 | } -------------------------------------------------------------------------------- /test/NCDC.ShardingTest/Seed/Entities/LogYearDateTime.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace NCDC.ShardingTest.Seed.Entities; 3 | 4 | public class LogYearDateTime 5 | { 6 | public Guid Id { get; set; } 7 | public string LogBody { get; set; } 8 | public DateTime LogTime { get; set; } 9 | } -------------------------------------------------------------------------------- /test/NCDC.ShardingTest/Seed/Entities/MultiShardingOrder.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ShardingTest.Seed.Entities; 2 | 3 | public class MultiShardingOrder 4 | { 5 | public long Id { get; set; } 6 | public string Name { get; set; } 7 | public DateTime CreateTime { get; set; } 8 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Dialect/Command/MySql/TCL/MySqlCommitCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command.TCL; 2 | 3 | namespace NCDC.CommandParser.Dialect.Command.MySql.TCL; 4 | 5 | public sealed class MySqlCommitCommand:CommitCommand,IMySqlCommand 6 | { 7 | 8 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Dialect/Command/MySql/TCL/MySqlUnlockCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command.TCL; 2 | 3 | namespace NCDC.CommandParser.Dialect.Command.MySql.TCL; 4 | 5 | public sealed class MySqlUnlockCommand:UnlockCommand,IMySqlCommand 6 | { 7 | 8 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Options/DataSourceOption.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ProxyServer.Options; 2 | 3 | public class DataSourceOption 4 | { 5 | public string DataSourceName { get; set; } 6 | public string ConnectionString { get; set; } 7 | public bool IsDefault { get; set; } 8 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Dialect/Command/MySql/DDL/MySqlPrepareCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command.DDL; 2 | 3 | namespace NCDC.CommandParser.Dialect.Command.MySql.DDL; 4 | 5 | public sealed class MySqlPrepareCommand:PrepareCommand,IMySqlCommand 6 | { 7 | 8 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Runtimes/Initializer/ITableMetadataInitializer.cs: -------------------------------------------------------------------------------- 1 | using NCDC.Basic.Metadatas; 2 | 3 | namespace NCDC.ProxyServer.Runtimes.Initializer; 4 | 5 | public interface ITableMetadataInitializer 6 | { 7 | Task InitializeAsync(TableMetadata tableMetadata); 8 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Dialect/Command/MySql/DDL/MySqlTruncateCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command.DDL; 2 | 3 | namespace NCDC.CommandParser.Dialect.Command.MySql.DDL; 4 | 5 | public sealed class MySqlTruncateCommand:TruncateCommand,IMySqlCommand 6 | { 7 | 8 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Dialect/Command/MySql/TCL/MySqlRollbackCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command.TCL; 2 | 3 | namespace NCDC.CommandParser.Dialect.Command.MySql.TCL; 4 | 5 | public sealed class MySqlRollbackCommand:RollbackCommand,IMySqlCommand 6 | { 7 | 8 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/AppServices/Abstractions/IAppUserLoader.cs: -------------------------------------------------------------------------------- 1 | using NCDC.Basic.User; 2 | 3 | namespace NCDC.ProxyServer.AppServices.Abstractions; 4 | 5 | public interface IAppUserLoader 6 | { 7 | bool AddAppUser(AuthUser authUser); 8 | bool RemoveAppUser(string username); 9 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Bootstrappers/IAppBootstrapper.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ProxyServer.Bootstrappers; 2 | 3 | public interface IAppBootstrapper 4 | { 5 | Task StartAsync(CancellationToken cancellationToken=default); 6 | Task StopAsync(CancellationToken cancellationToken=default); 7 | } -------------------------------------------------------------------------------- /src/bootstrapper/NCDC.WebBootstrapper/Jwt/JwtIssuerOptions.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.WebBootstrapper.Jwt; 2 | 3 | public class JwtIssuerOptions 4 | { 5 | public string Issuer { get; set; } 6 | 7 | public string Audience { get; set; } 8 | 9 | public string SecretKey { get; set; } 10 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/Available/IFromDatabaseAvailable.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Segment.Generic; 2 | 3 | namespace NCDC.CommandParser.Common.Command.Available; 4 | 5 | public interface IFromDatabaseAvailable 6 | { 7 | DatabaseSegment? Database { get; } 8 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Dialect/Command/MySql/DDL/MySqlRenameTableCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command.DDL; 2 | 3 | namespace NCDC.CommandParser.Dialect.Command.MySql.DDL; 4 | 5 | public sealed class MySqlRenameTableCommand:RenameTableCommand,IMySqlCommand 6 | { 7 | 8 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Options/UserOption.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ProxyServer.Options; 2 | 3 | public class UserOption 4 | { 5 | public string UserName { get; set; } 6 | public string Password { get; set; } 7 | public ISet DatabaseNames { get; set; } = new HashSet(); 8 | } -------------------------------------------------------------------------------- /test/NCDC.ShardingTest/Seed/Entities/LogDay.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ShardingTest.Seed.Entities; 2 | 3 | public class LogDay 4 | { 5 | public Guid Id { get; set; } 6 | public string LogLevel { get; set; } 7 | public string LogBody { get; set; } 8 | public DateTime LogTime { get; set; } 9 | } -------------------------------------------------------------------------------- /test/NCDC.ShardingTest/Seed/Entities/LogDayLong.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ShardingTest.Seed.Entities; 2 | 3 | public class LogDayLong 4 | { 5 | public Guid Id { get; set; } 6 | public string LogLevel { get; set; } 7 | public string LogBody { get; set; } 8 | public long LogTime { get; set; } 9 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DAL/ExplainStatement.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Abstractions; 2 | 3 | namespace NCDC.CommandParser.Common.Command.DAL; 4 | 5 | public sealed class ExplainStatement:AbstractSqlCommand,IDALCommand 6 | { 7 | public ISqlCommand? SqlCommand { get; set; } 8 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Dialect/Command/MySql/TCL/MySqlSetTransactionCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command.TCL; 2 | 3 | namespace NCDC.CommandParser.Dialect.Command.MySql.TCL; 4 | 5 | public sealed class MySqlSetTransactionCommand:SetTransactionCommand,IMySqlCommand 6 | { 7 | 8 | } -------------------------------------------------------------------------------- /src/bootstrapper/NCDC.WebBootstrapper/Controllers/AuthUser/Page/AuthUserPageRequest.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.WebBootstrapper.Controllers.AuthUser.Page; 2 | 3 | public class AuthUserPageRequest:PageRequest 4 | { 5 | /// 6 | /// 用户名 7 | /// 8 | public string? UserName { get; set; } 9 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Dialect/Command/MySql/TCL/MySqlBeginTransactionCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command.TCL; 2 | 3 | namespace NCDC.CommandParser.Dialect.Command.MySql.TCL; 4 | 5 | public sealed class MySqlBeginTransactionCommand:BeginTransactionCommand,IMySqlCommand 6 | { 7 | 8 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingRoute/DataSourceRoutes/Abstractions/IDataSourceRouteRuleEngine.cs: -------------------------------------------------------------------------------- 1 | using NCDC.Plugin; 2 | 3 | namespace NCDC.ShardingRoute.DataSourceRoutes.Abstractions; 4 | 5 | public interface IDataSourceRouteRuleEngine 6 | { 7 | DataSourceRouteResult Route(DataSourceRouteRuleContext context); 8 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Abstractions/IASTNode.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Abstractions 2 | { 3 | /* 4 | * @Author: xjm 5 | * @Description: 6 | * @Date: Tuesday, 23 March 2021 21:23:31 7 | * @Email: 326308290@qq.com 8 | */ 9 | public interface IASTNode 10 | { 11 | 12 | } 13 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Constant/CombineTypeEnum.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Constant; 2 | 3 | public enum CombineTypeEnum 4 | { 5 | UNION_ALL, 6 | UNION, 7 | INTERSECT_ALL, 8 | INTERSECT, 9 | EXCEPT_ALL, 10 | EXCEPT, 11 | MINUS_ALL, 12 | MINUS 13 | } -------------------------------------------------------------------------------- /src/core/NCDC.Plugin/DefaultRules/ShardingRuleParams/TableRuleParam.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.Plugin.DefaultRules.ShardingRuleParams; 2 | 3 | public class TableRuleParam:BaseRuleParam 4 | { 5 | public int Mod { get; set; } 6 | public int TailLength { get; set; } 7 | public string TableSeparator { get; set; } = "_"; 8 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Constant/TransactionIsolationLevelEnum.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Constant; 2 | 3 | public enum TransactionIsolationLevelEnum 4 | { 5 | NONE, 6 | READ_UNCOMMITTED, 7 | READ_COMMITTED, 8 | REPEATABLE_READ, 9 | SNAPSHOT, 10 | SERIALIZABLE 11 | } -------------------------------------------------------------------------------- /src/core/NCDC.Plugin/DefaultRules/ShardingRuleParams/BaseRuleParam.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.Plugin.DefaultRules.ShardingRuleParams; 2 | 3 | public class BaseRuleParam 4 | { 5 | public string TableName { get; set; } = null!; 6 | public string ColumnName { get; set; } = null!; 7 | public List? ColumnNames { get; set; } 8 | } -------------------------------------------------------------------------------- /src/core/NCDC.Plugin/TableRouteRules/ITableRuleConfigure.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.Plugin.TableRouteRules; 2 | 3 | public interface ITableRuleConfigure 4 | { 5 | /// 6 | /// 配置对象的分表信息 7 | /// 8 | /// 9 | void Configure(TableRuleConfigureBuilder builder); 10 | } -------------------------------------------------------------------------------- /src/bootstrapper/NCDC.WebBootstrapper/Controllers/User/Info/UserInfoResponse.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.WebBootstrapper.Controllers.User.Info; 2 | 3 | public class UserInfoResponse 4 | { 5 | public string UserId { get; set; } = null!; 6 | public string Username { get; set; }= null!; 7 | public string Account { get; set; }= null!; 8 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DML/EmptyCommand.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Command.DML 2 | { 3 | public sealed class EmptyCommand:AbstractSqlCommand 4 | { 5 | public new int ParameterCount 6 | { 7 | get => 0; 8 | set { } 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingRewrite/Sql/ISqlBuilder.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ShardingRewrite.Sql 2 | { 3 | /* 4 | * @Author: xjm 5 | * @Description: 6 | * @Date: Tuesday, 13 April 2021 20:51:07 7 | * @Email: 326308290@qq.com 8 | */ 9 | public interface ISqlBuilder 10 | { 11 | 12 | string ToSql(); 13 | } 14 | } -------------------------------------------------------------------------------- /src/core/NCDC.Basic/Metadatas/IProxyDatabase.cs: -------------------------------------------------------------------------------- 1 | // using NCDC.Basic.Connection.Abstractions; 2 | // 3 | // namespace NCDC.Basic.Metadatas; 4 | // 5 | // public interface IProxyDatabase 6 | // { 7 | // string DataSourceName { get; } 8 | // bool IsDefault { get; } 9 | // IServerDbConnection CreateServerDbConnection(); 10 | // } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DAL/ShowStatement.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Command.DAL; 2 | 3 | public abstract class ShowStatement:AbstractSqlCommand,IDALCommand 4 | { 5 | public string Name { get; } 6 | 7 | public ShowStatement(string name) 8 | { 9 | Name = name; 10 | } 11 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DAL/UseCommand.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Command.DAL; 2 | 3 | public abstract class UseCommand:AbstractSqlCommand,IDALCommand 4 | { 5 | public string Schema { get; } 6 | 7 | public UseCommand(string schema) 8 | { 9 | Schema = schema; 10 | } 11 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Connection/Abstractions/IServerDbDataReader.cs: -------------------------------------------------------------------------------- 1 | // using System.Data.Common; 2 | // 3 | // namespace NCDC.ProxyServer.Connection.Abstractions; 4 | // 5 | // public interface IServerDbDataReader:IDisposable 6 | // { 7 | // DbDataReader GetDbDataReader(); 8 | // IServerDbConnection GetServerDbConnection(); 9 | // } -------------------------------------------------------------------------------- /src/bootstrapper/NCDC.WebBootstrapper/Controllers/AuthUser/UserDatabasesSave/UserDatabasesSaveRequest.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.WebBootstrapper.Controllers.AuthUser.UserDatabasesSave; 2 | 3 | public class UserDatabasesSaveRequest 4 | { 5 | public string Id { get; set; } 6 | public List CheckedDatabases{ get; set; } = new List(); 7 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Dialect/Command/MySql/TCL/MySqlXACommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command.TCL; 2 | 3 | namespace NCDC.CommandParser.Dialect.Command.MySql.TCL; 4 | 5 | public sealed class MySqlXACommand:XACommand,IMySqlCommand 6 | { 7 | public MySqlXACommand(string op) : base(op) 8 | { 9 | } 10 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyClient/Command/MessageExecutorFactory.cs: -------------------------------------------------------------------------------- 1 | using NCDC.ProxyClient.Command.Abstractions; 2 | 3 | namespace NCDC.ProxyClient.Command; 4 | 5 | public sealed class MessageExecutorFactory:IMessageExecutorFactory 6 | { 7 | public IMessageExecutor Create() 8 | { 9 | return new MessageExecutor(); 10 | } 11 | } -------------------------------------------------------------------------------- /test/NCDC.ShardingTest/Seed/Entities/Order.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using ShardingCore.Core; 3 | 4 | namespace NCDC.ShardingTest.Seed.Entities; 5 | 6 | public class Order 7 | { 8 | public Guid Id { get; set; } 9 | public string Area { get; set; } 10 | public long Money { get; set; } 11 | public DateTime CreateTime { get; set; } 12 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DAL/SetCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Segment.DAL; 2 | 3 | namespace NCDC.CommandParser.Common.Command.DAL; 4 | 5 | public abstract class SetCommand:AbstractSqlCommand,IDALCommand 6 | { 7 | public ICollection VariableAssigns = new LinkedList(); 8 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Constant/OrderDirectionEnum.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Constant 2 | { 3 | /* 4 | * @Author: xjm 5 | * @Description: 6 | * @Date: Sunday, 11 April 2021 15:40:03 7 | * @Email: 326308290@qq.com 8 | */ 9 | public enum OrderDirectionEnum 10 | { 11 | ASC, 12 | DESC 13 | } 14 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Connection/Abstractions/IServerDbTransaction.cs: -------------------------------------------------------------------------------- 1 | // namespace NCDC.ProxyServer.Connection.Abstractions; 2 | // 3 | // public interface IServerDbTransaction:IDisposable 4 | // { 5 | // ValueTask CommitTransactionAsync(); 6 | // ValueTask RollbackTransactionAsync(); 7 | // IServerDbConnection GetServerDbConnection(); 8 | // } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingRewrite/Abstractions/ISqlRewriterContextFactory.cs: -------------------------------------------------------------------------------- 1 | 2 | using NCDC.ShardingParser; 3 | using NCDC.ShardingRoute; 4 | 5 | namespace NCDC.ShardingRewrite.Abstractions; 6 | 7 | public interface ISqlRewriterContextFactory 8 | { 9 | SqlRewriteContext Rewrite(SqlParserResult sqlParserResult, RouteContext routeContext); 10 | } -------------------------------------------------------------------------------- /src/bootstrapper/NCDC.WebBootstrapper/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.WebBootstrapper; 2 | 3 | public class WeatherForecast 4 | { 5 | public DateTime Date { get; set; } 6 | 7 | public int TemperatureC { get; set; } 8 | 9 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 10 | 11 | public string? Summary { get; set; } 12 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Abstractions/SqlLexer/ISqlLexer.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Abstractions.SqlLexer 2 | { 3 | /* 4 | * @Author: xjm 5 | * @Description: 6 | * @Date: 2021/4/20 8:37:57 7 | * @Ver: 1.0 8 | * @Email: 326308290@qq.com 9 | */ 10 | public interface ISqlLexer 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/DML/Item/IProjectionSegment.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Segment.DML.Item 2 | { 3 | /* 4 | * @Author: xjm 5 | * @Description: 6 | * @Date: Sunday, 11 April 2021 13:19:10 7 | * @Email: 326308290@qq.com 8 | */ 9 | public interface IProjectionSegment:ISqlSegment 10 | { 11 | 12 | } 13 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/Generic/IRemoveAvailable.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Segment.Generic 2 | { 3 | /* 4 | * @Author: xjm 5 | * @Description: 6 | * @Date: Monday, 12 April 2021 22:02:33 7 | * @Email: 326308290@qq.com 8 | */ 9 | public interface IRemoveAvailable:ISqlSegment 10 | { 11 | 12 | } 13 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Dialect/Command/MySql/DDL/MySqlAlterDatabaseCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command; 2 | using NCDC.CommandParser.Common.Command.DDL; 3 | 4 | namespace NCDC.CommandParser.Dialect.Command.MySql.DDL; 5 | 6 | public sealed class MySqlAlterDatabaseCommand:AbstractSqlCommand,IDDLCommand,IMySqlCommand 7 | { 8 | 9 | } -------------------------------------------------------------------------------- /src/protocol/NCDC.Protocol/MySql/Constant/MySqlConstants.cs: -------------------------------------------------------------------------------- 1 | // using DotNetty.Common.Utilities; 2 | // 3 | // namespace NCDC.Protocol.MySql.Constant; 4 | // 5 | // public class MySqlConstants 6 | // { 7 | // 8 | // public static readonly AttributeKey MYSQL_OPTION_MULTI_STATEMENTS=AttributeKey.ValueOf("MYSQL_OPTION_MULTI_STATEMENTS"); 9 | // } -------------------------------------------------------------------------------- /src/core/NCDC/DataSource/IDataSourceMetaData.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.DataSource 2 | { 3 | /* 4 | * @Author: xjm 5 | * @Description: 6 | * @Date: 2021/4/19 13:52:17 7 | * @Ver: 1.0 8 | * @Email: 326308290@qq.com 9 | */ 10 | public interface IDataSourceMetaData 11 | { 12 | string GetConnectionString(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/TCL/XACommand.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Command.TCL; 2 | 3 | public abstract class XACommand: AbstractSqlCommand, ITCLCommand 4 | { 5 | protected XACommand(string op) 6 | { 7 | Op = op; 8 | } 9 | 10 | public string Op { get; } 11 | public string? XId { get; set; } 12 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Exceptions/SqlParsingException.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace NCDC.CommandParser.Exceptions; 4 | 5 | public class SqlParsingException:SqlParsingBaseException 6 | { 7 | public SqlParsingException(string sql) : base($"You have an error in your SQL syntax: {sql}") 8 | { 9 | } 10 | 11 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyClient/Exceptions/NotSupportedCommandException.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ProxyClient.Exceptions; 2 | 3 | public class NotSupportedCommandException:ClientException 4 | { 5 | private readonly string _commandType; 6 | 7 | public NotSupportedCommandException(string commandType) 8 | { 9 | _commandType = commandType; 10 | } 11 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyClientMySql/Authentication/Authenticator/IMySqlAuthenticator.cs: -------------------------------------------------------------------------------- 1 | 2 | using NCDC.Basic.User; 3 | using NCDC.ProxyClient.Authentication; 4 | 5 | namespace NCDC.ProxyClientMySql.Authentication.Authenticator; 6 | 7 | public interface IMySqlAuthenticator:IAuthenticator 8 | { 9 | bool Authenticate(AuthUser user, byte[] authResponse); 10 | } -------------------------------------------------------------------------------- /src/bootstrapper/NCDC.WebBootstrapper/Controllers/AuthUser/UserDatabases/UserDatabasesRequest.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace NCDC.WebBootstrapper.Controllers.AuthUser.UserDatabases; 4 | 5 | public class UserDatabasesRequest 6 | { 7 | [Display(Name = "用户id"),Required(ErrorMessage = "{0}不能为空")] 8 | public string Id { get; set; } 9 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DAL/AnalyzeTableStatement.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Segment.Generic.Table; 2 | 3 | namespace NCDC.CommandParser.Common.Command.DAL; 4 | 5 | public abstract class AnalyzeTableStatement:AbstractSqlCommand,IDALCommand 6 | { 7 | public ICollection Tables = new List(); 8 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingRewrite/Token/Generator/IIgnoreForSingleRoute.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ShardingRewrite.Token.Generator 2 | { 3 | /* 4 | * @Author: xjm 5 | * @Description: 6 | * @Date: 2021/4/27 8:56:02 7 | * @Ver: 1.0 8 | * @Email: 326308290@qq.com 9 | */ 10 | public interface IIgnoreForSingleRoute 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Abstractions/IServerDataReaderFactory.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Abstractions; 2 | using NCDC.CommandParser.Common.Command; 3 | using NCDC.ProxyServer.Connection.Abstractions; 4 | 5 | namespace NCDC.ProxyServer.Abstractions; 6 | 7 | public interface IServerDataReaderFactory 8 | { 9 | IServerDataReader Create(IQueryContext queryContext); 10 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/DAL/VariableAssignSegment.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Segment.DAL; 2 | 3 | public sealed class VariableAssignSegment:ISqlSegment 4 | { 5 | public int StartIndex { get; set; } 6 | public int StopIndex { get; set; } 7 | public VariableSegment? Variable { get; set; } 8 | public string? AssignValue { get; set; } 9 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/AppServices/Abstractions/IUserDatabaseMappingLoader.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ProxyServer.AppServices.Abstractions; 2 | 3 | public interface IUserDatabaseMappingLoader 4 | { 5 | bool AddUserDatabaseMapping(UserDatabaseEntry entry); 6 | bool RemoveUserDatabaseMapping(UserDatabaseEntry entry); 7 | bool ContainsUserDatabaseMapping(UserDatabaseEntry entry); 8 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Connection/Abstractions/IServerDbCommand.cs: -------------------------------------------------------------------------------- 1 | // using System.Data.Common; 2 | // 3 | // namespace NCDC.ProxyServer.Connection.Abstractions; 4 | // 5 | // public interface IServerDbCommand:IDisposable 6 | // { 7 | // DbCommand GetDbCommand(); 8 | // IServerDbDataReader ExecuteReader(); 9 | // IServerDbConnection GetServerDbConnection(); 10 | // } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DCL/AlterRoleCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NCDC.CommandParser.Common.Command.DCL 4 | { 5 | /* 6 | * @Author: xjm 7 | * @Description: 8 | * @Date: Tuesday, 20 April 2021 21:26:57 9 | * @Email: 326308290@qq.com 10 | */ 11 | public abstract class AlterRoleCommand:AbstractSqlCommand,IDCLCommand 12 | { 13 | } 14 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DML/DoCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NCDC.CommandParser.Common.Command.DML 4 | { 5 | /* 6 | * @Author: xjm 7 | * @Description: 8 | * @Date: Tuesday, 20 April 2021 22:01:55 9 | * @Email: 326308290@qq.com 10 | */ 11 | public abstract class DoCommand: AbstractSqlCommand, IDMLCommand 12 | { 13 | 14 | } 15 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/DML/Expr/IExpressionSegment.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Segment.DML.Expr 2 | { 3 | /* 4 | * @Author: xjm 5 | * @Description: 6 | * @Date: 2021/4/12 8:11:51 7 | * @Ver: 1.0 8 | * @Email: 326308290@qq.com 9 | */ 10 | public interface IExpressionSegment:ISqlSegment 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/bootstrapper/NCDC.WebBootstrapper/Controllers/ActualDatabase/All/ActualDatabaseAllResponse.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.WebBootstrapper.Controllers.ActualDatabase.All; 2 | 3 | public class ActualDatabaseAllResponse 4 | { 5 | public string Id { get; set; } = null!; 6 | /// 7 | /// 数据源名称 8 | /// 9 | public string DataSourceName { get; set; } = null!; 10 | } -------------------------------------------------------------------------------- /src/core/NCDC/Enums/TransactionTypeEnum.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.Enums 2 | { 3 | /* 4 | * @Author: xjm 5 | * @Description: 6 | * @Date: 2021/04/16 00:00:00 7 | * @Ver: 1.0 8 | * @Email: 326308290@qq.com 9 | */ 10 | /// 11 | /// 12 | /// 13 | public enum TransactionTypeEnum 14 | { 15 | LOCAL//, XA, BASE 16 | } 17 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DML/CallCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NCDC.CommandParser.Common.Command.DML 4 | { 5 | /* 6 | * @Author: xjm 7 | * @Description: 8 | * @Date: Tuesday, 20 April 2021 21:58:27 9 | * @Email: 326308290@qq.com 10 | */ 11 | public abstract class CallCommand:AbstractSqlCommand,IDMLCommand 12 | { 13 | 14 | } 15 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/Generic/Table/ITableSegment.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Segment.Generic.Table 2 | { 3 | /* 4 | * @Author: xjm 5 | * @Description: 6 | * @Date: 2021/4/10 9:50:30 7 | * @Ver: 1.0 8 | * @Email: 326308290@qq.com 9 | */ 10 | public interface ITableSegment:IAliasAvailable 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Dialect/Command/MySql/TCL/MySqlSavepointCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command.TCL; 2 | 3 | namespace NCDC.CommandParser.Dialect.Command.MySql.TCL; 4 | 5 | public sealed class MySqlSavepointCommand:SavepointCommand,IMySqlCommand 6 | { 7 | public MySqlSavepointCommand(string savepointName) : base(savepointName) 8 | { 9 | } 10 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyClientMySql/Common/MySqlConnectionPhaseEnum.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ProxyClientMySql.Common; 2 | 3 | /// 4 | /// Connection Phase 5 | /// 6 | public enum MySqlConnectionPhaseEnum 7 | { 8 | INITIAL_HANDSHAKE, AUTH_PHASE_FAST_PATH, AUTHENTICATION_METHOD_MISMATCH 9 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Abstractions/ICommandListener.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ProxyServer.Abstractions; 2 | 3 | public delegate ValueTask ReceivedDelegate(ICommand messageSender); 4 | public interface ICommandListener 5 | { 6 | /// 7 | /// 接收到的消息 8 | /// 9 | event ReceivedDelegate OnReceived; 10 | 11 | ValueTask Received(ICommand messageSender); 12 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Connection/IConnectionSessionFactory.cs: -------------------------------------------------------------------------------- 1 | using DotNetty.Transport.Channels; 2 | using NCDC.Basic.User; 3 | using NCDC.ProxyServer.Connection.Abstractions; 4 | 5 | namespace NCDC.ProxyServer.Connection; 6 | 7 | public interface IConnectionSessionFactory 8 | { 9 | IConnectionSession Create(int connectionId,string database,Grantee grantee,IChannel channel); 10 | } -------------------------------------------------------------------------------- /src/core/NCDC.Plugin/DataSourceRouteRules/IDataSourceRuleConfigure.cs: -------------------------------------------------------------------------------- 1 | using NCDC.Plugin.TableRouteRules; 2 | 3 | namespace NCDC.Plugin.DataSourceRouteRules; 4 | 5 | public interface IDataSourceRuleConfigure 6 | { 7 | /// 8 | /// 配置对象的分库信息 9 | /// 10 | /// 11 | void Configure(DataSourceRuleConfigureBuilder builder); 12 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Abstractions/SqlParser/ISqlParser.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace NCDC.CommandParser.Abstractions.SqlParser 3 | { 4 | /* 5 | * @Author: xjm 6 | * @Description: 7 | * @Date: 2021/4/20 8:39:22 8 | * @Ver: 1.0 9 | * @Email: 326308290@qq.com 10 | */ 11 | public interface ISqlParser 12 | { 13 | IASTNode Parse(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Abstractions/Visitor/Commands/IDALVisitor.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace NCDC.CommandParser.Abstractions.Visitor.Commands 3 | { 4 | /* 5 | * @Author: xjm 6 | * @Description: 7 | * @Date: 2021/4/20 8:42:56 8 | * @Ver: 1.0 9 | * @Email: 326308290@qq.com 10 | */ 11 | public interface IDALVisitor:ISqlTypeVisitor 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Abstractions/Visitor/Commands/IDCLVisitor.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace NCDC.CommandParser.Abstractions.Visitor.Commands 3 | { 4 | /* 5 | * @Author: xjm 6 | * @Description: 7 | * @Date: 2021/4/20 8:43:10 8 | * @Ver: 1.0 9 | * @Email: 326308290@qq.com 10 | */ 11 | public interface IDCLVisitor:ISqlTypeVisitor 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Abstractions/Visitor/Commands/IDDLVisitor.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace NCDC.CommandParser.Abstractions.Visitor.Commands 3 | { 4 | /* 5 | * @Author: xjm 6 | * @Description: 7 | * @Date: 2021/4/20 8:43:24 8 | * @Ver: 1.0 9 | * @Email: 326308290@qq.com 10 | */ 11 | public interface IDDLVisitor:ISqlTypeVisitor 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Abstractions/Visitor/Commands/IDMLVisitor.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace NCDC.CommandParser.Abstractions.Visitor.Commands 3 | { 4 | /* 5 | * @Author: xjm 6 | * @Description: 7 | * @Date: 2021/4/20 8:43:41 8 | * @Ver: 1.0 9 | * @Email: 326308290@qq.com 10 | */ 11 | public interface IDMLVisitor:ISqlTypeVisitor 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Abstractions/Visitor/Commands/IRLVisitor.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace NCDC.CommandParser.Abstractions.Visitor.Commands 3 | { 4 | /* 5 | * @Author: xjm 6 | * @Description: 7 | * @Date: 2021/4/20 8:43:56 8 | * @Ver: 1.0 9 | * @Email: 326308290@qq.com 10 | */ 11 | public interface IRLVisitor:ISqlTypeVisitor 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Abstractions/Visitor/Commands/ITCLVisitor.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace NCDC.CommandParser.Abstractions.Visitor.Commands 3 | { 4 | /* 5 | * @Author: xjm 6 | * @Description: 7 | * @Date: 2021/4/20 8:44:55 8 | * @Ver: 1.0 9 | * @Email: 326308290@qq.com 10 | */ 11 | public interface ITCLVisitor:ISqlTypeVisitor 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DCL/DropRoleCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NCDC.CommandParser.Common.Command.DCL 4 | { 5 | /* 6 | * @Author: xjm 7 | * @Description: 8 | * @Date: Tuesday, 20 April 2021 21:28:37 9 | * @Email: 326308290@qq.com 10 | */ 11 | public abstract class DropRoleCommand:AbstractSqlCommand,IDCLCommand 12 | { 13 | 14 | } 15 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DCL/SetRoleCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NCDC.CommandParser.Common.Command.DCL 4 | { 5 | /* 6 | * @Author: xjm 7 | * @Description: 8 | * @Date: Tuesday, 20 April 2021 21:31:46 9 | * @Email: 326308290@qq.com 10 | */ 11 | public abstract class SetRoleCommand:AbstractSqlCommand,IDCLCommand 12 | { 13 | 14 | } 15 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/TCL/CommitCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NCDC.CommandParser.Common.Command.TCL 4 | { 5 | /* 6 | * @Author: xjm 7 | * @Description: 8 | * @Date: Tuesday, 20 April 2021 22:16:58 9 | * @Email: 326308290@qq.com 10 | */ 11 | public abstract class CommitCommand:AbstractSqlCommand,ITCLCommand 12 | { 13 | 14 | } 15 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Dialect/Command/MySql/TCL/MySqlSetAutoCommitCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command.TCL; 2 | 3 | namespace NCDC.CommandParser.Dialect.Command.MySql.TCL; 4 | 5 | public sealed class MySqlSetAutoCommitCommand:SetAutoCommitCommand,IMySqlCommand 6 | { 7 | public MySqlSetAutoCommitCommand(bool autoCommit) : base(autoCommit) 8 | { 9 | } 10 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Exceptions/SqlASTVisitorException.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | using Antlr4.Runtime.Tree; 3 | 4 | namespace NCDC.CommandParser.Exceptions; 5 | 6 | public class SqlASTVisitorException:SqlParsingBaseException 7 | { 8 | 9 | public SqlASTVisitorException(Type type) : base($"Can not accept SQL type {type.FullName}") 10 | { 11 | } 12 | } -------------------------------------------------------------------------------- /src/protocol/NCDC.Protocol/Packets/IPacket.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.Protocol.Packets; 2 | 3 | public interface IPacket 4 | { 5 | void WriteTo(IPacketPayload payload); 6 | } 7 | public interface IPacket :IPacket where T:IPacketPayload 8 | { 9 | void WriteTo(T payload); 10 | 11 | void IPacket.WriteTo(IPacketPayload payload) 12 | { 13 | WriteTo((T)payload); 14 | } 15 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Connection/DefaultConnectionInvokeReply.cs: -------------------------------------------------------------------------------- 1 | // using NCDC.ProxyServer.Connection.Abstractions; 2 | // 3 | // namespace NCDC.ProxyServer.Connection; 4 | // 5 | // public class DefaultConnectionInvokeReply:IConnectionInvokeReply 6 | // { 7 | // public ValueTask Process(IServerDbConnection target) 8 | // { 9 | // 10 | // } 11 | // } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingMerge/Abstractions/IDataReaderMergerFactory.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Abstractions; 2 | using NCDC.CommandParser.Common.Command; 3 | using NCDC.ShardingParser.Command; 4 | 5 | namespace NCDC.ShardingMerge.Abstractions; 6 | 7 | public interface IDataReaderMergerFactory 8 | { 9 | IDataReaderMerger Create(ISqlCommandContext sqlCommandContext); 10 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingRewrite/Sql/Token/SimpleObject/IAttachable.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ShardingRewrite.Sql.Token.SimpleObject 2 | { 3 | /* 4 | * @Author: xjm 5 | * @Description: 6 | * @Date: 2021/4/24 10:46:36 7 | * @Ver: 1.0 8 | * @Email: 326308290@qq.com 9 | */ 10 | public interface IAttachable 11 | { 12 | int GetStartIndex(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DCL/CreateRoleCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NCDC.CommandParser.Common.Command.DCL 4 | { 5 | /* 6 | * @Author: xjm 7 | * @Description: 8 | * @Date: Tuesday, 20 April 2021 21:27:41 9 | * @Email: 326308290@qq.com 10 | */ 11 | public abstract class CreateRoleCommand:AbstractSqlCommand,IDCLCommand 12 | { 13 | 14 | } 15 | } -------------------------------------------------------------------------------- /src/core/NCDC.Plugin/NCDC.Plugin.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/RL/IRLCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NCDC.CommandParser.Abstractions; 3 | 4 | namespace NCDC.CommandParser.Common.Command.RL 5 | { 6 | /* 7 | * @Author: xjm 8 | * @Description: 9 | * @Date: Tuesday, 20 April 2021 22:12:57 10 | * @Email: 326308290@qq.com 11 | */ 12 | public interface IRLCommand:ISqlCommand 13 | { 14 | 15 | } 16 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingParser/Abstractions/ISqlCommandContextFactory.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command; 2 | using NCDC.ShardingAdoNet; 3 | using NCDC.ShardingParser.Command; 4 | 5 | namespace NCDC.ShardingParser.Abstractions; 6 | 7 | public interface ISqlCommandContextFactory 8 | { 9 | ISqlCommandContext Create(ParameterContext parameterContext, ISqlCommand sqlCommand); 10 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DDL/IDDLCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NCDC.CommandParser.Abstractions; 3 | 4 | namespace NCDC.CommandParser.Common.Command.DDL 5 | { 6 | /* 7 | * @Author: xjm 8 | * @Description: 9 | * @Date: Tuesday, 20 April 2021 21:37:29 10 | * @Email: 326308290@qq.com 11 | */ 12 | public interface IDDLCommand:ISqlCommand 13 | { 14 | 15 | } 16 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/TCL/ITCLCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NCDC.CommandParser.Abstractions; 3 | 4 | namespace NCDC.CommandParser.Common.Command.TCL 5 | { 6 | /* 7 | * @Author: xjm 8 | * @Description: 9 | * @Date: Tuesday, 20 April 2021 22:16:06 10 | * @Email: 326308290@qq.com 11 | */ 12 | public interface ITCLCommand:ISqlCommand 13 | { 14 | 15 | } 16 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Runtimes/Builder/ActualTableNode.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ProxyServer.Runtimes.Builder; 2 | 3 | public sealed class ActualTableNode 4 | { 5 | public string DataSource { get; } 6 | public string TableName { get; } 7 | 8 | public ActualTableNode(string dataSource,string tableName) 9 | { 10 | DataSource = dataSource; 11 | TableName = tableName; 12 | } 13 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/StreamMerges/IExecutor.cs: -------------------------------------------------------------------------------- 1 | 2 | using NCDC.ProxyServer.Executors; 3 | 4 | namespace NCDC.ProxyServer.StreamMerges; 5 | 6 | public interface IExecutor 7 | { 8 | IShardingMerger GetShardingMerger(); 9 | Task> ExecuteAsync(DataSourceSqlExecutorUnit dataSourceSqlExecutorUnit, CancellationToken cancellationToken = new CancellationToken()); 10 | } -------------------------------------------------------------------------------- /src/core/NCDC/DataStructure/RangeStructure/BoundType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NCDC.DataStructure.RangeStructure 4 | { 5 | /* 6 | * @Author: xjm 7 | * @Description: 8 | * @Date: 2021/4/28 15:09:29 9 | * @Ver: 1.0 10 | * @Email: 326308290@qq.com 11 | */ 12 | [Serializable] 13 | public enum BoundType 14 | { 15 | OPEN, 16 | CLOSED 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DML/IDMLCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Abstractions; 2 | 3 | namespace NCDC.CommandParser.Common.Command.DML 4 | { 5 | /* 6 | * @Author: xjm 7 | * @Description: 8 | * @Date: 2021/4/10 9:30:27 9 | * @Ver: 1.0 10 | * @Email: 326308290@qq.com 11 | */ 12 | public interface IDMLCommand:ISqlCommand 13 | { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/TCL/BeginTransactionCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NCDC.CommandParser.Common.Command.TCL 4 | { 5 | /* 6 | * @Author: xjm 7 | * @Description: 8 | * @Date: Tuesday, 20 April 2021 22:16:32 9 | * @Email: 326308290@qq.com 10 | */ 11 | public abstract class BeginTransactionCommand:AbstractSqlCommand,ITCLCommand 12 | { 13 | 14 | } 15 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingParser/Command/IIndexAvailable.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Segment.DDL.Index; 2 | 3 | namespace NCDC.ShardingParser.Command 4 | { 5 | /* 6 | * @Author: xjm 7 | * @Description: 8 | * @Date: Tuesday, 27 April 2021 21:50:06 9 | * @Email: 326308290@qq.com 10 | */ 11 | public interface IIndexAvailable 12 | { 13 | ICollection GetIndexes(); 14 | } 15 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingParser/Command/IWhereAvailable.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Segment.DML.Predicate; 2 | 3 | namespace NCDC.ShardingParser.Command 4 | { 5 | /* 6 | * @Author: xjm 7 | * @Description: 8 | * @Date: Sunday, 11 April 2021 14:53:12 9 | * @Email: 326308290@qq.com 10 | */ 11 | public interface IWhereAvailable 12 | { 13 | 14 | WhereSegment? GetWhere(); 15 | } 16 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/DML/Expr/Simple/ISimpleExpressionSegment.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Segment.DML.Expr.Simple 2 | { 3 | /* 4 | * @Author: xjm 5 | * @Description: 6 | * @Date: 2021/4/12 12:48:54 7 | * @Ver: 1.0 8 | * @Email: 326308290@qq.com 9 | */ 10 | public interface ISimpleExpressionSegment:IExpressionSegment 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/Generic/IOwnerAvailable.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Segment.Generic 2 | { 3 | /* 4 | * @Author: xjm 5 | * @Description: 6 | * @Date: 2021/4/10 9:52:37 7 | * @Ver: 1.0 8 | * @Email: 326308290@qq.com 9 | */ 10 | public interface IOwnerAvailable:ISqlSegment 11 | { 12 | OwnerSegment? Owner { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Core/Cahce/ParseCacheOption.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Core.Cahce; 2 | 3 | public class ParseCacheOption 4 | { 5 | public int InitialCapacity { get; } 6 | public long MaximumSize { get; } 7 | 8 | public ParseCacheOption(int initialCapacity,long maximumSize) 9 | { 10 | InitialCapacity = initialCapacity; 11 | MaximumSize = maximumSize; 12 | } 13 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Abstractions/IServerDataReader.cs: -------------------------------------------------------------------------------- 1 | using NCDC.ProxyServer.Binaries; 2 | using NCDC.ProxyServer.StreamMerges; 3 | 4 | namespace NCDC.ProxyServer.Abstractions; 5 | 6 | public interface IServerDataReader:IDisposable 7 | { 8 | Task ExecuteDbDataReaderAsync(CancellationToken cancellationToken=new CancellationToken()); 9 | 10 | bool Read(); 11 | BinaryRow GetRowData(); 12 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingRewrite/Sql/Token/SimpleObject/IRouteUnitAware.cs: -------------------------------------------------------------------------------- 1 | 2 | using NCDC.ShardingRoute; 3 | 4 | namespace NCDC.ShardingRewrite.Sql.Token.SimpleObject 5 | { 6 | /* 7 | * @Author: xjm 8 | * @Description: 9 | * @Date: Tuesday, 13 April 2021 21:05:09 10 | * @Email: 326308290@qq.com 11 | */ 12 | public interface IRouteUnitAware 13 | { 14 | string ToString(RouteUnit routeUnit); 15 | } 16 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/Generic/WindowSegment.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Segment.Generic; 2 | 3 | public sealed class WindowSegment:ISqlSegment 4 | { 5 | public WindowSegment(int startIndex, int stopIndex) 6 | { 7 | StartIndex = startIndex; 8 | StopIndex = stopIndex; 9 | } 10 | 11 | public int StartIndex { get; } 12 | public int StopIndex { get; } 13 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Dialect/Command/MySql/TCL/MySqlLockCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command.TCL; 2 | using NCDC.CommandParser.Common.Segment.Generic.Table; 3 | 4 | namespace NCDC.CommandParser.Dialect.Command.MySql.TCL; 5 | 6 | public sealed class MySqlLockCommand:LockCommand,IMySqlCommand 7 | { 8 | public ICollection Tables = new LinkedList(); 9 | 10 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/ServerHandlers/ServerTransactions/TransactionHolder.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ProxyServer.ServerHandlers.ServerTransactions; 2 | 3 | public class TransactionHolder 4 | { 5 | private static AsyncLocal _inTransaction = new AsyncLocal(); 6 | public static bool? InTransaction 7 | { 8 | get => _inTransaction.Value; 9 | set => _inTransaction.Value = value; 10 | } 11 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DAL/ResetParameterStatement.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Command.DAL; 2 | 3 | public abstract class ResetParameterStatement:AbstractSqlCommand,IDALCommand 4 | { 5 | public string ConfigurationParameter { get; } 6 | 7 | public ResetParameterStatement(string configurationParameter) 8 | { 9 | ConfigurationParameter = configurationParameter; 10 | } 11 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Executors/IShardingExecutionContextFactory.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Abstractions; 2 | using NCDC.CommandParser.Common.Command; 3 | using NCDC.ProxyServer.Connection; 4 | using NCDC.ProxyServer.Connection.Abstractions; 5 | 6 | namespace NCDC.ProxyServer.Executors; 7 | 8 | public interface IShardingExecutionContextFactory 9 | { 10 | ShardingExecutionContext Create(IQueryContext queryContext); 11 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingRoute/DataSourceRoutes/DataSourceRouteRuleContext.cs: -------------------------------------------------------------------------------- 1 | using NCDC.ShardingParser; 2 | 3 | namespace NCDC.ShardingRoute.DataSourceRoutes; 4 | 5 | public sealed class DataSourceRouteRuleContext 6 | { 7 | public SqlParserResult SqlParserResult { get; } 8 | 9 | public DataSourceRouteRuleContext(SqlParserResult sqlParserResult) 10 | { 11 | SqlParserResult = sqlParserResult; 12 | } 13 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/TCL/RollbackCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NCDC.CommandParser.Common.Command.TCL 4 | { 5 | /* 6 | * @Author: xjm 7 | * @Description: 8 | * @Date: Tuesday, 20 April 2021 22:17:19 9 | * @Email: 326308290@qq.com 10 | */ 11 | public abstract class RollbackCommand: AbstractSqlCommand, ITCLCommand 12 | { 13 | public string? SavepointName { get; set; } 14 | } 15 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/DML/Pagination/INumberLiteralPaginationValueSegment.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Segment.DML.Pagination 2 | { 3 | /* 4 | * @Author: xjm 5 | * @Description: 6 | * @Date: Sunday, 11 April 2021 16:04:49 7 | * @Email: 326308290@qq.com 8 | */ 9 | public interface INumberLiteralPaginationValueSegment:IPaginationValueSegment 10 | { 11 | long Value { get; } 12 | } 13 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Dialect/Command/MySql/DDL/MySqlDropTableCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command.DDL; 2 | 3 | namespace NCDC.CommandParser.Dialect.Command.MySql.DDL; 4 | 5 | public sealed class MySqlDropTableCommand:DropTableCommand,IMySqlCommand 6 | { 7 | public bool IfExists { get; } 8 | 9 | public MySqlDropTableCommand(bool ifExists) 10 | { 11 | IfExists = ifExists; 12 | } 13 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/ServerHandlers/Results/AffectRowUnitResult.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ProxyServer.ServerHandlers.Results; 2 | 3 | public sealed class AffectRowUnitResult 4 | { 5 | public int UpdateCount { get; } 6 | public long LastInsertId { get; } 7 | 8 | public AffectRowUnitResult(int updateCount,long lastInsertId) 9 | { 10 | UpdateCount = updateCount; 11 | LastInsertId = lastInsertId; 12 | } 13 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Value/IValueASTNode.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Abstractions; 2 | 3 | 4 | namespace NCDC.CommandParser.Common.Value 5 | { 6 | /* 7 | * @Author: xjm 8 | * @Description: 9 | * @Date: 2021/4/10 10:09:53 10 | * @Ver: 1.0 11 | * @Email: 326308290@qq.com 12 | */ 13 | public interface IValueASTNode:IASTNode 14 | { 15 | T Value { get; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Dialect/Command/MySql/DAL/MySqlShowDatabasesCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command; 2 | using NCDC.CommandParser.Common.Command.DAL; 3 | using NCDC.CommandParser.Common.Segment.DAL; 4 | 5 | namespace NCDC.CommandParser.Dialect.Command.MySql.DAL; 6 | 7 | public sealed class MySqlShowDatabasesCommand:AbstractSqlCommand,IDALCommand 8 | { 9 | public ShowFilterSegment? Filter { get; set; } 10 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingParser/NCDC.ShardingParser.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyClient/NCDC.ProxyClient.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyClientMySql/NCDC.ProxyClientMySql.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Abstractions/IServerHandlerFactory.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Abstractions; 2 | using NCDC.CommandParser.Common.Command; 3 | using NCDC.Enums; 4 | using NCDC.ProxyServer.Connection.Abstractions; 5 | 6 | namespace NCDC.ProxyServer.Abstractions; 7 | 8 | public interface IServerHandlerFactory 9 | { 10 | IServerHandler Create(string sql, ISqlCommand sqlCommand, 11 | IConnectionSession connectionSession); 12 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/AppServices/Abstractions/IAppRuntimeLoader.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | using NCDC.ProxyServer.Runtimes; 3 | 4 | namespace NCDC.ProxyServer.AppServices.Abstractions; 5 | 6 | public interface IAppRuntimeLoader 7 | { 8 | bool LoadRuntimeContext(IRuntimeContext runtimeContext); 9 | bool UnLoadRemoveRuntimeContext(string databaseName,[MaybeNullWhen(false)] out IRuntimeContext runtimeContext); 10 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DCL/IDCLCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NCDC.CommandParser.Abstractions; 3 | using NCDC.CommandParser.Common.Segment; 4 | 5 | namespace NCDC.CommandParser.Common.Command.DCL 6 | { 7 | /* 8 | * @Author: xjm 9 | * @Description: 10 | * @Date: Tuesday, 20 April 2021 21:26:13 11 | * @Email: 326308290@qq.com 12 | */ 13 | public interface IDCLCommand:ISqlCommand 14 | { 15 | 16 | } 17 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingMerge/Abstractions/IDataReaderMerger.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Abstractions; 2 | using NCDC.CommandParser.Common.Command; 3 | using NCDC.ShardingParser.Command; 4 | using NCDC.StreamDataReaders; 5 | 6 | namespace NCDC.ShardingMerge.Abstractions; 7 | 8 | public interface IDataReaderMerger 9 | { 10 | IStreamDataReader Merge(List streamDataReaders, ISqlCommandContext sqlCommandContext); 11 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingMerge/NCDC.ShardingMerge.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingRewrite/NCDC.ShardingRewrite.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/ShardingRoutePluginTest/ShardingRoutePluginTest.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/DML/Expr/Complex/IComplexExpressionSegment.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Segment.DML.Expr.Complex 2 | { 3 | /* 4 | * @Author: xjm 5 | * @Description: 6 | * @Date: 2021/4/12 8:11:29 7 | * @Ver: 1.0 8 | * @Email: 326308290@qq.com 9 | */ 10 | public interface IComplexExpressionSegment:IExpressionSegment 11 | { 12 | string Text { get; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/Generic/IAliasAvailable.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Segment.Generic 2 | { 3 | /* 4 | * @Author: xjm 5 | * @Description: 6 | * @Date: 2021/4/10 9:52:19 7 | * @Ver: 1.0 8 | * @Email: 326308290@qq.com 9 | */ 10 | public interface IAliasAvailable: ISqlSegment 11 | { 12 | string? GetAlias(); 13 | void SetAlias(AliasSegment? alias); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/orm/NCDC.EntityFrameworkCore/Entities/Base/BaseEntity.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.EntityFrameworkCore.Entities.Base; 2 | 3 | public abstract class BaseEntity:IEntity,ICreateTime,IUpdateTime,IVersion,ILogicDelete 4 | { 5 | public string Id { get; set; } = null!; 6 | public DateTime CreateTime { get; set; } 7 | public DateTime UpdateTime { get; set; } 8 | public string Version { get; set; } = null!; 9 | public bool IsDelete { get; set; } 10 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyClient/Abstractions/IClientQueryDataReader.cs: -------------------------------------------------------------------------------- 1 | using NCDC.Protocol.Packets; 2 | using NCDC.ProxyServer.Commons; 3 | 4 | namespace NCDC.ProxyClient.Abstractions; 5 | 6 | public interface IClientQueryDataReader:IClientDataReader 7 | { 8 | ResultTypeEnum ResultType { get; } 9 | 10 | } 11 | 12 | public interface IClientQueryDataReader : IClientQueryDataReader, IClientDataReader where T : IPacketPayload 13 | { 14 | 15 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyStarter/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "DatabaseType": "MySql", 9 | "StorageType": "MySql", 10 | "ConnectionString": "server=127.0.0.1;port=3306;database=ncdcdb;userid=root;password=root;", 11 | "Port": 3307, 12 | "RoutePluginPath": "rule/test", 13 | "LogEncode":false, 14 | "LogDecode":true 15 | } -------------------------------------------------------------------------------- /src/core/NCDC/Base/DoOnlyOnce.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.Base; 2 | 3 | public sealed class DoOnlyOnce 4 | { 5 | private const int Did = 1; 6 | private const int UnDo = 0; 7 | private int Status = UnDo; 8 | 9 | public bool IsUnDo() 10 | { 11 | return Interlocked.CompareExchange(ref Status, Did, UnDo) == UnDo; 12 | } 13 | 14 | public void Reset() 15 | { 16 | Interlocked.Exchange(ref Status, UnDo); 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DDL/PrepareCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command.DML; 2 | 3 | namespace NCDC.CommandParser.Common.Command.DDL; 4 | 5 | public abstract class PrepareCommand:AbstractSqlCommand,IDDLCommand 6 | { 7 | public SelectCommand? Select { get; set; } 8 | public InsertCommand? Insert { get; set; } 9 | public UpdateCommand? Update { get; set; } 10 | public DeleteCommand? Delete { get; set; } 11 | } -------------------------------------------------------------------------------- /src/orm/NCDC.EntityFrameworkCore/QueryableExtension.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using NCDC.EntityFrameworkCore.Entities.Base; 3 | 4 | namespace NCDC.EntityFrameworkCore; 5 | public static class QueryableExtension 6 | { 7 | public static Task LogicDeleteAsync(this IQueryable queryable) where T:ILogicDelete 8 | { 9 | return queryable.ExecuteUpdateAsync(o => o.SetProperty(p => p.IsDelete, p => true)); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingParser/Segment/Select/Projection/IProjection.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ShardingParser.Segment.Select.Projection 2 | { 3 | /* 4 | * @Author: xjm 5 | * @Description: 6 | * @Date: Sunday, 11 April 2021 14:55:59 7 | * @Email: 326308290@qq.com 8 | */ 9 | public interface IProjection 10 | { 11 | 12 | string GetExpression(); 13 | 14 | string? GetAlias(); 15 | 16 | string GetColumnLabel(); 17 | } 18 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingRewrite/SqlRewriteResult.cs: -------------------------------------------------------------------------------- 1 | using NCDC.ShardingAdoNet; 2 | 3 | namespace NCDC.ShardingRewrite; 4 | 5 | 6 | public sealed class SqlRewriteResult 7 | { 8 | public SqlRewriteResult(string sql, ParameterContext parameterContext) 9 | { 10 | Sql = sql; 11 | ParameterContext = parameterContext; 12 | } 13 | 14 | public string Sql { get; } 15 | 16 | public ParameterContext ParameterContext { get; } 17 | } -------------------------------------------------------------------------------- /src/bootstrapper/NCDC.WebBootstrapper/Controllers/ActualDatabase/All/ActualDatabaseAllRequest.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace NCDC.WebBootstrapper.Controllers.ActualDatabase.All; 4 | 5 | public class ActualDatabaseAllRequest 6 | { 7 | /// 8 | /// 所属逻辑数据库名称 9 | /// 10 | [Display(Name = "逻辑数据库"),Required(ErrorMessage = "{0}不能为空")] 11 | public string LogicDatabaseId { get; set; } = null!; 12 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Dialect/Command/MySql/DDL/MySqlDropDatabaseCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command; 2 | using NCDC.CommandParser.Common.Command.DDL; 3 | 4 | namespace NCDC.CommandParser.Dialect.Command.MySql.DDL; 5 | 6 | public sealed class MySqlDropDatabaseCommand:DropDatabaseCommand,IMySqlCommand 7 | { 8 | public MySqlDropDatabaseCommand(string databaseName, bool ifExists) : base(databaseName, ifExists) 9 | { 10 | } 11 | } -------------------------------------------------------------------------------- /src/orm/NCDC.EntityFrameworkCore/Entities/DatabaseUserEntity.cs: -------------------------------------------------------------------------------- 1 | using NCDC.EntityFrameworkCore.Entities.Base; 2 | 3 | namespace NCDC.EntityFrameworkCore.Entities; 4 | 5 | public class DatabaseUserEntity:BaseEntity 6 | { 7 | /// 8 | /// 所属数据库 9 | /// 10 | public string DatabaseId { get; set; } = null!; 11 | /// 12 | /// 授权用户账号 13 | /// 14 | public string AppAuthUserId { get; set; } = null!; 15 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingRewrite/Abstractions/IParameterRewriterBuilder.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Abstractions; 2 | using NCDC.CommandParser.Common.Command; 3 | using NCDC.ShardingParser.Command; 4 | using NCDC.ShardingRoute; 5 | 6 | namespace NCDC.ShardingRewrite.Abstractions; 7 | 8 | public interface IParameterRewriterBuilder 9 | { 10 | ICollection>> GetParameterRewriters(RouteContext routeContext); 11 | } -------------------------------------------------------------------------------- /src/bootstrapper/NCDC.WebBootstrapper/Controllers/Passport/Login/LoginRequest.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace NCDC.WebBootstrapper.Controllers.Passport.Login; 4 | 5 | public class LoginRequest 6 | { 7 | [Display(Name = "账号"),Required(ErrorMessage = "{0}不能为空")] 8 | public string Account { get; set; } =null!; 9 | [Display(Name = "密码"),Required(ErrorMessage = "{0}不能为空")] 10 | public string Password { get; set; } =null!; 11 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/DDL/IAlterDefinitionSegment.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace NCDC.CommandParser.Common.Segment.DDL 6 | { 7 | /* 8 | * @Author: xjm 9 | * @Description: 10 | * @Date: 2021/4/20 16:42:38 11 | * @Ver: 1.0 12 | * @Email: 326308290@qq.com 13 | */ 14 | public interface IAlterDefinitionSegment:ISqlSegment 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Value/Literal/ILiteralValue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace NCDC.CommandParser.Common.Value.Literal 6 | { 7 | /* 8 | * @Author: xjm 9 | * @Description: 10 | * @Date: 2021/4/20 15:22:34 11 | * @Ver: 1.0 12 | * @Email: 326308290@qq.com 13 | */ 14 | public interface ILiteralValue:IValueASTNode 15 | { 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/SqlCommandTypeEnum.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace NCDC.CommandParser.Common.Command 6 | { 7 | /* 8 | * @Author: xjm 9 | * @Description: 10 | * @Date: 2021/4/20 11:04:09 11 | * @Ver: 1.0 12 | * @Email: 326308290@qq.com 13 | */ 14 | public enum SqlCommandTypeEnum 15 | { 16 | DML, DDL, TCL, DCL, DAL, RL 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/DDL/ICreateDefinitionSegment.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace NCDC.CommandParser.Common.Segment.DDL 6 | { 7 | /* 8 | * @Author: xjm 9 | * @Description: 10 | * @Date: 2021/4/20 16:46:35 11 | * @Ver: 1.0 12 | * @Email: 326308290@qq.com 13 | */ 14 | public interface ICreateDefinitionSegment:ISqlSegment 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/bootstrapper/NCDC.WebBootstrapper/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "DatabaseType": "MySql", 9 | "StorageType": "MySql", 10 | "ConnectionString": "server=127.0.0.1;port=3306;database=ncdcdb;userid=root;password=root;", 11 | "Port": 3307, 12 | "RoutePluginPath": "rule/test", 13 | "LogEncode":false, 14 | "LogDecode":false 15 | } 16 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Dialect/Command/MySql/DDL/MySqlCreateDatabaseCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command; 2 | using NCDC.CommandParser.Common.Command.DDL; 3 | 4 | namespace NCDC.CommandParser.Dialect.Command.MySql.DDL; 5 | 6 | public sealed class MySqlCreateDatabaseCommand:CreateDatabaseCommand,IMySqlCommand 7 | { 8 | public MySqlCreateDatabaseCommand(string databaseName, bool ifNotExists) : base(databaseName, ifNotExists) 9 | { 10 | } 11 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Binaries/BinaryRow.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ProxyServer.Binaries; 2 | /// 3 | /// 二进制行 4 | /// 5 | public sealed class BinaryRow 6 | { 7 | /// 8 | /// 单元格 9 | /// 10 | public List Cells { get; } 11 | public BinaryRow(List cells) 12 | { 13 | Cells = cells; 14 | } 15 | 16 | public static BinaryRow Empty { get; } = new BinaryRow(new List(0)); 17 | 18 | } -------------------------------------------------------------------------------- /src/bootstrapper/NCDC.WebBootstrapper/Controllers/PageRequest.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace NCDC.WebBootstrapper.Controllers; 4 | 5 | public class PageRequest 6 | { 7 | 8 | [Display(Name = "当前页")] 9 | [Range(1, int.MaxValue, ErrorMessage = "{0}必须为非零的正整数")] 10 | public int Page { get; set; } 11 | 12 | [Display(Name = "每页行数")] 13 | [Range(1, 500, ErrorMessage = "{0}的范围为{1}和{2}之间")] 14 | public int PageSize { get; set; } 15 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Dialect/Command/MySql/DDL/MySqlAlterTableCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command; 2 | using NCDC.CommandParser.Common.Command.DDL; 3 | using NCDC.CommandParser.Common.Segment.Generic.Table; 4 | 5 | namespace NCDC.CommandParser.Dialect.Command.MySql.DDL; 6 | 7 | public sealed class MySqlAlterTableCommand:AlterTableCommand,IMySqlCommand 8 | { 9 | public MySqlAlterTableCommand(SimpleTableSegment table) : base(table) 10 | { 11 | } 12 | } -------------------------------------------------------------------------------- /src/protocol/NCDC.Protocol/Helper/BytesHelper.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.Protocol.Helper; 2 | 3 | public class BytesHelper 4 | { 5 | private BytesHelper() 6 | { 7 | } 8 | 9 | public static byte[] CombineBytes(byte[] b1, byte[] b2) 10 | { 11 | int size = b1.Length + b2.Length; 12 | byte[] total = new byte[size]; 13 | Array.Copy(b1, 0, total, 0, b1.Length); 14 | Array.Copy(b2, 0, total, b1.Length, b2.Length); 15 | return total; 16 | } 17 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyClient/ConnectionIdGenerator.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ProxyClient; 2 | 3 | public class ConnectionIdGenerator 4 | { 5 | public static ConnectionIdGenerator Instance{get;}= new ConnectionIdGenerator(); 6 | 7 | private ConnectionIdGenerator() 8 | { 9 | 10 | } 11 | 12 | private int _currentId; 13 | 14 | public int NextId() 15 | { 16 | var increment = Interlocked.Increment(ref _currentId); 17 | return increment; 18 | } 19 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingParser/NCDCShardingParserExtension.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using NCDC.ShardingParser.Abstractions; 3 | 4 | namespace NCDC.ShardingParser; 5 | 6 | public static class NCDCShardingParserExtension 7 | { 8 | public static IServiceCollection AddShardingParser(this IServiceCollection services) 9 | { 10 | services.AddSingleton(); 11 | return services; 12 | } 13 | } -------------------------------------------------------------------------------- /src/bootstrapper/NCDC.WebBootstrapper/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*", 9 | "DatabaseType": "MySql", 10 | "StorageType": "MySql", 11 | "ConnectionString": "server=127.0.0.1;port=3306;database=ncdcdb;userid=root;password=root;", 12 | "Port": 3307, 13 | "RoutePluginPath": "rule/test", 14 | "LogEncode":false, 15 | "LogDecode":false 16 | } 17 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/Generic/CommentSegment.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Segment.Generic; 2 | 3 | public sealed class CommentSegment:ISqlSegment 4 | { 5 | public CommentSegment(int startIndex, int stopIndex,string text) 6 | { 7 | StartIndex = startIndex; 8 | StopIndex = stopIndex; 9 | Text = text; 10 | } 11 | 12 | public int StartIndex { get; } 13 | public int StopIndex { get; } 14 | public string Text { get; } 15 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Abstractions/IServerHandler.cs: -------------------------------------------------------------------------------- 1 | using NCDC.ProxyServer.Binaries; 2 | 3 | namespace NCDC.ProxyServer.Abstractions; 4 | 5 | public interface IServerHandler:IDisposable 6 | { 7 | Task ExecuteAsync(); 8 | 9 | bool Read() 10 | { 11 | return false; 12 | } 13 | 14 | BinaryRow GetRowData() 15 | { 16 | return BinaryRow.Empty; 17 | } 18 | 19 | void IDisposable.Dispose() 20 | { 21 | 22 | } 23 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingRoute/RouteMapper.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ShardingRoute; 2 | 3 | 4 | public sealed class RouteMapper 5 | { 6 | public RouteMapper(string logicName, string actualName) 7 | { 8 | LogicName = logicName; 9 | ActualName = actualName; 10 | } 11 | /// 12 | /// 逻辑名称 13 | /// 14 | public string LogicName { get; } 15 | /// 16 | /// 真实名称 17 | /// 18 | public string ActualName { get; } 19 | } -------------------------------------------------------------------------------- /src/antlr4/NCDC.MySqlParser/Visitor/Impl/MySqlRLVisitor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using NCDC.CommandParser.Abstractions.Visitor.Commands; 5 | 6 | namespace NCDC.MySqlParser.Visitor.Impl 7 | { 8 | /// 9 | /// 10 | /// 11 | /// Author: xjm 12 | /// Created: 2022/5/10 9:07:18 13 | /// Email: 326308290@qq.com 14 | public sealed class MySqlRLVisitor : MySqlVisitor,IRLVisitor 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyClient/Command/Abstractions/IMessageCommandProcessor.cs: -------------------------------------------------------------------------------- 1 | using DotNetty.Transport.Channels; 2 | using NCDC.ProxyServer.Abstractions; 3 | 4 | namespace NCDC.ProxyClient.Command.Abstractions; 5 | 6 | public interface IMessageCommandProcessor 7 | { 8 | IMessageExecutor GetMessageExecutor(IChannelId channelId); 9 | bool TryReceived(IChannelId channelId,ICommand command); 10 | IMessageExecutor Register(IChannelId channelId); 11 | void UnRegister(IChannelId channelId); 12 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Executors/SqlExecutorGroup.cs: -------------------------------------------------------------------------------- 1 | using NCDC.Enums; 2 | 3 | namespace NCDC.ProxyServer.Executors 4 | { 5 | public sealed class SqlExecutorGroup 6 | { 7 | public ConnectionModeEnum ConnectionMode { get; } 8 | public List Groups { get; } 9 | 10 | public SqlExecutorGroup(ConnectionModeEnum connectionMode,List groups) 11 | { 12 | ConnectionMode = connectionMode; 13 | Groups = groups; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingParser/Segment/Insert/Values/Expression/IDerivedSimpleExpressionSegment.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Segment.DML.Expr.Simple; 2 | 3 | namespace NCDC.ShardingParser.Segment.Insert.Values.Expression 4 | { 5 | /* 6 | * @Author: xjm 7 | * @Description: 8 | * @Date: 2021/4/13 8:56:19 9 | * @Ver: 1.0 10 | * @Email: 326308290@qq.com 11 | */ 12 | public interface IDerivedSimpleExpressionSegment: ISimpleExpressionSegment 13 | { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingRewrite/Sql/Token/Generator/Builder/ISqlTokenGeneratorBuilder.cs: -------------------------------------------------------------------------------- 1 | 2 | using NCDC.ShardingRoute; 3 | 4 | namespace NCDC.ShardingRewrite.Sql.Token.Generator.Builder 5 | { 6 | /* 7 | * @Author: xjm 8 | * @Description: 9 | * @Date: Monday, 12 April 2021 21:50:14 10 | * @Email: 326308290@qq.com 11 | */ 12 | public interface ISqlTokenGeneratorBuilder 13 | { 14 | 15 | ICollection GetSqlTokenGenerators(RouteContext routeContext); 16 | } 17 | } -------------------------------------------------------------------------------- /src/antlr4/NCDC.MySqlParser/Visitor/Impl/MySqlDCLVisitor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using NCDC.CommandParser.Abstractions.Visitor.Commands; 5 | 6 | namespace NCDC.MySqlParser.Visitor.Impl 7 | { 8 | /// 9 | /// 10 | /// 11 | /// Author: xjm 12 | /// Created: 2022/5/10 9:06:02 13 | /// Email: 326308290@qq.com 14 | public sealed class MySqlDCLVisitor : MySqlVisitor, IDCLVisitor 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/bootstrapper/NCDC.WebBootstrapper/Controllers/AuthUser/All/AuthUserAllResponse.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace NCDC.WebBootstrapper.Controllers.AuthUser.All; 4 | 5 | public class AuthUserAllResponse 6 | { 7 | public string Id { get; set; } 8 | [JsonProperty("userName")] 9 | public string UserNameDisplay => UserName +"--"+ (IsEnable ? "启用" : "禁用"); 10 | [JsonIgnore] 11 | public string UserName { get; set; } 12 | [JsonIgnore] 13 | public bool IsEnable { get; set; } 14 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/DML/Pagination/IPaginationValueSegment.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Segment.DML.Pagination 2 | { 3 | /* 4 | * @Author: xjm 5 | * @Description: 6 | * @Date: Sunday, 11 April 2021 14:34:41 7 | * @Email: 326308290@qq.com 8 | */ 9 | public interface IPaginationValueSegment : ISqlSegment 10 | { 11 | /** 12 | * Is bound opened. 13 | * 14 | * @return bound opened 15 | */ 16 | bool IsBoundOpened(); 17 | } 18 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Dialect/Command/MySql/DDL/MySqlDropIndexCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command.DDL; 2 | using NCDC.CommandParser.Common.Segment.Generic.Table; 3 | 4 | namespace NCDC.CommandParser.Dialect.Command.MySql.DDL; 5 | 6 | public sealed class MySqlDropIndexCommand:DropIndexCommand,IMySqlCommand 7 | { 8 | public MySqlDropIndexCommand(SimpleTableSegment table) 9 | { 10 | Table = table; 11 | } 12 | 13 | public SimpleTableSegment Table { get; } 14 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyClient/DotNetty/ChannelAttrInitializer.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | using DotNetty.Transport.Channels; 3 | using NCDC.ProxyServer; 4 | using NCDC.ProxyServer.Extensions; 5 | 6 | namespace NCDC.ProxyClient.DotNetty; 7 | 8 | public sealed class ChannelAttrInitializer:ChannelHandlerAdapter 9 | { 10 | public override void ChannelActive(IChannelHandlerContext context) 11 | { 12 | context.Channel.SetEncoding(Encoding.UTF8); 13 | context.FireChannelActive(); 14 | } 15 | } -------------------------------------------------------------------------------- /test/NCDC.ShardingTest/Seed/Entities/SysUserModInt.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ShardingTest.Seed.Entities; 2 | 3 | public class SysUserModInt 4 | { 5 | /// 6 | /// 用户Id用于分表 7 | /// 8 | public int Id { get; set; } 9 | 10 | /// 11 | /// 用户名称 12 | /// 13 | public string Name { get; set; } 14 | 15 | /// 16 | /// 用户姓名 17 | /// 18 | public int Age { get; set; } 19 | 20 | public int AgeGroup { get; set; } 21 | } -------------------------------------------------------------------------------- /src/bootstrapper/NCDC.WebBootstrapper/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "profiles": { 4 | "NCDC.WebBootstrapper": { 5 | "commandName": "Project", 6 | "dotnetRunMessages": true, 7 | "launchBrowser": true, 8 | "launchUrl": "swagger", 9 | "applicationUrl": "http://localhost:5043", 10 | "environmentVariables": { 11 | "ASPNETCORE_ENVIRONMENT": "Development" 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/core/NCDC.Plugin/TableRouteUnit.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.Plugin; 2 | 3 | public sealed class TableRouteUnit 4 | { 5 | public string DataSourceName { get; } 6 | public string LogicTableName { get; } 7 | public string ActualTableName { get; } 8 | 9 | public TableRouteUnit(string dataSourceName,string logicTableName,string actualTableName) 10 | { 11 | DataSourceName = dataSourceName; 12 | LogicTableName = logicTableName; 13 | ActualTableName = actualTableName; 14 | } 15 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/ISqlCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Abstractions; 2 | 3 | namespace NCDC.CommandParser.Common.Command 4 | { 5 | /* 6 | * @Author: xjm 7 | * @Description: 8 | * @Date: Tuesday, 23 March 2021 21:23:58 9 | * @Email: 326308290@qq.com 10 | */ 11 | public interface ISqlCommand:IASTNode 12 | { 13 | /// 14 | /// 获取参数个数 15 | /// 16 | /// 17 | int ParameterCount { get; } 18 | } 19 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/ServerHandlers/ServerTransactions/ITransactionManager.cs: -------------------------------------------------------------------------------- 1 | using System.Data; 2 | 3 | namespace NCDC.ProxyServer.ServerHandlers.ServerTransactions; 4 | 5 | public interface ITransactionManager 6 | { 7 | Task BeginAsync(IsolationLevel isolationLevel); 8 | Task CommitAsync(); 9 | Task RollbackAsync(); 10 | Task CreateSavepoint(string name); 11 | Task RollbackToSavepoint(string name); 12 | Task ReleaseSavepoint(string name); 13 | bool SupportSavepoint { get; } 14 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/ServerHandlers/SkipServerHandler.cs: -------------------------------------------------------------------------------- 1 | using NCDC.ProxyServer.Abstractions; 2 | using NCDC.ProxyServer.ServerHandlers.Results; 3 | 4 | namespace NCDC.ProxyServer.ServerHandlers; 5 | 6 | public sealed class SkipServerHandler:IServerHandler 7 | { 8 | public static SkipServerHandler Default { get; } = new SkipServerHandler(); 9 | public Task ExecuteAsync() 10 | { 11 | return Task.FromResult((IServerResult)RecordsAffectedServerResult.Default); 12 | } 13 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingRewrite/Sql/Token/SimpleObject/ISubstitutable.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ShardingRewrite.Sql.Token.SimpleObject 2 | { 3 | /* 4 | * @Author: xjm 5 | * @Description: 6 | * @Date: Tuesday, 13 April 2021 21:00:11 7 | * @Email: 326308290@qq.com 8 | */ 9 | public interface ISubstitutable 10 | { 11 | 12 | int GetStartIndex(); 13 | 14 | /** 15 | * Get stop index. 16 | * 17 | * @return stop index 18 | */ 19 | int GetStopIndex(); 20 | } 21 | } -------------------------------------------------------------------------------- /src/bootstrapper/NCDC.WebBootstrapper/AppResult.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.WebBootstrapper; 2 | 3 | public class AppResult 4 | { 5 | /// 错误消息 6 | public string? Msg { get; } 7 | 8 | /// 返回结果 9 | public T? Data { get; } 10 | 11 | /// 返回状态码 12 | public int Code { get; } 13 | 14 | public AppResult(int code, T? data, string? msg) 15 | { 16 | this.Msg = msg; 17 | this.Code = code; 18 | this.Data = data; 19 | } 20 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Dialect/Command/MySql/DML/MySqlDoCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command.DML; 2 | using NCDC.CommandParser.Common.Segment.DML.Expr; 3 | 4 | namespace NCDC.CommandParser.Dialect.Command.MySql.DML; 5 | 6 | public sealed class MySqlDoCommand:DoCommand,IMySqlCommand 7 | { 8 | public MySqlDoCommand(ICollection parameters) 9 | { 10 | Parameters = parameters; 11 | } 12 | 13 | public ICollection Parameters { get; } 14 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Connection/Abstractions/IServerDbConnection.cs: -------------------------------------------------------------------------------- 1 | using System.Data; 2 | using System.Data.Common; 3 | 4 | namespace NCDC.ProxyServer.Connection.Abstractions; 5 | 6 | public interface IServerDbConnection:IDisposable 7 | { 8 | Task BeginAsync(IsolationLevel isolationLevel); 9 | Task CommitAsync(); 10 | Task RollbackAsync(); 11 | DbConnection GetDbConnection(); 12 | DbCommand CreateCommand(string sql,ICollection? dbParameters); 13 | bool IsBeginTransaction(); 14 | } -------------------------------------------------------------------------------- /src/bootstrapper/NCDC.WebBootstrapper/Controllers/LogicTable/Page/LogicTablePageRequest.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace NCDC.WebBootstrapper.Controllers.LogicTable.Page; 4 | 5 | public class LogicTablePageRequest:PageRequest 6 | { 7 | /// 8 | /// 所属逻辑数据库名称 9 | /// 10 | [Display(Name = "逻辑数据库"),Required(ErrorMessage = "请先选择{0}")] 11 | public string LogicDatabaseId { get; set; } = null!; 12 | 13 | public string? TableName { get; set; } 14 | } 15 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/DML/Predicate/Value/IPredicateRightValue.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Abstractions; 2 | 3 | 4 | namespace NCDC.CommandParser.Common.Segment.DML.Predicate.Value 5 | { 6 | /* 7 | * @Author: xjm 8 | * @Description: 9 | * @Date: 2021/4/10 15:18:52 10 | * @Ver: 1.0 11 | * @Email: 326308290@qq.com 12 | */ 13 | /// 14 | /// 条件在右侧 15 | /// 16 | public interface IPredicateRightValue:IASTNode 17 | { 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/DAL/VariableSegment.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Segment.DAL 2 | { 3 | /* 4 | * @Author: xjm 5 | * @Description: 6 | * @Date: Monday, 12 April 2021 22:25:58 7 | * @Email: 326308290@qq.com 8 | */ 9 | public sealed class VariableSegment:ISqlSegment 10 | { 11 | public int StartIndex { get; set; } 12 | public int StopIndex { get; set; } 13 | public string? Scope { get; set; } 14 | public string? Variable { get; set; } 15 | 16 | } 17 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Dialect/Command/MySql/DML/MySqlInsertCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command.DML; 2 | using NCDC.CommandParser.Common.Segment.DML.Assignment; 3 | using NCDC.CommandParser.Common.Segment.DML.Column; 4 | 5 | namespace NCDC.CommandParser.Dialect.Command.MySql.DML; 6 | 7 | public sealed class MySqlInsertCommand:InsertCommand,IMySqlCommand 8 | { 9 | public SetAssignmentSegment? SetAssignment { get; set; } 10 | public OnDuplicateKeyColumnsSegment? OnDuplicateKeyColumns { get; set; } 11 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyClientMySql/ClientConnections/Commands/MySqlQuitClientCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.Protocol.MySql.Payload; 2 | using NCDC.ProxyClient.Abstractions; 3 | using NCDC.ProxyClientMySql.ClientConnections.DataReaders.Quit; 4 | 5 | namespace NCDC.ProxyClientMySql.ClientConnections.Commands; 6 | 7 | public sealed class MySqlQuitClientCommand:IClientCommand 8 | { 9 | public IClientDataReader ExecuteReader() 10 | { 11 | return new MySqlQuitClientDataReader(); 12 | } 13 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingParser/Command/ITableAvailable.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Segment.Generic.Table; 2 | using NCDC.ShardingParser.Segment.Table; 3 | 4 | namespace NCDC.ShardingParser.Command 5 | { 6 | /* 7 | * @Author: xjm 8 | * @Description: 9 | * @Date: Sunday, 11 April 2021 14:52:35 10 | * @Email: 326308290@qq.com 11 | */ 12 | public interface ITableAvailable 13 | { 14 | 15 | ICollection GetAllTables(); 16 | 17 | TablesContext GetTablesContext(); 18 | } 19 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingRoute/NCDC.ShardingRoute.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/core/NCDC/Base/SemaphoreReleaseOnlyOnce.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.Base; 2 | 3 | public sealed class SemaphoreReleaseOnlyOnce 4 | { 5 | private readonly DoOnlyOnce _doOnlyOnce = new DoOnlyOnce(); 6 | private readonly SemaphoreSlim _semaphore; 7 | 8 | public SemaphoreReleaseOnlyOnce(SemaphoreSlim semaphore) 9 | { 10 | _semaphore = semaphore; 11 | } 12 | 13 | public void Release() 14 | { 15 | if (_doOnlyOnce.IsUnDo()) 16 | { 17 | _semaphore.Release(); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/Generic/DataTypeLengthSegment.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Segment.Generic 2 | { 3 | /* 4 | * @Author: xjm 5 | * @Description: 6 | * @Date: Monday, 12 April 2021 22:05:13 7 | * @Email: 326308290@qq.com 8 | */ 9 | public sealed class DataTypeLengthSegment:ISqlSegment 10 | { 11 | public int StartIndex { get; set; } 12 | public int StopIndex { get; set; } 13 | public int Precision { get; set; } 14 | public int? Scale { get; set; } 15 | } 16 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/AppServices/Abstractions/IAppConfiguration.cs: -------------------------------------------------------------------------------- 1 | using NCDC.Enums; 2 | using NCDC.ProxyServer.Commons; 3 | 4 | namespace NCDC.ProxyServer.AppServices.Abstractions; 5 | 6 | public interface IAppConfiguration 7 | { 8 | DatabaseTypeEnum DatabaseType { get; set; } 9 | DbStorageTypeEnum StorageType { get; set; } 10 | string ConnectionsString { get; set; } 11 | int Port { get; set; } 12 | string RulePluginPath{ get; set; } 13 | bool LogEncode { get; set; } 14 | bool LogDecode { get; set; } 15 | } -------------------------------------------------------------------------------- /src/bootstrapper/NCDC.WebBootstrapper/Controllers/ActualDatabase/Page/ActualDatabasePageRequest.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace NCDC.WebBootstrapper.Controllers.ActualDatabase.Page; 4 | 5 | public class ActualDatabasePageRequest:PageRequest 6 | { 7 | /// 8 | /// 所属逻辑数据库名称 9 | /// 10 | [Display(Name = "逻辑数据库"),Required(ErrorMessage = "请先选择{0}")] 11 | public string LogicDatabaseId { get; set; } = null!; 12 | 13 | public string? DataSourceName { get; set; } 14 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyClient/Abstractions/IClientCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.Protocol.Packets; 2 | 3 | namespace NCDC.ProxyClient.Abstractions; 4 | 5 | public interface IClientCommand:IDisposable 6 | { 7 | IClientDataReader ExecuteReader(); 8 | void IDisposable.Dispose(){} 9 | } 10 | 11 | public interface IClientCommand:IClientCommand where T : IPacketPayload 12 | { 13 | IClientDataReader ExecuteReader(); 14 | 15 | IClientDataReader IClientCommand.ExecuteReader() 16 | { 17 | return ExecuteReader(); 18 | } 19 | } -------------------------------------------------------------------------------- /src/core/NCDC/DataSource/IDataSource.cs: -------------------------------------------------------------------------------- 1 | using System.Data.Common; 2 | 3 | namespace NCDC.DataSource 4 | { 5 | /* 6 | * @Author: xjm 7 | * @Description: 8 | * @Date: 2021/4/19 13:51:22 9 | * @Ver: 1.0 10 | * @Email: 326308290@qq.com 11 | */ 12 | public interface IDataSource 13 | { 14 | string DataSourceName { get; } 15 | bool IsDefault(); 16 | string GetConnectionString(); 17 | DbProviderFactory GetDbProviderFactory(); 18 | DbConnection CreateConnection(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/ServerHandlers/Results/QueryServerResult.cs: -------------------------------------------------------------------------------- 1 | using System.Data.Common; 2 | using NCDC.ProxyServer.Abstractions; 3 | using NCDC.ProxyServer.Commons; 4 | 5 | namespace NCDC.ProxyServer.ServerHandlers.Results; 6 | 7 | public sealed class QueryServerResult:IServerResult 8 | { 9 | 10 | public ResultTypeEnum ResultType => ResultTypeEnum.QUERY; 11 | public List DbColumns { get; } 12 | 13 | public QueryServerResult(List dbColumns) 14 | { 15 | DbColumns = dbColumns; 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/StreamMerges/Results/AffectedRowsExecuteResult.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ProxyServer.StreamMerges.Results; 2 | 3 | public sealed class AffectedRowsExecuteResult:IExecuteResult 4 | { 5 | 6 | public int RecordsAffected { get; } 7 | public long LastInsertId { get; } 8 | 9 | public AffectedRowsExecuteResult(int recordsAffected,long lastInsertId) 10 | { 11 | RecordsAffected = recordsAffected; 12 | LastInsertId = lastInsertId; 13 | } 14 | 15 | public void Dispose() 16 | { 17 | } 18 | } -------------------------------------------------------------------------------- /src/bootstrapper/NCDC.WebBootstrapper/Controllers/AuthUser/UserDatabases/UserDatabasesResponse.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.WebBootstrapper.Controllers.AuthUser.UserDatabases; 2 | 3 | public class UserDatabasesResponse 4 | { 5 | public List CheckedDatabases{ get; set; } = new List(); 6 | public List AllDatabases { get; set; } = new List(); 7 | } 8 | 9 | public class UserDatabaseAllResponse 10 | { 11 | public string Id { get; set; } 12 | public string DatabaseName { get; set; } 13 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/NCDCCommandParserExtension.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using NCDC.CommandParser.Abstractions; 3 | using NCDC.CommandParser.Core; 4 | using NCDC.CommandParser.SqlParseEngines; 5 | 6 | namespace NCDC.CommandParser; 7 | 8 | public static class NCDCCommandParserExtension 9 | { 10 | public static IServiceCollection AddCommandParser(this IServiceCollection services) 11 | { 12 | services.AddSingleton(); 13 | return services; 14 | } 15 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingParser/Segment/Select/SubQuery/SubQueryTableContext.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ShardingParser.Segment.Select.SubQuery; 2 | 3 | public sealed class SubQueryTableContext 4 | { 5 | public string TableName { get; } 6 | public string? Alias { get; } 7 | public ICollection ColumnNames { get; } 8 | 9 | public SubQueryTableContext(string tableName,string? alias,ICollection columnNames) 10 | { 11 | TableName = tableName; 12 | Alias = alias; 13 | ColumnNames = columnNames; 14 | } 15 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DDL/AlterIndexCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NCDC.CommandParser.Common.Segment.DDL.Index; 3 | using NCDC.CommandParser.Common.Segment.Generic.Table; 4 | 5 | namespace NCDC.CommandParser.Common.Command.DDL 6 | { 7 | /* 8 | * @Author: xjm 9 | * @Description: 10 | * @Date: Tuesday, 20 April 2021 21:37:55 11 | * @Email: 326308290@qq.com 12 | */ 13 | public abstract class AlterIndexCommand:AbstractSqlCommand,IDDLCommand 14 | { 15 | 16 | public IndexSegment? Index { get; set; } 17 | } 18 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DDL/RenameTableCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NCDC.CommandParser.Common.Segment.DDL.Table; 3 | 4 | namespace NCDC.CommandParser.Common.Command.DDL 5 | { 6 | /* 7 | * @Author: xjm 8 | * @Description: 9 | * @Date: Tuesday, 20 April 2021 21:57:34 10 | * @Email: 326308290@qq.com 11 | */ 12 | public abstract class RenameTableCommand:AbstractSqlCommand,IDDLCommand 13 | { 14 | public ICollection RenameTables = new LinkedList(); 15 | } 16 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DCL/GrantCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using NCDC.CommandParser.Common.Segment.Generic.Table; 4 | 5 | namespace NCDC.CommandParser.Common.Command.DCL 6 | { 7 | /* 8 | * @Author: xjm 9 | * @Description: 10 | * @Date: Tuesday, 20 April 2021 21:29:43 11 | * @Email: 326308290@qq.com 12 | */ 13 | public abstract class GrantCommand:AbstractSqlCommand,IDCLCommand 14 | { 15 | public ICollection Tables = new LinkedList(); 16 | } 17 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingRoute/DataSourceRoutes/Abstractions/IDataSourceRoute.cs: -------------------------------------------------------------------------------- 1 | using NCDC.Basic.Metadatas; 2 | using NCDC.Plugin; 3 | using NCDC.Plugin.DataSourceRouteRules; 4 | using NCDC.ShardingParser; 5 | using NCDC.ShardingRoute.Abstractions; 6 | 7 | namespace NCDC.ShardingRoute.DataSourceRoutes.Abstractions; 8 | 9 | public interface IDataSourceRoute:IRoute 10 | { 11 | string TableName { get; } 12 | TableMetadata GetTableMetadata(); 13 | IDataSourceRouteRule GetRouteRule(); 14 | ICollection Route(SqlParserResult sqlParserResult); 15 | } -------------------------------------------------------------------------------- /src/antlr4/NCDC.MySqlParser/NCDCMySqlParserExtension.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using NCDC.CommandParser; 3 | using NCDC.CommandParser.Abstractions; 4 | using NCDC.MySqlParser; 5 | 6 | namespace NCDC.MySqlParser; 7 | 8 | public static class NCDCMySqlParserExtension 9 | { 10 | public static IServiceCollection AddMySqlParser(this IServiceCollection services) 11 | { 12 | services.AddCommandParser(); 13 | services.AddSingleton(); 14 | return services; 15 | } 16 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DCL/RevokeCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using NCDC.CommandParser.Common.Segment.Generic.Table; 4 | 5 | namespace NCDC.CommandParser.Common.Command.DCL 6 | { 7 | /* 8 | * @Author: xjm 9 | * @Description: 10 | * @Date: Tuesday, 20 April 2021 21:30:45 11 | * @Email: 326308290@qq.com 12 | */ 13 | public abstract class RevokeCommand:AbstractSqlCommand,IDCLCommand 14 | { 15 | public ICollection Tables = new LinkedList(); 16 | } 17 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/TCL/SetAutoCommitCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NCDC.CommandParser.Common.Command.TCL 4 | { 5 | /* 6 | * @Author: xjm 7 | * @Description: 8 | * @Date: Tuesday, 20 April 2021 22:17:53 9 | * @Email: 326308290@qq.com 10 | */ 11 | public abstract class SetAutoCommitCommand: AbstractSqlCommand, ITCLCommand 12 | { 13 | protected SetAutoCommitCommand(bool autoCommit) 14 | { 15 | AutoCommit = autoCommit; 16 | } 17 | 18 | public bool AutoCommit { get;} 19 | } 20 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/DML/Pagination/IParameterMarkerPaginationValueSegment.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Segment.Generic; 2 | 3 | namespace NCDC.CommandParser.Common.Segment.DML.Pagination 4 | { 5 | /* 6 | * @Author: xjm 7 | * @Description: 8 | * @Date: Sunday, 11 April 2021 16:02:28 9 | * @Email: 326308290@qq.com 10 | */ 11 | public interface IParameterMarkerPaginationValueSegment:IPaginationValueSegment,IParameterMarkerSegment 12 | { 13 | int ParameterIndex { get; } 14 | string ParameterName{ get; } 15 | } 16 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Dialect/Command/MySql/DDL/MySqlCreateIndexCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command; 2 | using NCDC.CommandParser.Common.Command.DDL; 3 | using NCDC.CommandParser.Common.Segment.DDL.Index; 4 | using NCDC.CommandParser.Common.Segment.Generic.Table; 5 | 6 | namespace NCDC.CommandParser.Dialect.Command.MySql.DDL; 7 | 8 | public sealed class MySqlCreateIndexCommand:CreateIndexCommand,IMySqlCommand 9 | { 10 | public MySqlCreateIndexCommand(IndexSegment index, SimpleTableSegment table) : base(index, table) 11 | { 12 | } 13 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/NCDC.CommandParser.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DDL/TruncateCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using NCDC.CommandParser.Common.Segment.Generic.Table; 4 | 5 | namespace NCDC.CommandParser.Common.Command.DDL 6 | { 7 | /* 8 | * @Author: xjm 9 | * @Description: 10 | * @Date: Tuesday, 20 April 2021 21:57:53 11 | * @Email: 326308290@qq.com 12 | */ 13 | public abstract class TruncateCommand:AbstractSqlCommand,IDDLCommand 14 | { 15 | public ICollection Tables = new LinkedList(); 16 | 17 | } 18 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/TCL/SavepointCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NCDC.CommandParser.Common.Command.TCL 4 | { 5 | /* 6 | * @Author: xjm 7 | * @Description: 8 | * @Date: Tuesday, 20 April 2021 22:17:36 9 | * @Email: 326308290@qq.com 10 | */ 11 | public abstract class SavepointCommand: AbstractSqlCommand, ITCLCommand 12 | { 13 | protected SavepointCommand(string savepointName) 14 | { 15 | SavepointName = savepointName; 16 | } 17 | 18 | public string SavepointName { get; } 19 | } 20 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/DAL/FromTableSegment.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Segment.Generic.Table; 2 | 3 | namespace NCDC.CommandParser.Common.Segment.DAL 4 | { 5 | /* 6 | * @Author: xjm 7 | * @Description: 8 | * @Date: Monday, 12 April 2021 22:28:55 9 | * @Email: 326308290@qq.com 10 | */ 11 | public sealed class FromTableSegment:ISqlSegment 12 | { 13 | public int StartIndex { get; set;} 14 | 15 | public int StopIndex { get; set;} 16 | 17 | public SimpleTableSegment? Table { get; set;} 18 | 19 | } 20 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/TCL/AutoCommitSegment.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Segment.TCL 2 | { 3 | public sealed class AutoCommitSegment:ISqlSegment 4 | { 5 | public int StartIndex { get; } 6 | public int StopIndex { get; } 7 | public bool AutoCommit { get; } 8 | 9 | 10 | public AutoCommitSegment(int startIndex, int stopIndex, bool autoCommit) 11 | { 12 | StartIndex = startIndex; 13 | StopIndex = stopIndex; 14 | AutoCommit = autoCommit; 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/TCL/ImplicitTransactionsSegment.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Segment.TCL 2 | { 3 | public sealed class ImplicitTransactionsSegment:ISqlSegment 4 | { 5 | public int StartIndex { get; } 6 | public int StopIndex { get; } 7 | public bool On { get; } 8 | 9 | 10 | public ImplicitTransactionsSegment(int startIndex, int stopIndex, bool on) 11 | { 12 | StartIndex = startIndex; 13 | StopIndex = stopIndex; 14 | On = on; 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/StreamMerges/IShardingMerger.cs: -------------------------------------------------------------------------------- 1 | using NCDC.ProxyServer.Connection.Abstractions; 2 | using NCDC.ProxyServer.Executors; 3 | 4 | namespace NCDC.ProxyServer.StreamMerges; 5 | 6 | public interface IShardingMerger 7 | { 8 | TResult StreamMerge(IConnectionSession connectionSession,ShardingExecutionContext shardingExecutionContext,List parallelResults); 9 | void InMemoryMerge(IConnectionSession connectionSession,ShardingExecutionContext shardingExecutionContext,List beforeInMemoryResults,List parallelResults); 10 | } 11 | -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingRewrite/Sql/Token/Generator/ISqlTokenGenerator.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Abstractions; 2 | using NCDC.CommandParser.Common.Command; 3 | using NCDC.ShardingParser.Command; 4 | 5 | namespace NCDC.ShardingRewrite.Sql.Token.Generator 6 | { 7 | /* 8 | * @Author: xjm 9 | * @Description: 10 | * @Date: 2021/4/12 16:08:57 11 | * @Ver: 1.0 12 | * @Email: 326308290@qq.com 13 | */ 14 | public interface ISqlTokenGenerator 15 | { 16 | bool IsGenerateSqlToken(ISqlCommandContext sqlCommandContext); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DDL/DropTableCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using NCDC.CommandParser.Common.Segment.Generic.Table; 4 | 5 | namespace NCDC.CommandParser.Common.Command.DDL 6 | { 7 | /* 8 | * @Author: xjm 9 | * @Description: 10 | * @Date: Tuesday, 20 April 2021 21:52:17 11 | * @Email: 326308290@qq.com 12 | */ 13 | public abstract class DropTableCommand:AbstractSqlCommand,IDDLCommand 14 | { 15 | 16 | public ICollection Tables = new LinkedList(); 17 | } 18 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/DML/Predicate/HavingSegment.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Segment.DML.Expr; 2 | 3 | namespace NCDC.CommandParser.Common.Segment.DML.Predicate; 4 | 5 | public sealed class HavingSegment:ISqlSegment 6 | { 7 | public HavingSegment(int startIndex, int stopIndex, IExpressionSegment expr) 8 | { 9 | StartIndex = startIndex; 10 | StopIndex = stopIndex; 11 | Expr = expr; 12 | } 13 | 14 | public int StartIndex { get; } 15 | public int StopIndex { get; } 16 | public IExpressionSegment Expr { get; } 17 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Dialect/Command/MySql/DAL/MySqlUseCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command.DAL; 2 | 3 | namespace NCDC.CommandParser.Dialect.Command.MySql.DAL 4 | { 5 | /* 6 | * @Author: xjm 7 | * @Description: 8 | * @Date: Monday, 12 April 2021 22:18:51 9 | * @Email: 326308290@qq.com 10 | */ 11 | public sealed class MySqlUseCommand:UseCommand,IMySqlCommand 12 | { 13 | public string Schema { get; } 14 | 15 | public MySqlUseCommand(string schema) : base(schema) 16 | { 17 | Schema = schema; 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Dialect/Command/MySql/DDL/MySqlCreateTableCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command; 2 | using NCDC.CommandParser.Common.Command.DDL; 3 | using NCDC.CommandParser.Common.Segment.Generic.Table; 4 | 5 | namespace NCDC.CommandParser.Dialect.Command.MySql.DDL; 6 | 7 | public sealed class MySqlCreateTableCommand:CreateTableCommand,IMySqlCommand 8 | { 9 | public bool IfNotExists { get; } 10 | 11 | public MySqlCreateTableCommand(bool ifNotExists,SimpleTableSegment table):base(table) 12 | { 13 | IfNotExists = ifNotExists; 14 | } 15 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/DML/Predicate/OrPredicateSegment.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Segment.DML.Predicate 2 | { 3 | /* 4 | * @Author: xjm 5 | * @Description: 6 | * @Date: 2021/4/12 13:55:44 7 | * @Ver: 1.0 8 | * @Email: 326308290@qq.com 9 | */ 10 | public sealed class OrPredicateSegment:ISqlSegment 11 | { 12 | 13 | public int StartIndex => 0; 14 | public int StopIndex => 0; 15 | public ICollection AndPredicates = new LinkedList(); 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/protocol/NCDC.Protocol/MySql/Packet/Command/MySqlServerNotSupportCommandPacket.cs: -------------------------------------------------------------------------------- 1 | // using NCDC.Protocol.MySql.Payload; 2 | // using NCDC.ProtocolMysql.Packet.ServerCommand; 3 | // 4 | // namespace NCDC.Protocol.MySql.Packet.Command; 5 | // 6 | // public class MySqlServerNotSupportCommandPacket:AbstractMySqlServerCommandPacket 7 | // { 8 | // public MySqlServerNotSupportCommandPacket(MySqlCommandTypeEnum commandType) : base(commandType) 9 | // { 10 | // } 11 | // 12 | // protected override void DoWrite(MySqlPacketPayload payload) 13 | // { 14 | // 15 | // } 16 | // } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingRoute/Extensions/TableMetadataExtension.cs: -------------------------------------------------------------------------------- 1 | using NCDC.Basic.Metadatas; 2 | 3 | namespace NCDC.ShardingRoute.Extensions; 4 | 5 | public static class TableMetadataExtension 6 | { 7 | 8 | public static bool IsMainShardingTableColumn(this TableMetadata metadata, string columnName) 9 | { 10 | return metadata.ShardingTableColumn == columnName; 11 | } 12 | public static bool IsMainShardingDataSourceColumn(this TableMetadata metadata, string columnName) 13 | { 14 | return metadata.ShardingDataSourceColumn == columnName; 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyClient/DIExtension.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using NCDC.ProxyClient.Command; 3 | using NCDC.ProxyClient.Command.Abstractions; 4 | 5 | namespace Microsoft.Extensions.DependencyInjection; 6 | 7 | public static class DIExtension 8 | { 9 | public static IServiceCollection AddProxyClientCore(this IServiceCollection services) 10 | { 11 | services.AddSingleton(); 12 | services.AddSingleton(); 13 | return services; 14 | } 15 | } -------------------------------------------------------------------------------- /test/NCDC.ShardingTest/Seed/Maps/OrderMap.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Microsoft.EntityFrameworkCore.Metadata.Builders; 3 | using NCDC.ShardingTest.Seed.Entities; 4 | 5 | namespace NCDC.ShardingTest.Seed.Maps 6 | { 7 | public class OrderMap:IEntityTypeConfiguration 8 | { 9 | public void Configure(EntityTypeBuilder builder) 10 | { 11 | builder.HasKey(o => o.Id); 12 | builder.Property(o => o.Area).IsRequired().IsUnicode(false).HasMaxLength(20); 13 | builder.ToTable(nameof(Order)); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/Generic/GrantLevelSegment.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Segment.Generic; 2 | 3 | public sealed class GrantLevelSegment:ISqlSegment 4 | { 5 | public GrantLevelSegment(int startIndex, int stopIndex,string dbName,string tableName) 6 | { 7 | StartIndex = startIndex; 8 | StopIndex = stopIndex; 9 | DbName = dbName; 10 | TableName = tableName; 11 | } 12 | 13 | public int StartIndex { get; } 14 | public int StopIndex { get; } 15 | public string DbName { get; } 16 | public string TableName { get; } 17 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/Generic/NameSegment.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Value.Identifier; 2 | 3 | namespace NCDC.CommandParser.Common.Segment.Generic; 4 | 5 | public sealed class NameSegment:ISqlSegment 6 | { 7 | public NameSegment(int startIndex, int stopIndex,IdentifierValue identifierValue) 8 | { 9 | StartIndex = startIndex; 10 | StopIndex = stopIndex; 11 | IdentifierValue = identifierValue; 12 | } 13 | 14 | public int StartIndex { get; } 15 | public int StopIndex { get; } 16 | public IdentifierValue IdentifierValue { get; } 17 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Dialect/Command/MySql/DML/MySqlTableCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command.DML; 2 | using NCDC.CommandParser.Common.Segment.DML.Column; 3 | using NCDC.CommandParser.Common.Segment.DML.Pagination.limit; 4 | using NCDC.CommandParser.Common.Segment.Generic.Table; 5 | 6 | namespace NCDC.CommandParser.Dialect.Command.MySql.DML; 7 | 8 | public sealed class MySqlTableCommand:TableCommand,IMySqlCommand 9 | { 10 | 11 | public SimpleTableSegment? Table { get; set; } 12 | public ColumnSegment? Column { get; set; } 13 | public LimitSegment? Limit { get; set; } 14 | } -------------------------------------------------------------------------------- /src/orm/NCDC.EntityFrameworkCore/Maps/DatabaseUserMap.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Metadata.Builders; 2 | using NCDC.EntityFrameworkCore.Entities; 3 | 4 | namespace NCDC.EntityFrameworkCore.Maps; 5 | 6 | public class DatabaseUserMap:BaseMap 7 | { 8 | protected override string TableName => "database_user"; 9 | protected override void Configure0(EntityTypeBuilder builder) 10 | { 11 | builder.Property(o => o.DatabaseId).IsRequired().HasMaxLength(50); 12 | builder.Property(o => o.AppAuthUserId).IsRequired().HasMaxLength(50); 13 | } 14 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Connection/Abstractions/IQueryContext.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command; 2 | using NCDC.ShardingAdoNet; 3 | using NCDC.ShardingParser.Command; 4 | 5 | namespace NCDC.ProxyServer.Connection.Abstractions; 6 | 7 | public interface IQueryContext 8 | { 9 | ISqlCommandContext SqlCommandContext { get; } 10 | string Sql { get; } 11 | ParameterContext ParameterContext { get; } 12 | IConnectionSession ConnectionSession { get; } 13 | /// 14 | /// 是否是直接执行的sql 15 | /// 16 | bool DirectAllDataSourceSql { get; } 17 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Connection/CreateServerDbConnectionStrategyEnum.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ProxyServer.Connection; 2 | 3 | public enum CreateServerDbConnectionStrategyEnum 4 | { 5 | /// 6 | /// 共享链接(只是用写链接字符串) 无需管理connection的生命周期 7 | /// 简单说就是无需调用dispose 8 | /// 9 | SharedConnection, 10 | /// 11 | /// 并行查询链接(有可能会使用读写分离链接字符串) 独立生命周期需要手动dispose或者等系统调用 12 | /// 13 | IndependentConnectionQuery, 14 | /// 15 | /// 并行写链接(只是用写链接字符串) 独立生命周期需要手动dispose或者等系统调用 16 | /// 17 | IndependentConnectionWrite 18 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/DML/Predicate/AndPredicateSegment.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Segment.DML.Expr; 2 | 3 | namespace NCDC.CommandParser.Common.Segment.DML.Predicate 4 | { 5 | /* 6 | * @Author: xjm 7 | * @Description: 8 | * @Date: Sunday, 11 April 2021 14:11:55 9 | * @Email: 326308290@qq.com 10 | */ 11 | public sealed class AndPredicateSegment:ISqlSegment 12 | { 13 | public int StartIndex => 0; 14 | public int StopIndex => 0; 15 | 16 | public ICollection Predicates = new LinkedList(); 17 | 18 | } 19 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/SqlParseEngines/Hook/IParsingHook.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Abstractions; 2 | using NCDC.CommandParser.Common.Command; 3 | 4 | namespace NCDC.CommandParser.SqlParseEngines.Hook 5 | { 6 | /* 7 | * @Author: xjm 8 | * @Description: 9 | * @Date: 2021/4/20 10:03:17 10 | * @Ver: 1.0 11 | * @Email: 326308290@qq.com 12 | */ 13 | public interface IParsingHook 14 | { 15 | void Start(String sql); 16 | 17 | 18 | void FinishSuccess(ISqlCommand sqlCommand); 19 | 20 | 21 | void FinishFailure(Exception exception); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/bootstrapper/NCDC.WebBootstrapper/Controllers/User/UserController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using NCDC.WebBootstrapper.Controllers.User.Info; 3 | 4 | namespace NCDC.WebBootstrapper.Controllers.User; 5 | 6 | [ApiController] 7 | [Route("/api/user")] 8 | public class UserController:BaseApiController 9 | { 10 | 11 | [HttpGet,Route("info")] 12 | public AppResult Info() 13 | { 14 | return OutputOk(new UserInfoResponse() 15 | { 16 | UserId = "a12345", 17 | Username = "管理员", 18 | Account = "admin" 19 | }); 20 | } 21 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DDL/DropIndexCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using NCDC.CommandParser.Common.Segment.DDL.Index; 4 | using NCDC.CommandParser.Common.Segment.Generic.Table; 5 | 6 | namespace NCDC.CommandParser.Common.Command.DDL 7 | { 8 | /* 9 | * @Author: xjm 10 | * @Description: 11 | * @Date: Tuesday, 20 April 2021 21:51:08 12 | * @Email: 326308290@qq.com 13 | */ 14 | public abstract class DropIndexCommand:AbstractSqlCommand,IDDLCommand 15 | { 16 | public ICollection Indexes = new LinkedList(); 17 | } 18 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/Generic/InsertMultiTableElementSegment.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command.DML; 2 | 3 | namespace NCDC.CommandParser.Common.Segment.Generic; 4 | 5 | public sealed class InsertMultiTableElementSegment:ISqlSegment 6 | { 7 | public InsertMultiTableElementSegment(int startIndex, int stopIndex) 8 | { 9 | StartIndex = startIndex; 10 | StopIndex = stopIndex; 11 | } 12 | 13 | public int StartIndex { get; } 14 | public int StopIndex { get; } 15 | public ICollection InsertCommands = new LinkedList(); 16 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Value/KeyWord/KeywordValue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace NCDC.CommandParser.Common.Value.KeyWord 6 | { 7 | /* 8 | * @Author: xjm 9 | * @Description: 10 | * @Date: 2021/4/20 16:10:58 11 | * @Ver: 1.0 12 | * @Email: 326308290@qq.com 13 | */ 14 | public sealed class KeywordValue:IValueASTNode 15 | { 16 | 17 | public KeywordValue(string value) 18 | { 19 | Value = value; 20 | } 21 | public string Value { get; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # .Net Core Distributed Connector 2 | 3 | ## ShardingRuleConfiguration 4 | 整个项目的分片规则配置 5 | - TableRuleConfigs 用来存储各个表的分片规则 6 | - DefaultTableShardingStrategyConfig 默认的分表策略配置 7 | - DefaultDatabaseShardingStrategyConfig 默认分库策略配置 8 | - DefaultDataSourceName 默认数据源名称 9 | 10 | ## ShardingDataSourceFactory 11 | 用于创建IDataSource 12 | ## IDataSource 13 | 用于创建DbConnection 14 | 15 | ### GenericDataSource 16 | 通用的数据源实现 17 | ### ShardingDataSource 18 | 分片的数据源实现 19 | 20 | ## ShardingRuntimeContext 21 | 22 | ### 分片规则 23 | ### 配置信息 24 | ### 数据库类型 25 | ### 执行引擎 26 | ### sql解析引擎 27 | ### 获取分片元信息 28 | 29 | -------------------------------------------------------------------------------- /src/bootstrapper/NCDC.WebBootstrapper/Controllers/LogicTable/ActualTablePage/ActualTablePageRequest.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace NCDC.WebBootstrapper.Controllers.LogicTable.ActualTablePage; 4 | 5 | public class ActualTablePageRequest:PageRequest 6 | { 7 | 8 | /// 9 | /// 所属逻辑数据库名称 10 | /// 11 | [Display(Name = "逻辑数据库"),Required(ErrorMessage = "请先选择{0}")] 12 | public string LogicDatabaseId { get; set; } = null!; 13 | 14 | [Display(Name = "逻辑表"),Required(ErrorMessage = "请先选择{0}")] 15 | public string LogicTableId { get; set; } = null!; 16 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/Generic/Table/DeleteMultiTableSegment.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Segment.Generic.Table; 2 | 3 | public sealed class DeleteMultiTableSegment:ITableSegment 4 | { 5 | public int StartIndex { get; set; } 6 | public int StopIndex { get; set; } 7 | public ICollection ActualDeleteTables = new LinkedList(); 8 | public ITableSegment? RelationTable { get; set; } 9 | public string? GetAlias() 10 | { 11 | return null; 12 | } 13 | 14 | public void SetAlias(AliasSegment? alias) 15 | { 16 | } 17 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/Generic/WithSegment.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Segment.DML.Expr.Complex; 2 | 3 | namespace NCDC.CommandParser.Common.Segment.Generic; 4 | 5 | public sealed class WithSegment:ISqlSegment 6 | { 7 | public WithSegment(int startIndex, int stopIndex) 8 | { 9 | StartIndex = startIndex; 10 | StopIndex = stopIndex; 11 | } 12 | 13 | public int StartIndex { get; } 14 | public int StopIndex { get; } 15 | 16 | public ICollection CommonTableExpressions = 17 | new LinkedList(); 18 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingRoute/TableRoutes/TableRouteContext.cs: -------------------------------------------------------------------------------- 1 | using NCDC.Plugin; 2 | using NCDC.ShardingParser; 3 | using NCDC.ShardingRoute.DataSourceRoutes; 4 | 5 | namespace NCDC.ShardingRoute.TableRoutes; 6 | 7 | public sealed class TableRouteContext 8 | { 9 | public DataSourceRouteResult DataSourceRouteResult { get; } 10 | public SqlParserResult SqlParserResult { get; } 11 | 12 | public TableRouteContext(DataSourceRouteResult dataSourceRouteResult,SqlParserResult sqlParserResult) 13 | { 14 | DataSourceRouteResult = dataSourceRouteResult; 15 | SqlParserResult = sqlParserResult; 16 | } 17 | } -------------------------------------------------------------------------------- /src/bootstrapper/NCDC.WebBootstrapper/Exceptions/AppException.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace NCDC.WebBootstrapper.Exceptions; 4 | 5 | public class AppException:Exception 6 | { 7 | public int Code { get; } 8 | /// 9 | /// 当异常名称不确定,但是异常code确定时调用此方法 10 | /// 11 | /// 12 | /// 13 | public AppException(int code, string? message) : base(message) 14 | { 15 | Code = code; 16 | 17 | } 18 | public AppException(string? message) : base(message) 19 | { 20 | Code = 400; 21 | } 22 | } -------------------------------------------------------------------------------- /src/core/NCDC/Exceptions/ShardingConfigException.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace NCDC.Exceptions; 4 | 5 | public class ShardingConfigException:ShardingException 6 | { 7 | public ShardingConfigException() 8 | { 9 | } 10 | 11 | protected ShardingConfigException(SerializationInfo info, StreamingContext context) : base(info, context) 12 | { 13 | } 14 | 15 | public ShardingConfigException(string? message) : base(message) 16 | { 17 | } 18 | 19 | public ShardingConfigException(string? message, Exception? innerException) : base(message, innerException) 20 | { 21 | } 22 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingRoute/TableRoutes/Abstractions/ITableRoute.cs: -------------------------------------------------------------------------------- 1 | using NCDC.Basic.Metadatas; 2 | using NCDC.Plugin; 3 | using NCDC.Plugin.TableRouteRules; 4 | using NCDC.ShardingParser; 5 | using NCDC.ShardingRoute.Abstractions; 6 | using NCDC.ShardingRoute.DataSourceRoutes; 7 | 8 | namespace NCDC.ShardingRoute.TableRoutes.Abstractions; 9 | 10 | public interface ITableRoute:IRoute 11 | { 12 | string TableName { get; } 13 | TableMetadata GetTableMetadata(); 14 | ITableRouteRule GetRouteRule(); 15 | ICollection Route(DataSourceRouteResult dataSourceRouteResult,SqlParserResult sqlParserResult); 16 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/Generic/DataTypeSegment.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Segment.DML.Expr; 2 | 3 | namespace NCDC.CommandParser.Common.Segment.Generic 4 | { 5 | /* 6 | * @Author: xjm 7 | * @Description: 8 | * @Date: Monday, 12 April 2021 22:04:27 9 | * @Email: 326308290@qq.com 10 | */ 11 | public sealed class DataTypeSegment:IExpressionSegment 12 | { 13 | public int StartIndex { get; set; } 14 | public int StopIndex { get; set; } 15 | 16 | public string? DataTypeName { get; set; } 17 | 18 | public DataTypeLengthSegment? DataLength { get; set; } 19 | } 20 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Executors/DataSourceSqlExecutorUnit.cs: -------------------------------------------------------------------------------- 1 | using NCDC.Enums; 2 | 3 | namespace NCDC.ProxyServer.Executors 4 | { 5 | public sealed class DataSourceSqlExecutorUnit 6 | { 7 | public ConnectionModeEnum ConnectionMode { get; } 8 | public List> SqlExecutorGroups { get; } 9 | 10 | public DataSourceSqlExecutorUnit(ConnectionModeEnum connectionMode,List> sqlExecutorGroups) 11 | { 12 | ConnectionMode = connectionMode; 13 | SqlExecutorGroups = sqlExecutorGroups; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/TCL/SetTransactionCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NCDC.CommandParser.Common.Constant; 3 | 4 | namespace NCDC.CommandParser.Common.Command.TCL 5 | { 6 | /* 7 | * @Author: xjm 8 | * @Description: 9 | * @Date: Tuesday, 20 April 2021 22:18:32 10 | * @Email: 326308290@qq.com 11 | */ 12 | public abstract class SetTransactionCommand: AbstractSqlCommand, ITCLCommand 13 | { 14 | public TransactionIsolationLevelEnum? IsolationLevel { get; set; } 15 | public OperationScopeEnum? Scope { get; set; } 16 | public TransactionAccessTypeEnum? AccessMode { get; set; } 17 | } 18 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Value/Literal/Impl/OtherLiteralValue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace NCDC.CommandParser.Common.Value.Literal.Impl 6 | { 7 | /* 8 | * @Author: xjm 9 | * @Description: 10 | * @Date: 2021/4/20 15:38:34 11 | * @Ver: 1.0 12 | * @Email: 326308290@qq.com 13 | */ 14 | public sealed class OtherLiteralValue:ILiteralValue 15 | { 16 | 17 | public OtherLiteralValue(string value) 18 | { 19 | Value = value; 20 | } 21 | public string Value { get; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Dialect/Command/MySql/DML/MySqlDeleteCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command.DML; 2 | using NCDC.CommandParser.Common.Segment.DML.Order; 3 | using NCDC.CommandParser.Common.Segment.DML.Pagination.limit; 4 | using NCDC.CommandParser.Common.Segment.Generic.Table; 5 | 6 | namespace NCDC.CommandParser.Dialect.Command.MySql.DML; 7 | 8 | public sealed class MySqlDeleteCommand:DeleteCommand,IMySqlCommand 9 | { 10 | public OrderBySegment? OrderBy { get; set; } 11 | public LimitSegment? Limit { get; set; } 12 | public MySqlDeleteCommand(ITableSegment table) : base(table) 13 | { 14 | } 15 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingRewrite/NCDCShardingRewriteExtension.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using NCDC.ShardingRewrite.Abstractions; 3 | using NCDC.ShardingRewrite.ParameterRewriters; 4 | 5 | namespace NCDC.ShardingRewrite; 6 | 7 | public static class NCDCShardingRewriteExtension 8 | { 9 | public static IServiceCollection AddShardingRewrite(this IServiceCollection services) 10 | { 11 | services.AddSingleton(); 12 | services.AddSingleton(); 13 | return services; 14 | } 15 | } -------------------------------------------------------------------------------- /src/core/NCDC.Basic/NCDC.Basic.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/core/NCDC/Helpers/UtcTimeHelper.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.Helpers 2 | { 3 | /* 4 | * @Author: xjm 5 | * @Description: 6 | * @Date: 2021/04/16 00:00:00 7 | * @Ver: 1.0 8 | * @Email: 326308290@qq.com 9 | */ 10 | /// 11 | /// 12 | /// 13 | 14 | public class UtcTime 15 | { 16 | private UtcTime(){} 17 | private static readonly long UtcStartTicks = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).Ticks; 18 | public static long CurrentTimeMillis() 19 | { 20 | return (DateTime.UtcNow.Ticks - UtcStartTicks) / 10000; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/DDL/Constraint/ConstraintSegment.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Value.Identifier; 2 | 3 | namespace NCDC.CommandParser.Common.Segment.DDL.Constraint; 4 | 5 | public sealed class ConstraintSegment:ISqlSegment 6 | { 7 | public int StartIndex { get; } 8 | public int StopIndex { get; } 9 | public IdentifierValue IdentifierValue { get; } 10 | 11 | public ConstraintSegment(int startIndex, int stopIndex,IdentifierValue identifierValue) 12 | { 13 | StartIndex = startIndex; 14 | StopIndex = stopIndex; 15 | IdentifierValue = identifierValue; 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /src/orm/NCDC.EntityFrameworkCore/Maps/LogicDatabaseMap.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Microsoft.EntityFrameworkCore.Metadata.Builders; 3 | using NCDC.EntityFrameworkCore.Entities; 4 | 5 | namespace NCDC.EntityFrameworkCore.Maps; 6 | 7 | public class LogicDatabaseMap:BaseMap 8 | { 9 | protected override string TableName => "logic_database"; 10 | protected override void Configure0(EntityTypeBuilder builder) 11 | { 12 | builder.Property(o => o.DatabaseName).IsRequired().HasMaxLength(355); 13 | builder.Property(o => o.ConnectionMode).HasConversion(); 14 | } 15 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingRewrite/Sql/Impl/DefaultSqlBuilder.cs: -------------------------------------------------------------------------------- 1 | 2 | using NCDC.ShardingRewrite.Sql.Token.SimpleObject; 3 | 4 | namespace NCDC.ShardingRewrite.Sql.Impl 5 | { 6 | /* 7 | * @Author: xjm 8 | * @Description: 9 | * @Date: Tuesday, 13 April 2021 20:50:37 10 | * @Email: 326308290@qq.com 11 | */ 12 | public sealed class DefaultSqlBuilder:AbstractSqlBuilder 13 | { 14 | public DefaultSqlBuilder(SqlRewriteContext context) : base(context) 15 | { 16 | } 17 | 18 | protected override string GetSqlTokenText(SqlToken sqlToken) 19 | { 20 | return sqlToken.ToString(); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/DDL/Constraint/Alter/ValidateConstraintDefinitionSegment.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Segment.DDL.Constraint.Alter; 2 | 3 | public sealed class ValidateConstraintDefinitionSegment:IAlterDefinitionSegment 4 | { 5 | public int StartIndex { get; } 6 | public int StopIndex { get; } 7 | public ConstraintSegment ConstraintName { get; } 8 | public ValidateConstraintDefinitionSegment(int startIndex, int stopIndex,ConstraintSegment constraintName) 9 | { 10 | StartIndex = startIndex; 11 | StopIndex = stopIndex; 12 | ConstraintName = constraintName; 13 | } 14 | 15 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingParser/Segment/Insert/Values/Expression/DerivedLiteralExpressionSegment.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Segment.DML.Expr.Simple; 2 | 3 | namespace NCDC.ShardingParser.Segment.Insert.Values.Expression 4 | { 5 | /* 6 | * @Author: xjm 7 | * @Description: 8 | * @Date: 2021/4/13 8:57:18 9 | * @Ver: 1.0 10 | * @Email: 326308290@qq.com 11 | */ 12 | public sealed class DerivedLiteralExpressionSegment: LiteralExpressionSegment, IDerivedSimpleExpressionSegment 13 | { 14 | public DerivedLiteralExpressionSegment(object literals) : base(0, 0, literals) 15 | { 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/DDL/Table/RenameTableDefinitionSegment.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Segment.Generic.Table; 2 | 3 | namespace NCDC.CommandParser.Common.Segment.DDL.Table; 4 | 5 | public sealed class RenameTableDefinitionSegment:IAlterDefinitionSegment 6 | { 7 | public RenameTableDefinitionSegment(int startIndex, int stopIndex) 8 | { 9 | StartIndex = startIndex; 10 | StopIndex = stopIndex; 11 | } 12 | 13 | public int StartIndex { get; } 14 | public int StopIndex { get; } 15 | public SimpleTableSegment? Table { get; set; } 16 | public SimpleTableSegment? RenameTable { get; set; } 17 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Dialect/Command/MySql/Segment/TableIndexSegment.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Segment; 2 | using NCDC.CommandParser.Common.Segment.Generic.Table; 3 | 4 | namespace NCDC.CommandParser.Dialect.Command.MySql.Segment; 5 | 6 | public abstract class TableIndexSegment:ISqlSegment 7 | { 8 | protected TableIndexSegment(int startIndex, int stopIndex, SimpleTableSegment table) 9 | { 10 | StartIndex = startIndex; 11 | StopIndex = stopIndex; 12 | Table = table; 13 | } 14 | 15 | public int StartIndex { get; } 16 | public int StopIndex { get; } 17 | public SimpleTableSegment Table { get; } 18 | } -------------------------------------------------------------------------------- /src/protocol/NCDC.Protocol/MySql/Packet/Command/MySqlCommandPacketTypeLoader.cs: -------------------------------------------------------------------------------- 1 | // using NCDC.Exceptions; 2 | // using NCDC.ProtocolMysql.Payload; 3 | // 4 | // namespace NCDC.ProtocolMysql.Packet.Command; 5 | // 6 | // public sealed class MySqlCommandPacketTypeLoader 7 | // { 8 | // public static MySqlCommandPacketType GetCommandPacketType(MySqlPacketPayload payload) 9 | // { 10 | // if (0 != payload.ReadInt1()) 11 | // { 12 | // throw new ArgumentException($" sequence id of mysql command packet must be `0`."); 13 | // } 14 | // 15 | // return MySqlCommandPacketType.FindById(payload.ReadInt1()); 16 | // } 17 | // } -------------------------------------------------------------------------------- /src/core/NCDC/Exceptions/ShardingNotSupportedException.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace NCDC.Exceptions; 4 | 5 | public class ShardingNotSupportedException:ShardingException 6 | { 7 | public ShardingNotSupportedException() 8 | { 9 | } 10 | 11 | protected ShardingNotSupportedException(SerializationInfo info, StreamingContext context) : base(info, context) 12 | { 13 | } 14 | 15 | public ShardingNotSupportedException(string? message) : base(message) 16 | { 17 | } 18 | 19 | public ShardingNotSupportedException(string? message, Exception? innerException) : base(message, innerException) 20 | { 21 | } 22 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DDL/DropDatabaseCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NCDC.CommandParser.Common.Command.DDL 4 | { 5 | /* 6 | * @Author: xjm 7 | * @Description: 8 | * @Date: Tuesday, 20 April 2021 21:50:40 9 | * @Email: 326308290@qq.com 10 | */ 11 | public abstract class DropDatabaseCommand:AbstractSqlCommand,IDDLCommand 12 | { 13 | protected DropDatabaseCommand(string databaseName, bool ifExists) 14 | { 15 | DatabaseName = databaseName; 16 | IfExists = ifExists; 17 | } 18 | 19 | public string DatabaseName { get; } 20 | public bool IfExists { get;} 21 | } 22 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/StreamMerges/Results/QueryExecuteResult.cs: -------------------------------------------------------------------------------- 1 | using System.Data.Common; 2 | using NCDC.StreamDataReaders; 3 | 4 | namespace NCDC.ProxyServer.StreamMerges.Results; 5 | 6 | public sealed class QueryExecuteResult:IExecuteResult 7 | { 8 | public List DbColumns { get; } 9 | public IStreamDataReader StreamDataReader { get; } 10 | 11 | public QueryExecuteResult(List dbColumns,IStreamDataReader streamDataReader) 12 | { 13 | DbColumns = dbColumns; 14 | StreamDataReader = streamDataReader; 15 | } 16 | 17 | public void Dispose() 18 | { 19 | StreamDataReader.Dispose(); 20 | } 21 | } -------------------------------------------------------------------------------- /src/core/NCDC.Plugin/DataSourceRouteResult.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.Plugin; 2 | 3 | public class DataSourceRouteResult 4 | { 5 | public DataSourceRouteResult(ICollection intersectDataSources) 6 | { 7 | IntersectDataSources = intersectDataSources; 8 | } 9 | public DataSourceRouteResult(string dataSource):this(new List(){dataSource}) 10 | { 11 | } 12 | /// 13 | /// 交集 14 | /// 15 | public ICollection IntersectDataSources { get; } 16 | 17 | public override string ToString() 18 | { 19 | return $"data source route result:{string.Join(",", IntersectDataSources)}"; 20 | } 21 | } -------------------------------------------------------------------------------- /src/core/NCDC.Plugin/TableRouteRules/ITableRouteRule.cs: -------------------------------------------------------------------------------- 1 | using NCDC.Plugin.Enums; 2 | 3 | namespace NCDC.Plugin.TableRouteRules; 4 | 5 | public interface ITableRouteRule:IRouteRule 6 | { 7 | string TableName { get; } 8 | Func RouteFilter(IComparable shardingValue, 9 | ShardingOperatorEnum shardingOperator, string columnName,bool isMainShardingColumn); 10 | 11 | ICollection BeforeFilterTableName(ICollection allDataSource); 12 | 13 | ICollection AfterFilterTableName(ICollection allTableNames, 14 | ICollection beforeTableNames, 15 | ICollection filterRouteUnits); 16 | } -------------------------------------------------------------------------------- /src/core/NCDC/Base/OneByOneChecker.cs: -------------------------------------------------------------------------------- 1 | using NCDC.Exceptions; 2 | 3 | namespace NCDC.Base; 4 | 5 | public class OneByOneChecker 6 | { 7 | private readonly OneByOneCheck _oneByOne; 8 | 9 | public OneByOneChecker() 10 | { 11 | _oneByOne = new OneByOneCheck(); 12 | } 13 | 14 | public void OneByOneLock() 15 | { 16 | //是否触发并发了 17 | var acquired = _oneByOne.Start(); 18 | if (!acquired) 19 | { 20 | throw new ShardingException($"{nameof(OneByOneLock)} cant parallel use in connection "); 21 | } 22 | } 23 | 24 | public void OneByOneUnLock() 25 | { 26 | _oneByOne.Stop(); 27 | } 28 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/DML/Expr/ExistsSubQueryExpression.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Segment.DML.Expr.SubQuery; 2 | 3 | namespace NCDC.CommandParser.Common.Segment.DML.Expr; 4 | 5 | public sealed class ExistsSubQueryExpression:IExpressionSegment 6 | { 7 | public ExistsSubQueryExpression(int startIndex, int stopIndex,SubQuerySegment subQuery) 8 | { 9 | StartIndex = startIndex; 10 | StopIndex = stopIndex; 11 | SubQuery = subQuery; 12 | } 13 | 14 | public int StartIndex { get; } 15 | public int StopIndex { get; } 16 | public SubQuerySegment SubQuery { get; } 17 | public bool Not { get; set; } 18 | } -------------------------------------------------------------------------------- /src/orm/NCDC.EntityFrameworkCore/Maps/AppAuthUserMap.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Metadata.Builders; 2 | using NCDC.EntityFrameworkCore.Entities; 3 | 4 | namespace NCDC.EntityFrameworkCore.Maps; 5 | 6 | public class AppAuthUserMap:BaseMap 7 | { 8 | protected override string TableName => "app_auth_user"; 9 | protected override void Configure0(EntityTypeBuilder builder) 10 | { 11 | builder.Property(o => o.UserName).IsRequired().HasMaxLength(255); 12 | builder.Property(o => o.Password).IsRequired().HasMaxLength(255); 13 | builder.Property(o => o.HostName).IsRequired().HasMaxLength(255); 14 | } 15 | } -------------------------------------------------------------------------------- /src/protocol/NCDC.Protocol/MySql/Packet/Handshake/MySqlAuthSwitchResponsePacket.cs: -------------------------------------------------------------------------------- 1 | using NCDC.Protocol.MySql.Payload; 2 | 3 | namespace NCDC.Protocol.MySql.Packet.Handshake; 4 | 5 | public sealed class MySqlAuthSwitchResponsePacket : IMysqlPacket 6 | { 7 | public MySqlAuthSwitchResponsePacket(MySqlPacketPayload payload) 8 | { 9 | SequenceId = payload.ReadInt1(); 10 | AuthPluginResponse = payload.ReadStringEOFByBytes(); 11 | } 12 | public void WriteTo(MySqlPacketPayload payload) 13 | { 14 | payload.WriteBytes(AuthPluginResponse); 15 | } 16 | 17 | public int SequenceId { get; } 18 | public byte[] AuthPluginResponse { get; } 19 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/AppServices/Abstractions/IAppRuntimeManager.cs: -------------------------------------------------------------------------------- 1 | using NCDC.Basic.User; 2 | using NCDC.ProxyServer.Runtimes; 3 | 4 | namespace NCDC.ProxyServer.AppServices.Abstractions; 5 | 6 | public interface IAppRuntimeManager 7 | { 8 | bool ContainsRuntimeContext(string databaseName); 9 | IRuntimeContext GetRuntimeContext(string databaseName); 10 | ICollection GetAllDatabaseNames(); 11 | ICollection GetAllUsers(); 12 | ICollection GetAuthorizedDatabases(string username); 13 | ICollection GetAuthorizedUsers(string database); 14 | AuthUser GetUser(string username); 15 | bool ContainsAppUser(string username); 16 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Binaries/BinaryCell.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ProxyServer.Binaries; 2 | 3 | /// 4 | /// 二进制单元格 5 | /// 6 | public class BinaryCell 7 | { 8 | /// 9 | /// 列CSharpLanguage类型 10 | /// 11 | public Type ClrType { get; } 12 | // /// 13 | // /// 列数据库类型 14 | // /// 15 | // public int ColumnType { get; } 16 | /// 17 | /// 数据 18 | /// 19 | public object? Data { get; } 20 | 21 | public BinaryCell(object? data, Type clrType) 22 | { 23 | Data = data; 24 | ClrType = clrType; 25 | // ColumnType = columnType; 26 | } 27 | } -------------------------------------------------------------------------------- /src/core/NCDC.Plugin/DataSourceRouteRules/IDataSourceRouteRule.cs: -------------------------------------------------------------------------------- 1 | using NCDC.Plugin.Enums; 2 | 3 | namespace NCDC.Plugin.DataSourceRouteRules; 4 | 5 | public interface IDataSourceRouteRule:IRouteRule 6 | { 7 | string TableName { get; } 8 | Func RouteFilter(IComparable shardingValue, 9 | ShardingOperatorEnum shardingOperator, string columnName,bool isMainShardingColumn); 10 | 11 | ICollection BeforeFilterDataSource(ICollection allDataSource); 12 | 13 | ICollection AfterFilterDataSource(ICollection allDataSources, 14 | ICollection beforeDataSources, 15 | ICollection filterDataSources); 16 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Command/DDL/CreateDatabaseCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NCDC.CommandParser.Common.Command.DDL 4 | { 5 | /* 6 | * @Author: xjm 7 | * @Description: 8 | * @Date: Tuesday, 20 April 2021 21:42:43 9 | * @Email: 326308290@qq.com 10 | */ 11 | public abstract class CreateDatabaseCommand:AbstractSqlCommand,IDDLCommand 12 | { 13 | protected CreateDatabaseCommand(string databaseName, bool ifNotExists) 14 | { 15 | DatabaseName = databaseName; 16 | IfNotExists = ifNotExists; 17 | } 18 | 19 | public string DatabaseName { get; } 20 | public bool IfNotExists { get; } 21 | } 22 | } -------------------------------------------------------------------------------- /src/protocol/NCDC.Protocol/MySql/Constant/MySqlAuthenticationMethod.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.Protocol.MySql.Constant; 2 | 3 | /// 4 | /// https://dev.mysql.com/doc/internals/en/authentication-method.html 5 | /// 6 | public class MySqlAuthenticationMethod 7 | { 8 | public static string OLD_PASSWORD_AUTHENTICATION = "mysql_old_password"; 9 | public static string NATIVE_PASSWORD_AUTHENTICATION = "mysql_native_password"; 10 | public static string CLEAR_PASSWORD_AUTHENTICATION = "mysql_clear_password"; 11 | public static string WINDOWS_CLIENT_AUTHENTICATION = "authentication_windows_client"; 12 | public static string SHA256_AUTHENTICATION = "sha256_password"; 13 | } -------------------------------------------------------------------------------- /src/protocol/NCDC.Protocol/MySql/Packet/Command/MySqlServerComSetOptionPacket.cs: -------------------------------------------------------------------------------- 1 | // using NCDC.Protocol.MySql.Payload; 2 | // using NCDC.ProtocolMysql.Packet.ServerCommand; 3 | // 4 | // namespace NCDC.Protocol.MySql.Packet.Command; 5 | // 6 | // public class MySqlServerComSetOptionPacket:AbstractMySqlServerCommandPacket 7 | // { 8 | // public const int MYSQL_OPTION_MULTI_STATEMENTS_ON = 0; 9 | // public const int MYSQL_OPTION_MULTI_STATEMENTS_OFF = 1; 10 | // public int Value { get; } 11 | // public MySqlServerComSetOptionPacket(MySqlPacketPayload payload) : base(MySqlCommandTypeEnum.COM_SET_OPTION) 12 | // { 13 | // Value = payload.ReadInt2(); 14 | // } 15 | // } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Databases/IDataSource.cs: -------------------------------------------------------------------------------- 1 | using System.Data.Common; 2 | using NCDC.ProxyServer.Connection.Abstractions; 3 | 4 | namespace NCDC.ProxyServer.Databases; 5 | 6 | public interface IDataSource 7 | { 8 | /// 9 | /// data source name 10 | /// 11 | string DataSourceName { get; } 12 | /// 13 | /// 数据源链接 14 | /// 15 | string ConnectionString { get; } 16 | /// 17 | /// 是否是默认的数据源 18 | /// 19 | bool IsDefault { get; } 20 | 21 | ValueTask CreateDbConnectionAsync(bool open); 22 | ValueTask CreateServerDbConnectionAsync(); 23 | } -------------------------------------------------------------------------------- /src/core/NCDC/Exceptions/ShardingInvalidOperationException.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace NCDC.Exceptions; 4 | 5 | public class ShardingInvalidOperationException:ShardingException 6 | { 7 | public ShardingInvalidOperationException() 8 | { 9 | } 10 | 11 | protected ShardingInvalidOperationException(SerializationInfo info, StreamingContext context) : base(info, context) 12 | { 13 | } 14 | 15 | public ShardingInvalidOperationException(string message) : base(message) 16 | { 17 | } 18 | 19 | public ShardingInvalidOperationException(string message, Exception innerException) : base(message, innerException) 20 | { 21 | } 22 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/DAL/ShowLikeSegment.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Segment.DAL 2 | { 3 | /* 4 | * @Author: xjm 5 | * @Description: 6 | * @Date: Monday, 12 April 2021 22:27:32 7 | * @Email: 326308290@qq.com 8 | */ 9 | public sealed class ShowLikeSegment:ISqlSegment 10 | { 11 | public int StartIndex { get; } 12 | public int StopIndex { get; } 13 | public string Pattern { get; } 14 | 15 | public ShowLikeSegment(int startIndex, int stopIndex, string pattern) 16 | { 17 | StartIndex = startIndex; 18 | StopIndex = stopIndex; 19 | Pattern = pattern; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Helpers/AutoCommitHelper.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command; 2 | using NCDC.CommandParser.Common.Command.DDL; 3 | using NCDC.CommandParser.Common.Command.DML; 4 | 5 | namespace NCDC.ProxyServer.Helpers; 6 | 7 | public class AutoCommitHelper 8 | { 9 | public static bool NeedOpenTransaction(ISqlCommand sqlCommand) 10 | { 11 | if (sqlCommand is SelectCommand selectCommand && null == selectCommand.From) 12 | { 13 | return false; 14 | } 15 | 16 | if (sqlCommand is IDDLCommand || sqlCommand is IDMLCommand) 17 | { 18 | return true; 19 | } 20 | 21 | return false; 22 | } 23 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Runtimes/Builder/DataSourceNode.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ProxyServer.Runtimes.Builder; 2 | 3 | public sealed class DataSourceNode 4 | { 5 | /// 6 | /// 数据源名称 7 | /// 8 | public string Name { get; } 9 | /// 10 | /// 数据源链接字符串 11 | /// 12 | public string ConnectionString { get; } 13 | /// 14 | /// 是否默认数据源 15 | /// 16 | public bool IsDefault { get; } 17 | 18 | public DataSourceNode(string name,string connectionString,bool isDefault) 19 | { 20 | Name = name; 21 | ConnectionString = connectionString; 22 | IsDefault = isDefault; 23 | } 24 | } -------------------------------------------------------------------------------- /test/NCDC.ShardingTest/Seed/Maps/LogDayMap.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Microsoft.EntityFrameworkCore.Metadata.Builders; 3 | using NCDC.ShardingTest.Seed.Entities; 4 | 5 | namespace NCDC.ShardingTest.Seed.Maps 6 | { 7 | public class LogDayMap:IEntityTypeConfiguration 8 | { 9 | public void Configure(EntityTypeBuilder builder) 10 | { 11 | builder.HasKey(o => o.Id); 12 | builder.Property(o => o.LogLevel).IsRequired().IsUnicode(false).HasMaxLength(32); 13 | builder.Property(o => o.LogBody).IsRequired().HasMaxLength(256); 14 | builder.ToTable(nameof(LogDay)); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingRewrite/Token/SimpleObject/DistinctProjectionPrefixToken.cs: -------------------------------------------------------------------------------- 1 | using NCDC.ShardingRewrite.Sql.Token.SimpleObject; 2 | 3 | namespace NCDC.ShardingRewrite.Token.SimpleObject 4 | { 5 | /* 6 | * @Author: xjm 7 | * @Description: 8 | * @Date: 2021/4/27 16:13:44 9 | * @Ver: 1.0 10 | * @Email: 326308290@qq.com 11 | */ 12 | public sealed class DistinctProjectionPrefixToken:SqlToken,IAttachable 13 | { 14 | public DistinctProjectionPrefixToken(int startIndex) : base(startIndex) 15 | { 16 | } 17 | 18 | public override string ToString() 19 | { 20 | return "DISTINCT "; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/DDL/Charset/CharsetNameSegment.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Segment.DDL.Charset; 2 | 3 | public sealed class CharsetNameSegment:ISqlSegment 4 | { 5 | public CharsetNameSegment(int startIndex, int stopIndex,string name) 6 | { 7 | StartIndex = startIndex; 8 | StopIndex = stopIndex; 9 | Name = name; 10 | } 11 | 12 | public int StartIndex { get; } 13 | public int StopIndex { get; } 14 | public string Name { get; } 15 | 16 | public override string ToString() 17 | { 18 | return $"{nameof(StartIndex)}: {StartIndex}, {nameof(StopIndex)}: {StopIndex}, {nameof(Name)}: {Name}"; 19 | } 20 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/ISqlSegment.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Abstractions; 2 | 3 | 4 | namespace NCDC.CommandParser.Common.Segment 5 | { 6 | /* 7 | * @Author: xjm 8 | * @Description: 9 | * @Date: 2021/4/10 9:49:09 10 | * @Ver: 1.0 11 | * @Email: 326308290@qq.com 12 | */ 13 | public interface ISqlSegment:IASTNode 14 | { 15 | /// 16 | /// 起始索引 17 | /// 18 | /// 19 | int StartIndex { get; } 20 | 21 | /// 22 | /// 结束索引 23 | /// 24 | /// 25 | int StopIndex { get; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/AppServices/AppConfiguration.cs: -------------------------------------------------------------------------------- 1 | using NCDC.Enums; 2 | using NCDC.ProxyServer.AppServices.Abstractions; 3 | using NCDC.ProxyServer.Commons; 4 | 5 | namespace NCDC.ProxyServer.AppServices; 6 | 7 | public class AppConfiguration : IAppConfiguration 8 | { 9 | public DatabaseTypeEnum DatabaseType { get; set; } = DatabaseTypeEnum.MySql; 10 | public DbStorageTypeEnum StorageType { get; set; } = DbStorageTypeEnum.MySql; 11 | public string ConnectionsString { get; set; } = null!; 12 | public int Port { get; set; } = 3307; 13 | public string RulePluginPath { get; set; } = null!; 14 | public bool LogEncode { get; set; } 15 | public bool LogDecode { get; set; } 16 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Dialect/Command/MySql/DML/MySqlSelectCommand.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command.DML; 2 | using NCDC.CommandParser.Common.Segment.DML.Pagination.limit; 3 | using NCDC.CommandParser.Common.Segment.DML.Predicate; 4 | using NCDC.CommandParser.Common.Segment.Generic; 5 | using NCDC.CommandParser.Common.Segment.Generic.Table; 6 | 7 | namespace NCDC.CommandParser.Dialect.Command.MySql.DML; 8 | 9 | public sealed class MySqlSelectCommand:SelectCommand,IMySqlCommand 10 | { 11 | public SimpleTableSegment? Table { get; set; } 12 | public LimitSegment? Limit { get; set; } 13 | public LockSegment? Lock { get; set; } 14 | public WindowSegment? Window { get; set; } 15 | } -------------------------------------------------------------------------------- /src/orm/NCDC.EntityFrameworkCore/Entities/ActualTableEntity.cs: -------------------------------------------------------------------------------- 1 | using NCDC.EntityFrameworkCore.Entities.Base; 2 | 3 | namespace NCDC.EntityFrameworkCore.Entities; 4 | 5 | public class ActualTableEntity:BaseEntity 6 | { 7 | /// 8 | /// 表名 9 | /// 10 | public string TableName { get; set; } = null!; 11 | /// 12 | /// 数据库 13 | /// 14 | public string LogicDatabaseId { get; set; } = null!; 15 | /// 16 | /// 逻辑表名 17 | /// 18 | public string LogicTableId { get; set; } = null!; 19 | /// 20 | /// 数据源 21 | /// 22 | public string DataSourceId { get; set; } = null!; 23 | 24 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingMerge/DataReaderMergers/DQL/GroupBy/Aggregation/IAggregationUnit.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ShardingMerge.DataReaderMergers.DQL.GroupBy.Aggregation 2 | { 3 | /* 4 | * @Author: xjm 5 | * @Description: 6 | * @Date: Friday, 07 May 2021 21:42:24 7 | * @Email: 326308290@qq.com 8 | */ 9 | public interface IAggregationUnit 10 | { 11 | 12 | /** 13 | * merge aggregation values. 14 | * 15 | * @param values aggregation values 16 | */ 17 | void Merge(List values); 18 | 19 | /** 20 | * Get aggregation result. 21 | * 22 | * @return aggregation result 23 | */ 24 | IComparable GetResult(); 25 | } 26 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingRewrite/Sql/Token/SimpleObject/Generic/RemoveToken.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ShardingRewrite.Sql.Token.SimpleObject.Generic 2 | { 3 | /* 4 | * @Author: xjm 5 | * @Description: 6 | * @Date: 2021/4/24 10:44:07 7 | * @Ver: 1.0 8 | * @Email: 326308290@qq.com 9 | */ 10 | public sealed class RemoveToken:SqlToken,ISubstitutable 11 | { 12 | private readonly int _stopIndex; 13 | 14 | public RemoveToken(int startIndex,int stopIndex) : base(startIndex) 15 | { 16 | _stopIndex = stopIndex; 17 | } 18 | 19 | public int GetStopIndex() 20 | { 21 | return _stopIndex; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingRoute/Abstractions/ITableRouteManager.cs: -------------------------------------------------------------------------------- 1 | using NCDC.Plugin; 2 | using NCDC.ShardingParser; 3 | using NCDC.ShardingRoute.DataSourceRoutes; 4 | using NCDC.ShardingRoute.TableRoutes; 5 | using NCDC.ShardingRoute.TableRoutes.Abstractions; 6 | 7 | namespace NCDC.ShardingRoute.Abstractions; 8 | 9 | public interface ITableRouteManager 10 | { 11 | bool HasRoute(string tableName); 12 | ITableRoute GetRoute(string tableName); 13 | IReadOnlyCollection GetRoutes(); 14 | bool AddRoute(ITableRoute route); 15 | 16 | ICollection RouteTo(string tableName, DataSourceRouteResult dataSourceRouteResult, 17 | SqlParserResult sqlParserResult); 18 | } -------------------------------------------------------------------------------- /test/NCDC.ShardingTest/Seed/Shardings/PaginationConfigs/LogDayPaginationConfiguration.cs: -------------------------------------------------------------------------------- 1 | using NCDC.ShardingTest.Seed.Entities; 2 | using ShardingCore.Sharding.PaginationConfigurations; 3 | 4 | namespace NCDC.ShardingTest.Seed.Shardings.PaginationConfigs 5 | { 6 | public class LogDayPaginationConfiguration: IPaginationConfiguration 7 | { 8 | public void Configure(PaginationBuilder builder) 9 | { 10 | builder.PaginationSequence(o => o.LogTime) 11 | .UseQueryMatch(PaginationMatchEnum.Named | PaginationMatchEnum.Owner | 12 | PaginationMatchEnum.PrimaryMatch).UseAppendIfOrderNone(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /test/NCDC.ShardingTest/Seed2/TypeSeedDbContext.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using NCDC.ShardingTest.Seed2.Maps; 3 | 4 | namespace NCDC.ShardingTest.Seed2; 5 | 6 | public class TypeSeedDbContext:DbContext 7 | { 8 | public TypeSeedDbContext(DbContextOptions options):base(options) 9 | { 10 | 11 | } 12 | 13 | protected override void OnModelCreating(ModelBuilder modelBuilder) 14 | { 15 | base.OnModelCreating(modelBuilder); 16 | modelBuilder.ApplyConfiguration(new StringEntityMap()); 17 | modelBuilder.ApplyConfiguration(new NumberEntityMap()); 18 | modelBuilder.ApplyConfiguration(new DateTimeEntityMap()); 19 | } 20 | } -------------------------------------------------------------------------------- /src/core/NCDC/Enums/ConnectionModeEnum.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.Enums 2 | { 3 | /// 4 | /// 链接模式,可以由用户自行指定,使用内存限制,和连接数限制或者系统自行选择最优 5 | /// MEMORY_STRICTLY的意思是最小化内存使用率,就是非一次性获取所有数据然后采用流式聚合 6 | /// CONNECTION_STRICTLY的意思是最小化连接并发数,就是单次查询并发连接数为设置的连接数。因为有限制,所以无法一直挂起连接,必须全部获取到内存后进行内存聚合 7 | /// 系统自行选择会根据用户的配置采取最小化连接数,但是如果遇到分页则会根据分页策略采取内存限制,因为skip过大会导致内存爆炸 8 | /// 9 | public enum ConnectionModeEnum 10 | { 11 | //内存限制模式最小化内存聚合 流式聚合 同时会有多个链接 12 | MEMORY_STRICTLY, 13 | //连接数限制模式最小化并发连接数 内存聚合 连接数会有限制 14 | CONNECTION_STRICTLY, 15 | //系统自动选择内存还是流式聚合 16 | SYSTEM_AUTO 17 | } 18 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Value/Literal/Impl/StringLiteralValue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using NCDC.Extensions; 5 | 6 | namespace NCDC.CommandParser.Common.Value.Literal.Impl 7 | { 8 | /* 9 | * @Author: xjm 10 | * @Description: 11 | * @Date: 2021/4/20 15:23:22 12 | * @Ver: 1.0 13 | * @Email: 326308290@qq.com 14 | */ 15 | public sealed class StringLiteralValue:ILiteralValue 16 | { 17 | 18 | public StringLiteralValue(string value) 19 | { 20 | Value = value.SubStringWithEndIndex(1,value.Length-1); 21 | } 22 | public string Value { get; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/orm/NCDC.EntityFrameworkCore/Maps/ActualDatabaseMap.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Metadata.Builders; 2 | using NCDC.EntityFrameworkCore.Entities; 3 | 4 | namespace NCDC.EntityFrameworkCore.Maps; 5 | 6 | public class ActualDatabaseMap:BaseMap 7 | { 8 | protected override string TableName => "actual_database"; 9 | protected override void Configure0(EntityTypeBuilder builder) 10 | { 11 | builder.Property(o => o.LogicDatabaseId).IsRequired().HasMaxLength(50); 12 | builder.Property(o => o.DataSourceName).IsRequired().HasMaxLength(255); 13 | builder.Property(o => o.ConnectionString).IsRequired().HasMaxLength(255); 14 | } 15 | } -------------------------------------------------------------------------------- /src/sharding/NCDC.ShardingRewrite/Token/SimpleObject/ParameterMarkerGeneratedKeyAssignmentToken.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ShardingRewrite.Token.SimpleObject 2 | { 3 | /* 4 | * @Author: xjm 5 | * @Description: 6 | * @Date: 2021/4/27 16:41:46 7 | * @Ver: 1.0 8 | * @Email: 326308290@qq.com 9 | */ 10 | public sealed class ParameterMarkerGeneratedKeyAssignmentToken:GeneratedKeyAssignmentToken 11 | { 12 | public ParameterMarkerGeneratedKeyAssignmentToken(int startIndex, string columnName) : base(startIndex, columnName) 13 | { 14 | } 15 | 16 | protected override string GetRightValue() 17 | { 18 | return "?"; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/core/NCDC.Plugin/DefaultRules/TableRules/ModLongTableRule.cs: -------------------------------------------------------------------------------- 1 | using NCDC.Plugin.DefaultRules.ShardingRuleParams; 2 | 3 | namespace NCDC.Plugin.DefaultRules.TableRules; 4 | 5 | public class ModLongTableRule: AbstractModNumberTableRule 6 | { 7 | private readonly TableRuleParam _tableRuleParam; 8 | 9 | public ModLongTableRule(TableRuleParam tableRuleParam) : base(tableRuleParam) 10 | { 11 | _tableRuleParam = tableRuleParam; 12 | } 13 | 14 | protected override string FormatToTail(IComparable shardingValue) 15 | { 16 | var hashCode = (long)shardingValue; 17 | return Math.Abs(hashCode % _tableRuleParam.Mod).ToString().PadLeft(_tableRuleParam.TailLength,'0'); 18 | } 19 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyClient/Authentication/AuthenticationResult.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ProxyClient.Authentication; 2 | 3 | public class AuthenticationResult 4 | { 5 | public string? Username { get; } 6 | public string? Hostname { get; } 7 | public string? Database { get; } 8 | public bool Finished { get; } 9 | 10 | public AuthenticationResult(string? username,string? hostname,string? database,bool finished) 11 | { 12 | Username = username; 13 | Hostname = hostname; 14 | Database = database; 15 | Finished = finished; 16 | } 17 | 18 | public static AuthenticationResult DefaultContinued { get; } = 19 | new AuthenticationResult(null, null, null, false); 20 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyClientMySql/ClientConnections/DataReaders/Quit/MySqlQuitClientDataReader.cs: -------------------------------------------------------------------------------- 1 | using NCDC.Protocol.MySql.Constant; 2 | using NCDC.Protocol.MySql.Packet.Generic; 3 | using NCDC.Protocol.MySql.Payload; 4 | using NCDC.Protocol.Packets; 5 | using NCDC.ProxyClient.Abstractions; 6 | 7 | namespace NCDC.ProxyClientMySql.ClientConnections.DataReaders.Quit; 8 | 9 | public class MySqlQuitClientDataReader:IClientDataReader 10 | { 11 | public async IAsyncEnumerable> SendCommand() 12 | { 13 | var mySqlOkPacket = new MySqlOkPacket(1, MySqlStatusFlagEnum.SERVER_STATUS_DEFAULT); 14 | yield return await Task.FromResult(mySqlOkPacket); 15 | } 16 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyServer/Executors/CommandExecuteUnit.cs: -------------------------------------------------------------------------------- 1 | using System.Data.Common; 2 | using NCDC.Enums; 3 | using NCDC.ProxyServer.Connection.Abstractions; 4 | 5 | namespace NCDC.ProxyServer.Executors; 6 | 7 | 8 | public sealed class CommandExecuteUnit 9 | { 10 | public ExecutionUnit ExecutionUnit { get; } 11 | 12 | public DbCommand ServerDbCommand{ get; } 13 | 14 | public ConnectionModeEnum ConnectionMode{ get; } 15 | 16 | public CommandExecuteUnit(ExecutionUnit executionUnit, DbCommand dbCommand, ConnectionModeEnum connectionMode) 17 | { 18 | ExecutionUnit = executionUnit; 19 | ServerDbCommand = dbCommand; 20 | ConnectionMode = connectionMode; 21 | } 22 | } -------------------------------------------------------------------------------- /test/NCDC.ShardingTest/Seed/Maps/LogWeekDateTimeMap.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Microsoft.EntityFrameworkCore.Metadata.Builders; 3 | using NCDC.ShardingTest.Seed.Entities; 4 | 5 | namespace NCDC.ShardingTest.Seed.Maps 6 | { 7 | public class LogWeekDateTimeMap:IEntityTypeConfiguration 8 | { 9 | public void Configure(EntityTypeBuilder builder) 10 | { 11 | builder.HasKey(o => o.Id); 12 | builder.Property(o => o.Id).IsRequired().IsUnicode(false).HasMaxLength(50); 13 | builder.Property(o => o.Body).HasMaxLength(128); 14 | builder.ToTable(nameof(LogWeekDateTime)); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/DML/Predicate/Value/PredicateRightBracketValue.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Segment.DML.Predicate.Value 2 | { 3 | /* 4 | * @Author: xjm 5 | * @Description: 6 | * @Date: 2021/4/12 12:42:34 7 | * @Ver: 1.0 8 | * @Email: 326308290@qq.com 9 | */ 10 | public sealed class PredicateRightBracketValue:IPredicateRightValue 11 | { 12 | private readonly int _startIndex; 13 | 14 | private readonly int _stopIndex; 15 | 16 | public PredicateRightBracketValue(int startIndex, int stopIndex) 17 | { 18 | _startIndex = startIndex; 19 | _stopIndex = stopIndex; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /test/NCDC.ShardingTest/Seed/Entities/SysUserMod.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.ShardingTest.Seed.Entities; 2 | 3 | /* 4 | * @Author: xjm 5 | * @Description: 6 | * @Date: Thursday, 14 January 2021 15:36:43 7 | * @Email: 326308290@qq.com 8 | */ 9 | public class SysUserMod : IId 10 | { 11 | /// 12 | /// 用户Id用于分表 13 | /// 14 | public string Id { get; set; } 15 | 16 | /// 17 | /// 用户名称 18 | /// 19 | public string Name { get; set; } 20 | 21 | /// 22 | /// 用户姓名 23 | /// 24 | public int Age { get; set; } 25 | 26 | public int AgeGroup { get; set; } 27 | } 28 | 29 | public interface IId 30 | { 31 | string Id { get; set; } 32 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/DML/Prepare/PrepareCommandQuerySegment.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Command.DML; 2 | 3 | namespace NCDC.CommandParser.Common.Segment.DML.Prepare; 4 | 5 | public sealed class PrepareCommandQuerySegment:ISqlSegment 6 | { 7 | public PrepareCommandQuerySegment(int startIndex, int stopIndex) 8 | { 9 | StartIndex = startIndex; 10 | StopIndex = stopIndex; 11 | } 12 | 13 | public int StartIndex { get; } 14 | public int StopIndex { get; } 15 | public SelectCommand? Select { get; set; } 16 | public InsertCommand? Insert { get; set; } 17 | public UpdateCommand? Update { get; set; } 18 | public DeleteCommand? Delete { get; set; } 19 | } -------------------------------------------------------------------------------- /src/orm/NCDC.EntityFrameworkCore/Entities/AppAuthUserEntity.cs: -------------------------------------------------------------------------------- 1 | using NCDC.EntityFrameworkCore.Entities.Base; 2 | 3 | namespace NCDC.EntityFrameworkCore.Entities; 4 | 5 | /// 6 | /// 应用授权用户 7 | /// 8 | public class AppAuthUserEntity:BaseEntity 9 | { 10 | /// 11 | /// 用户名 12 | /// 13 | public string UserName { get; set; } = null!; 14 | /// 15 | /// 密码 16 | /// 17 | public string Password { get; set; } = null!; 18 | /// 19 | /// 限制地址 20 | /// 21 | public string HostName { get; set; } = null!; 22 | /// 23 | /// 是否启用 24 | /// 25 | public bool IsEnable { get; set; } 26 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/DDL/Types/TypeSegment.cs: -------------------------------------------------------------------------------- 1 | using NCDC.CommandParser.Common.Segment.Generic; 2 | using NCDC.CommandParser.Common.Value.Identifier; 3 | 4 | namespace NCDC.CommandParser.Common.Segment.DDL.Types; 5 | 6 | public sealed class TypeSegment:ISqlSegment,IOwnerAvailable 7 | { 8 | public TypeSegment(int startIndex, int stopIndex,IdentifierValue identifierValue) 9 | { 10 | StartIndex = startIndex; 11 | StopIndex = stopIndex; 12 | IdentifierValue = identifierValue; 13 | } 14 | 15 | public int StartIndex { get; } 16 | public int StopIndex { get; } 17 | public IdentifierValue IdentifierValue { get; } 18 | public OwnerSegment? Owner { get; set; } 19 | } -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyClient/IDatabaseProtocolClientEngine.cs: -------------------------------------------------------------------------------- 1 | using NCDC.ProxyClient.Abstractions; 2 | using NCDC.ProxyClient.Authentication; 3 | using NCDC.ProxyClient.Codecs; 4 | using NCDC.ProxyServer.Connection.Abstractions; 5 | 6 | namespace NCDC.ProxyClient; 7 | 8 | public interface IDatabaseProtocolClientEngine 9 | { 10 | 11 | IPacketCodec GetPacketCodec(); 12 | // IAuthenticationEngine GetAuthenticationEngine(); 13 | IAuthenticationHandler GetAuthenticationHandler(); 14 | IAuthContext GetAuthContext(); 15 | IClientDbConnection GetClientDbConnection(); 16 | void Release(IConnectionSession connectionSession); 17 | void HandleException(IConnectionSession connectionSession, Exception exception); 18 | } -------------------------------------------------------------------------------- /test/ShardingConnector.HiSqlTest/ShardingConnector.HiSqlTest.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net6.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/proxy/NCDC.ProxyClientMySql/Common/ServerStatusFlagCalculator.cs: -------------------------------------------------------------------------------- 1 | using NCDC.Protocol.MySql.Constant; 2 | using NCDC.ProxyServer.Connection.Abstractions; 3 | 4 | namespace NCDC.ProxyClientMySql.Common; 5 | 6 | public sealed class ServerStatusFlagCalculator 7 | { 8 | public static MySqlStatusFlagEnum CalculateFor(IConnectionSession connectionSession) 9 | { 10 | int result = 0; 11 | result |= connectionSession.GetIsAutoCommit() ? (int)MySqlStatusFlagEnum.SERVER_STATUS_AUTOCOMMIT : 0; 12 | result |= connectionSession.GetTransactionStatus().IsInTransaction() 13 | ? (int)MySqlStatusFlagEnum.SERVER_STATUS_IN_TRANS 14 | : 0; 15 | return (MySqlStatusFlagEnum)result; 16 | } 17 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/DML/Expr/ListExpression.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Segment.DML.Expr; 2 | 3 | public sealed class ListExpression:IExpressionSegment 4 | { 5 | public ListExpression(int startIndex, int stopIndex) 6 | { 7 | StartIndex = startIndex; 8 | StopIndex = stopIndex; 9 | Items = new LinkedList(); 10 | } 11 | 12 | public int StartIndex { get; } 13 | public int StopIndex { get; } 14 | public ICollection Items { get; } 15 | 16 | public override string ToString() 17 | { 18 | return $"{nameof(StartIndex)}: {StartIndex}, {nameof(StopIndex)}: {StopIndex}, {nameof(Items)}: {Items}"; 19 | } 20 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/DDL/Column/Position/ColumnAfterPositionSegment.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using NCDC.CommandParser.Common.Segment.DML.Column; 5 | 6 | namespace NCDC.CommandParser.Common.Segment.DDL.Column.Position 7 | { 8 | /* 9 | * @Author: xjm 10 | * @Description: 11 | * @Date: 2021/4/20 17:04:35 12 | * @Ver: 1.0 13 | * @Email: 326308290@qq.com 14 | */ 15 | public sealed class ColumnAfterPositionSegment:ColumnPositionSegment 16 | { 17 | public ColumnAfterPositionSegment(int startIndex, int stopIndex, ColumnSegment? columnName) : base(startIndex, stopIndex, columnName) 18 | { 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/DDL/Column/Position/ColumnFirstPositionSegment.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using NCDC.CommandParser.Common.Segment.DML.Column; 5 | 6 | namespace NCDC.CommandParser.Common.Segment.DDL.Column.Position 7 | { 8 | /* 9 | * @Author: xjm 10 | * @Description: 11 | * @Date: 2021/4/20 17:00:17 12 | * @Ver: 1.0 13 | * @Email: 326308290@qq.com 14 | */ 15 | public sealed class ColumnFirstPositionSegment:ColumnPositionSegment 16 | { 17 | public ColumnFirstPositionSegment(int startIndex, int stopIndex, ColumnSegment? columnName) : base(startIndex, stopIndex, columnName) 18 | { 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/DDL/Index/DropIndexDefinitionSegment.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Segment.DDL.Index; 2 | 3 | public sealed class DropIndexDefinitionSegment:IAlterDefinitionSegment 4 | { 5 | public int StartIndex { get; } 6 | public int StopIndex { get; } 7 | public IndexSegment Index { get; } 8 | public DropIndexDefinitionSegment(int startIndex, int stopIndex,IndexSegment index) 9 | { 10 | StartIndex = startIndex; 11 | StopIndex = stopIndex; 12 | Index = index; 13 | } 14 | 15 | public override string ToString() 16 | { 17 | return $"{nameof(StartIndex)}: {StartIndex}, {nameof(StopIndex)}: {StopIndex}, {nameof(Index)}: {Index}"; 18 | } 19 | } -------------------------------------------------------------------------------- /src/core/parser/NCDC.CommandParser/Common/Segment/DML/Expr/NotExpression.cs: -------------------------------------------------------------------------------- 1 | namespace NCDC.CommandParser.Common.Segment.DML.Expr; 2 | 3 | public sealed class NotExpression:IExpressionSegment 4 | { 5 | public NotExpression(int startIndex, int stopIndex,IExpressionSegment expression) 6 | { 7 | StartIndex = startIndex; 8 | StopIndex = stopIndex; 9 | Expression = expression; 10 | } 11 | 12 | public int StartIndex { get; } 13 | public int StopIndex { get; } 14 | public IExpressionSegment Expression { get; } 15 | 16 | public override string ToString() 17 | { 18 | return $"{nameof(StartIndex)}: {StartIndex}, {nameof(StopIndex)}: {StopIndex}, {nameof(Expression)}: {Expression}"; 19 | } 20 | } -------------------------------------------------------------------------------- /src/protocol/NCDC.Protocol/Helper/Sha1Helper.cs: -------------------------------------------------------------------------------- 1 | using System.Security.Cryptography; 2 | using System.Text; 3 | 4 | namespace NCDC.Protocol.Helper; 5 | 6 | public class Sha1Helper 7 | { 8 | public static string Hash(string input) 9 | { 10 | using var sha1 = SHA1.Create(); 11 | return Convert.ToHexString(sha1.ComputeHash(Encoding.UTF8.GetBytes(input))); 12 | } 13 | public static byte[] Hash2Bytes(string input) 14 | { 15 | using var sha1 = SHA1.Create(); 16 | return sha1.ComputeHash(Encoding.UTF8.GetBytes(input)); 17 | } 18 | public static byte[] Hash2Bytes(byte[] inputBytes) 19 | { 20 | using var sha1 = SHA1.Create(); 21 | return sha1.ComputeHash(inputBytes); 22 | } 23 | } --------------------------------------------------------------------------------