gloriousfutureio / sql2kv Goto Github PK
View Code? Open in Web Editor NEWTake RDBS and convert to a KV of your choosing
License: MIT License
Take RDBS and convert to a KV of your choosing
License: MIT License
Document in #9 after we're done
Add this early on so we benefit from it over time. This project pushes a lot of data from network to disk, and holds things in memory to reshape them. Profiling seems worth it.
We get column types after scanning information_schema. The first place we map those to a go type is here
There are a lot of types to map. We might gather them under a function like:
for _, t := range ts.Columns {
val, err := mapMySQLType(ts.DataType)
// check err ...
newRow = append(newRow, val)
}
rows.Scan(newRow...)
If we encapsulate the different DB's mappings into functions, it will be easier to swap the implementation.
The core function is to dump data, but we might persist additional metadata on a special key path:
/{schema}/{table}/metadata/{something}
Rather than forcing the person querying out k-v store to map a complicated data structure that contains all metadata, we might provide arrays of strings for some things
/{schema}/{table}/metadata/columns - ["id", "name", "age"]
/{schema}/{table}/metadata/types - ["numeric", "string", "numeric"]
//{schema}/{table}/metadata/primary-key - "id"
Travis is free for open source. Does Circle do the same thing?
The JSON serializer knows what to do with a flat map[string]interface{}
. We need to switch over the pointer types and dereference the pointers to get values.
Note that we need column names and (optionally) the primary key column name turned into the special __pk
key.
Proposed signature:
func derefToMap(cols []string, row []interface{}, pkCol string) map[string]interface{} { /* ... */ }
We have a chain of conversions from SQL to Go types to Key + JSON representation.
MySQL type | Go type | JSON type | Done |
---|---|---|---|
text | string | string | YES |
binary(n) | []byte | base64 string | NO |
varchar(n) | string | string | YES |
boolean | bool | bool | YES |
timestamp(n) | time.Time | ISO_8601 string | NO |
int | int64 | float64/numeric | YES |
bigint | int64 | float64/numeric | NO |
Most regular types, if nullable, will need to map to a custom Go struct that implements the Valuer
interface: https://golang.org/pkg/database/sql/driver/#Valuer . There might also be libraries that provide these types.
Still working on the POC.
Take the user table
+----+---------------+-------+
| id | name | age |
+----+---------------+-------+
| 1 | Farhan | 32 |
| 2 | Coleman | 32 |
| 3 | Jeff May | 27 |
| 4 | Mr&MissGophie | 1 |
| 5 | Dogs | 200 |
| 6 | GopherThing | 20 |
| 7 | Linus Torval | 100 |
| 8 | Rob Pike | 100 |
| 9 | NinjaMan | 23232 |
| 10 | Zack | 34 |
+----+---------------+-------+
Into a leveldb with something like
<schema>!<table>!<PrimaryKEY>! JSON
We need an open source license and a README stubbed out.
We can ship tools under cmd like
sql2kv/cmd/sql2kv # "real" command line app
sql2kv/cmd/sql2kv-test # an standalone CLI for benchmarking
Everybody loves the cli
framework.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.