mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-30 00:42:26 -05:00 
			
		
		
		
	Add SQLite support, fix un-thread-safe DB caches, small performance f… (#172)
* Add SQLite support, fix un-thread-safe DB caches, small performance fixes Signed-off-by: kim (grufwub) <grufwub@gmail.com> * add SQLite licenses to README Signed-off-by: kim (grufwub) <grufwub@gmail.com> * appease the linter, and fix my dumbass-ery Signed-off-by: kim (grufwub) <grufwub@gmail.com> * make requested changes Signed-off-by: kim (grufwub) <grufwub@gmail.com> * add back comment Signed-off-by: kim (grufwub) <grufwub@gmail.com>
This commit is contained in:
		
					parent
					
						
							
								53507ac2a3
							
						
					
				
			
			
				commit
				
					
						ed46224573
					
				
			
		
					 730 changed files with 2239881 additions and 3669 deletions
				
			
		
							
								
								
									
										24
									
								
								vendor/github.com/uptrace/bun/dialect/sqlitedialect/LICENSE
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								vendor/github.com/uptrace/bun/dialect/sqlitedialect/LICENSE
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,24 @@ | |||
| Copyright (c) 2021 Vladimir Mihailenco. All rights reserved. | ||||
| 
 | ||||
| Redistribution and use in source and binary forms, with or without | ||||
| modification, are permitted provided that the following conditions are | ||||
| met: | ||||
| 
 | ||||
|    * Redistributions of source code must retain the above copyright | ||||
| notice, this list of conditions and the following disclaimer. | ||||
|    * Redistributions in binary form must reproduce the above | ||||
| copyright notice, this list of conditions and the following disclaimer | ||||
| in the documentation and/or other materials provided with the | ||||
| distribution. | ||||
| 
 | ||||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||||
| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||||
| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||||
| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||||
| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||||
| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||||
| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||||
| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||||
| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||||
| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||||
| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
							
								
								
									
										94
									
								
								vendor/github.com/uptrace/bun/dialect/sqlitedialect/dialect.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								vendor/github.com/uptrace/bun/dialect/sqlitedialect/dialect.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,94 @@ | |||
| package sqlitedialect | ||||
| 
 | ||||
| import ( | ||||
| 	"database/sql" | ||||
| 	"reflect" | ||||
| 	"sync" | ||||
| 
 | ||||
| 	"github.com/uptrace/bun/dialect" | ||||
| 	"github.com/uptrace/bun/dialect/feature" | ||||
| 	"github.com/uptrace/bun/dialect/sqltype" | ||||
| 	"github.com/uptrace/bun/schema" | ||||
| ) | ||||
| 
 | ||||
| type Dialect struct { | ||||
| 	tables   *schema.Tables | ||||
| 	features feature.Feature | ||||
| 
 | ||||
| 	appenderMap sync.Map | ||||
| 	scannerMap  sync.Map | ||||
| } | ||||
| 
 | ||||
| func New() *Dialect { | ||||
| 	d := new(Dialect) | ||||
| 	d.tables = schema.NewTables(d) | ||||
| 	d.features = feature.Returning | feature.InsertTableAlias | feature.DeleteTableAlias | ||||
| 	return d | ||||
| } | ||||
| 
 | ||||
| func (d *Dialect) Init(*sql.DB) {} | ||||
| 
 | ||||
| func (d *Dialect) Name() dialect.Name { | ||||
| 	return dialect.SQLite | ||||
| } | ||||
| 
 | ||||
| func (d *Dialect) Features() feature.Feature { | ||||
| 	return d.features | ||||
| } | ||||
| 
 | ||||
| func (d *Dialect) Tables() *schema.Tables { | ||||
| 	return d.tables | ||||
| } | ||||
| 
 | ||||
| func (d *Dialect) OnTable(table *schema.Table) { | ||||
| 	for _, field := range table.FieldMap { | ||||
| 		d.onField(field) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (d *Dialect) onField(field *schema.Field) { | ||||
| 	// INTEGER PRIMARY KEY is an alias for the ROWID. | ||||
| 	// It is safe to convert all ints to INTEGER, because SQLite types don't have size. | ||||
| 	switch field.DiscoveredSQLType { | ||||
| 	case sqltype.SmallInt, sqltype.BigInt: | ||||
| 		field.DiscoveredSQLType = sqltype.Integer | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (d *Dialect) IdentQuote() byte { | ||||
| 	return '"' | ||||
| } | ||||
| 
 | ||||
| func (d *Dialect) Append(fmter schema.Formatter, b []byte, v interface{}) []byte { | ||||
| 	return schema.Append(fmter, b, v, nil) | ||||
| } | ||||
| 
 | ||||
| func (d *Dialect) Appender(typ reflect.Type) schema.AppenderFunc { | ||||
| 	if v, ok := d.appenderMap.Load(typ); ok { | ||||
| 		return v.(schema.AppenderFunc) | ||||
| 	} | ||||
| 
 | ||||
| 	fn := schema.Appender(typ, nil) | ||||
| 
 | ||||
| 	if v, ok := d.appenderMap.LoadOrStore(typ, fn); ok { | ||||
| 		return v.(schema.AppenderFunc) | ||||
| 	} | ||||
| 	return fn | ||||
| } | ||||
| 
 | ||||
| func (d *Dialect) FieldAppender(field *schema.Field) schema.AppenderFunc { | ||||
| 	return schema.FieldAppender(d, field) | ||||
| } | ||||
| 
 | ||||
| func (d *Dialect) Scanner(typ reflect.Type) schema.ScannerFunc { | ||||
| 	if v, ok := d.scannerMap.Load(typ); ok { | ||||
| 		return v.(schema.ScannerFunc) | ||||
| 	} | ||||
| 
 | ||||
| 	fn := scanner(typ) | ||||
| 
 | ||||
| 	if v, ok := d.scannerMap.LoadOrStore(typ, fn); ok { | ||||
| 		return v.(schema.ScannerFunc) | ||||
| 	} | ||||
| 	return fn | ||||
| } | ||||
							
								
								
									
										7
									
								
								vendor/github.com/uptrace/bun/dialect/sqlitedialect/go.mod
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								vendor/github.com/uptrace/bun/dialect/sqlitedialect/go.mod
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,7 @@ | |||
| module github.com/uptrace/bun/dialect/sqlitedialect | ||||
| 
 | ||||
| go 1.16 | ||||
| 
 | ||||
| replace github.com/uptrace/bun => ../.. | ||||
| 
 | ||||
| require github.com/uptrace/bun v0.4.3 | ||||
							
								
								
									
										22
									
								
								vendor/github.com/uptrace/bun/dialect/sqlitedialect/go.sum
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								vendor/github.com/uptrace/bun/dialect/sqlitedialect/go.sum
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,22 @@ | |||
| github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||||
| github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||||
| github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||||
| github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= | ||||
| github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= | ||||
| github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||||
| github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||||
| github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||||
| github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||||
| github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= | ||||
| github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||||
| github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc h1:9lRDQMhESg+zvGYmW5DyG0UqvY96Bu5QYsTLvCHdrgo= | ||||
| github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc/go.mod h1:bciPuU6GHm1iF1pBvUfxfsH0Wmnc2VbpgvbI9ZWuIRs= | ||||
| github.com/vmihailenco/msgpack/v5 v5.3.4 h1:qMKAwOV+meBw2Y8k9cVwAy7qErtYCwBzZ2ellBfvnqc= | ||||
| github.com/vmihailenco/msgpack/v5 v5.3.4/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc= | ||||
| github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= | ||||
| github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= | ||||
| golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 h1:RqytpXGR1iVNX7psjB3ff8y7sNFinVFvkx1c8SjBkio= | ||||
| golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||||
| gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||||
| gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= | ||||
| gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||||
							
								
								
									
										28
									
								
								vendor/github.com/uptrace/bun/dialect/sqlitedialect/scan.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								vendor/github.com/uptrace/bun/dialect/sqlitedialect/scan.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,28 @@ | |||
| package sqlitedialect | ||||
| 
 | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"reflect" | ||||
| 
 | ||||
| 	"github.com/uptrace/bun/schema" | ||||
| ) | ||||
| 
 | ||||
| func scanner(typ reflect.Type) schema.ScannerFunc { | ||||
| 	if typ.Kind() == reflect.Interface { | ||||
| 		return scanInterface | ||||
| 	} | ||||
| 	return schema.Scanner(typ) | ||||
| } | ||||
| 
 | ||||
| func scanInterface(dest reflect.Value, src interface{}) error { | ||||
| 	if dest.IsNil() { | ||||
| 		dest.Set(reflect.ValueOf(src)) | ||||
| 		return nil | ||||
| 	} | ||||
| 
 | ||||
| 	dest = dest.Elem() | ||||
| 	if fn := scanner(dest.Type()); fn != nil { | ||||
| 		return fn(dest, src) | ||||
| 	} | ||||
| 	return fmt.Errorf("bun: can't scan %#v into %s", src, dest.Type()) | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue