GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — sqlb/render_facade.go at main · ubgo/sqlb Expand file tree/ Copy pathrender_facade.goMore file actions 133 lines (105 loc) · 5.73 KB / Copy pathrender_facade.goFile metadata and controls133 lines (105 loc) · 5.73 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 package sqlb import ( "github.com/ubgo/sqlb/dialect/clickhouse" "github.com/ubgo/sqlb/dialect/mysql" "github.com/ubgo/sqlb/dialect/postgres" "github.com/ubgo/sqlb/dialect/sqlite" "github.com/ubgo/sqlb/render" ) // This file is the facade over the render layer, and is named for the layer // rather than for what it used to hold. It was dialect.go until the dialects // moved into dialect/, and a file named dialect.go sitting beside a directory // named dialect/ with different contents is the kind of thing a reader is // entitled to get wrong. Every name below is an alias // or a forwarder, declared here so that splitting the bottom layer out into its // own package did not break a single import. // // Why aliases rather than wrappers: a Go type alias is the same type, so a // dialect written against render.Dialect satisfies sqlb.Dialect with no // conversion, an *Args passes between the layers untouched, and the facade // costs nothing at runtime. A wrapper type would have made the two spellings // different types and forced every engine package to pick one. // // The rule for adding to this file: a name belongs here only if it is defined // in render. Anything that names an operator, a join type, a sort direction or // a keyword is SQL vocabulary and stays in the layers that own it. // Dialect is the two things SQL engines disagree on: how a bound parameter is // written and how an identifier is quoted. See render.Dialect. type Dialect = render.Dialect // Named is satisfied by dialects that can name their engine. See render.Named. type Named = render.Named // Returning is satisfied by dialects that support INSERT ... RETURNING. type Returning = render.Returning // InsertAliasing is satisfied by dialects that accept "INSERT INTO t AS alias". type InsertAliasing = render.InsertAliasing // NewInlineArgs returns Args whose Next writes every value as a literal, for a // statement that takes no parameters. See render.NewInlineArgs. func NewInlineArgs(d Dialect) *Args { return render.NewInlineArgs(d) } // LiteralQuoting is satisfied by a dialect that can write a value as a literal // the engine reads back exactly. See render.LiteralQuoting. type LiteralQuoting = render.LiteralQuoting // ErrNotInlinable reports a value a dialect will not write as a literal. var ErrNotInlinable = render.ErrNotInlinable // ErrNoLiteralQuoting reports a literal requested of a dialect without the // capability. var ErrNoLiteralQuoting = render.ErrNoLiteralQuoting // CombinedAlter is satisfied by dialects that accept several actions in one // ALTER TABLE. See render.CombinedAlter. type CombinedAlter = render.CombinedAlter // UnrestrictedAddColumn is satisfied by dialects whose ADD COLUMN takes any // column. See render.UnrestrictedAddColumn. type UnrestrictedAddColumn = render.UnrestrictedAddColumn // UntypedParameters is satisfied by a dialect that must be told a bound // parameter's type in a function taking any. See render.UntypedParameters. type UntypedParameters = render.UntypedParameters // LikeEscaping is satisfied by dialects that accept an ESCAPE clause on LIKE. // See render.LikeEscaping for why escaping a pattern is not portable. type LikeEscaping = render.LikeEscaping // CaseInsensitiveLike is satisfied by a dialect with ILIKE. See // render.CaseInsensitiveLike for why the fold predicates ask for it. type CaseInsensitiveLike = render.CaseInsensitiveLike // NumericParameters is satisfied by a dialect that widens an untyped integer // parameter beside a DECIMAL. See render.NumericParameters for the MySQL // measurement behind it. type NumericParameters = render.NumericParameters // Args collects bound values during one render and carries the first error. type Args = render.Args // SQLer is anything that can render itself into SQL text using the statement's // Args. type SQLer = render.SQLer // PostgresDialect renders $1, $2 placeholders and double-quoted identifiers. // // The three dialects below are aliases because each one now lives in its own // package under dialect/, built the way a dialect from another repository is // built: importing the render layer and nothing else. Keeping the old names // here means the split cost no caller an import, and it keeps a one-import // entry point for code that just needs to say which engine it targets. type PostgresDialect = postgres.Dialect // SQLiteDialect renders ? placeholders and double-quoted identifiers. type SQLiteDialect = sqlite.Dialect // ClickHouseDialect renders ? placeholders and backquoted identifiers. It // deliberately does not satisfy Returning; ClickHouse has no RETURNING. type ClickHouseDialect = clickhouse.Dialect // MySQLDialect renders ? placeholders and backquoted identifiers. It does not // satisfy Returning; MySQL has no RETURNING. type MySQLDialect = mysql.Dialect // The engine names this module ships. Not a closed set; see render. const ( DialectPostgres = render.DialectPostgres DialectSQLite = render.DialectSQLite DialectClickHouse = render.DialectClickHouse DialectMySQL = render.DialectMySQL DialectUnknown = render.DialectUnknown ) // ErrUnsupportedDialect is returned by Build when a construct was rendered // through a dialect that does not support it. var ErrUnsupportedDialect = render.ErrUnsupportedDialect // DialectName reports the engine name of d, or DialectUnknown. func DialectName(d Dialect) string { return render.DialectName(d) } // Quote wraps s in q and doubles any embedded q. func Quote(s string, q byte) string { return render.Quote(s, q) } // NewArgs starts an empty argument list for d. func NewArgs(d Dialect) *Args { return render.NewArgs(d) } // Raw makes a SQLer from a render function, for a fragment in a position typed // SQLer, such as a GROUP BY item or a raw WHERE condition. func Raw(f func(a *Args) string) SQLer { return render.Raw(f) } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |